GET: /node To do: - Iterate node queries
(ctx context.Context)
| 35 | // To do: |
| 36 | // - Iterate node queries |
| 37 | func (cr *NodeController) ReadMany(ctx context.Context) error { |
| 38 | u, err := request.Authenticate(ctx.HttpRequest()) |
| 39 | if err != nil && err.Error() != e.NoAuth { |
| 40 | return request.AuthError(err, ctx) |
| 41 | } |
| 42 | |
| 43 | // Gather query params |
| 44 | query := ctx.HttpRequest().URL.Query() |
| 45 | |
| 46 | // Setup query and nodes objects |
| 47 | // Note: query is composed of 3 sub-query objects: |
| 48 | // 1) qPerm - user permissions (system-defined) |
| 49 | // 2) qOpts - query options (user-defined) |
| 50 | // 3) qAcls - ACL queries (user-defined) |
| 51 | q := bson.M{} |
| 52 | qPerm := bson.M{} |
| 53 | qOpts := bson.M{} |
| 54 | qAcls := bson.M{} |
| 55 | nodes := node.Nodes{} |
| 56 | |
| 57 | if u != nil { |
| 58 | // Skip this part if user is an admin |
| 59 | if !u.Admin { |
| 60 | qPerm["$or"] = []bson.M{bson.M{"acl.read": "public"}, bson.M{"acl.read": u.Uuid}, bson.M{"acl.owner": u.Uuid}} |
| 61 | } |
| 62 | } else { |
| 63 | // User is anonymous |
| 64 | if conf.ANON_READ { |
| 65 | // select on only nodes that are publicly readable |
| 66 | qPerm["acl.read"] = "public" |
| 67 | } else { |
| 68 | return responder.RespondWithError(ctx, http.StatusUnauthorized, e.NoAuth) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // bson.M is a convenient alias for a map[string]interface{} map, useful for dealing with BSON in a native way. |
| 73 | var OptsMArray []bson.M |
| 74 | |
| 75 | // Gather params to make db query. Do not include the following list. |
| 76 | if _, ok := query["query"]; ok { |
| 77 | paramlist := map[string]int{"query": 1, "limit": 1, "offset": 1, "order": 1, "direction": 1, "distinct": 1, "download_url": 1, "file_name": 1, "archive": 1} |
| 78 | for key := range query { |
| 79 | if _, found := paramlist[key]; !found { |
| 80 | keyStr := fmt.Sprintf("attributes.%s", key) |
| 81 | for _, value := range query[key] { |
| 82 | if value != "" { |
| 83 | OptsMArray = append(OptsMArray, parseOption(keyStr, value)) |
| 84 | } else { |
| 85 | OptsMArray = append(OptsMArray, bson.M{keyStr: map[string]bool{"$exists": true}}) |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } else if _, ok := query["querynode"]; ok { |
| 91 | paramlist := map[string]int{"querynode": 1, "limit": 1, "offset": 1, "order": 1, "direction": 1, "distinct": 1, "download_url": 1, "file_name": 1, "archive": 1, "owner": 1, "read": 1, "write": 1, "delete": 1, "public_owner": 1, "public_read": 1, "public_write": 1, "public_delete": 1} |
| 92 | for key := range query { |
| 93 | if _, found := paramlist[key]; !found { |
| 94 | for _, value := range query[key] { |
nothing calls this directly
no test coverage detected