예제 #1
0
func parseAclRequestTyped(cx *goweb.Context) (ids []string, err error) {
	var users []string
	query := &Query{list: cx.Request.URL.Query()}
	params, _, err := ParseMultipartForm(cx.Request)
	if err != nil && err.Error() == "request Content-Type isn't multipart/form-data" && query.Has("users") {
		users = strings.Split(query.Value("users"), ",")
	} else if params["users"] != "" {
		users = strings.Split(params["users"], ",")
	} else {
		return nil, errors.New("Action requires list of comma seperated email address in 'users' parameter")
	}
	for _, v := range users {
		if isEmail(v) {
			u := user.User{Username: v, Email: v}
			if err := u.SetUuid(); err != nil {
				return nil, err
			}
			ids = append(ids, u.Uuid)
		} else if isUuid(v) {
			ids = append(ids, v)
		} else {
			return nil, errors.New("Unknown user id. Must be uuid or email address")
		}
	}
	return ids, nil
}
예제 #2
0
func parseAclRequest(cx *goweb.Context) (ids map[string][]string, err error) {
	ids = map[string][]string{}
	users := map[string][]string{}
	query := &Query{list: cx.Request.URL.Query()}
	params, _, err := ParseMultipartForm(cx.Request)
	if err != nil && err.Error() == "request Content-Type isn't multipart/form-data" && (query.Has("all") || query.Has("read") || query.Has("write") || query.Has("delete")) {
		if query.Has("all") {
			users["all"] = strings.Split(query.Value("all"), ",")
		}
		if query.Has("read") {
			users["read"] = strings.Split(query.Value("read"), ",")
		}
		if query.Has("write") {
			users["write"] = strings.Split(query.Value("write"), ",")
		}
		if query.Has("delete") {
			users["delete"] = strings.Split(query.Value("delete"), ",")
		}
	} else if params["all"] != "" || params["read"] != "" || params["write"] != "" || params["delete"] != "" {
		users["all"] = strings.Split(params["all"], ",")
		users["read"] = strings.Split(params["read"], ",")
		users["write"] = strings.Split(params["write"], ",")
		users["delete"] = strings.Split(params["delete"], ",")
	} else {
		return nil, errors.New("Action requires list of comma seperated email address in 'all', 'read', 'write', and/or 'delete' parameter")
	}
	for k, _ := range users {
		for _, v := range users[k] {
			if v != "" {
				if isEmail(v) {
					u := user.User{Username: v, Email: v}
					if err := u.SetUuid(); err != nil {
						return nil, err
					}
					ids[k] = append(ids[k], u.Uuid)
				} else if isUuid(v) {
					ids[k] = append(ids[k], v)
				} else {
					return nil, errors.New("Unknown user id. Must be uuid or email address")
				}
			}
		}
	}
	if len(ids["all"]) > 0 {
		ids["read"] = append(ids["read"], ids["all"]...)
		ids["write"] = append(ids["write"], ids["all"]...)
		ids["delete"] = append(ids["delete"], ids["all"]...)
	}
	delete(ids, "all")
	return ids, nil
}