Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMQ-2705 - Add list groups with no parent group #2708

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions api/http/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ const (
GroupKey = "group"
DomainKey = "domain"

StartLevelKey = "start_level"
EndLevelKey = "end_level"
TreeKey = "tree"
ParentKey = "parent_id"
LevelKey = "level"
StartLevelKey = "start_level"
EndLevelKey = "end_level"
TreeKey = "tree"
ParentKey = "parent_id"
LevelKey = "level"
WithoutParentKey = "without_parent"

TokenKey = "token"
SubjectKey = "subject"
Expand Down
19 changes: 14 additions & 5 deletions apidocs/openapi/groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ tags:
- name: Roles
description: All operations involving roles for groups
externalDocs:
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
- name: Health
description: Health check operations
externalDocs:
Expand Down Expand Up @@ -92,7 +92,7 @@ paths:
- $ref: "#/components/parameters/Tree"
- $ref: "#/components/parameters/Metadata"
- $ref: "#/components/parameters/GroupName"
- $ref: "#/components/parameters/ParentID"
- $ref: "#/components/parameters/WithoutParent"
responses:
"200":
$ref: "#/components/responses/GroupPageRes"
Expand Down Expand Up @@ -516,7 +516,7 @@ paths:
- bearerAuth: []
responses:
"201":
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
"400":
description: Failed due to malformed group's ID.
"401":
Expand Down Expand Up @@ -1222,7 +1222,7 @@ components:
ParentGroupReqObj:
type: object
properties:
group_id:
group_id:
type: string
format: uuid
example: bb7edb32-2eac-4aad-aebe-ed96fe073879
Expand Down Expand Up @@ -1432,6 +1432,15 @@ components:
type: boolean
default: false

WithoutParent:
name: without_parent
description: List groups without a parent group.
in: query
schema:
type: boolean
default: false
required: false

Metadata:
name: metadata
description: Metadata filter. Filtering is performed matching the parameter with metadata on top level. Parameter is json.
Expand Down
26 changes: 16 additions & 10 deletions groups/api/http/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,23 @@
return groups.PageMeta{}, errors.Wrap(apiutil.ErrValidation, err)
}

withoutParent, err := apiutil.ReadBoolQuery(r, api.WithoutParentKey, false)
if err != nil {
return groups.PageMeta{}, errors.Wrap(apiutil.ErrValidation, err)
}

Check warning on line 258 in groups/api/http/decode.go

View check run for this annotation

Codecov / codecov/patch

groups/api/http/decode.go#L257-L258

Added lines #L257 - L258 were not covered by tests

ret := groups.PageMeta{
Offset: offset,
Limit: limit,
Name: name,
ID: id,
Metadata: meta,
Status: st,
RoleName: roleName,
RoleID: roleID,
Actions: actions,
AccessType: accessType,
Offset: offset,
Limit: limit,
Name: name,
ID: id,
Metadata: meta,
Status: st,
RoleName: roleName,
RoleID: roleID,
Actions: actions,
AccessType: accessType,
WithoutParent: withoutParent,
}
return ret, nil
}
29 changes: 15 additions & 14 deletions groups/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ package groups

// PageMeta contains page metadata that helps navigation.
type PageMeta struct {
Total uint64 `json:"total"`
Offset uint64 `json:"offset"`
Limit uint64 `json:"limit"`
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
Path string `json:"path,omitempty"`
DomainID string `json:"domain_id,omitempty"`
Tag string `json:"tag,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
Status Status `json:"status,omitempty"`
RoleName string `json:"role_name,omitempty"`
RoleID string `json:"role_id,omitempty"`
Actions []string `json:"actions,omitempty"`
AccessType string `json:"access_type,omitempty"`
Total uint64 `json:"total"`
Offset uint64 `json:"offset"`
Limit uint64 `json:"limit"`
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
Path string `json:"path,omitempty"`
DomainID string `json:"domain_id,omitempty"`
Tag string `json:"tag,omitempty"`
Metadata Metadata `json:"metadata,omitempty"`
Status Status `json:"status,omitempty"`
RoleName string `json:"role_name,omitempty"`
RoleID string `json:"role_id,omitempty"`
Actions []string `json:"actions,omitempty"`
AccessType string `json:"access_type,omitempty"`
WithoutParent bool `json:"without_parent,omitempty"`
}
3 changes: 3 additions & 0 deletions groups/postgres/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,9 @@
if len(gm.Metadata) > 0 {
queries = append(queries, "g.metadata @> :metadata")
}
if gm.WithoutParent {
queries = append(queries, "g.parent_id IS NULL")
}

Check warning on line 928 in groups/postgres/groups.go

View check run for this annotation

Codecov / codecov/patch

groups/postgres/groups.go#L927-L928

Added lines #L927 - L928 were not covered by tests
if len(queries) > 0 {
return fmt.Sprintf("WHERE %s", strings.Join(queries, " AND "))
}
Expand Down
Loading