SMQ-2997 - Allow listing root groups with groups that the user has access to (#3226)

Signed-off-by: Felix Gateru <felix.gateru@gmail.com>
This commit is contained in:
Felix Gateru
2025-12-01 16:15:31 +03:00
committed by GitHub
parent fa080ab0f8
commit f7dcaa949b
2 changed files with 19 additions and 4 deletions
+3 -1
View File
@@ -33,6 +33,8 @@ AM_CERTS_GRPC_CLIENT_TLS=
AM_CERTS_GRPC_CA_CERTS=
AM_CERTS_INSTANCE_ID=
AM_CERTS_RELEASE_TAG=latest
# WARNING: This is a development/testing secret only.
# NEVER use this weak secret in production! Generate a strong random secret for production deployments.
AM_CERTS_SECRET=12345678
## OpenBao PKI Config
@@ -45,7 +47,7 @@ AM_CERTS_OPENBAO_PKI_PATH=pki
AM_CERTS_OPENBAO_ROLE=absmach
AM_CERTS_OPENBAO_PKI_CA_CN=Abstract Machines Certificate Authority
AM_CERTS_OPENBAO_PKI_CA_OU=Abstract Machines
AM_CERTS_OPENBAO_PKI_CA_O=AbstractMacines
AM_CERTS_OPENBAO_PKI_CA_O=AbstractMachines
AM_CERTS_OPENBAO_PKI_CA_C=FRANCE
AM_CERTS_OPENBAO_PKI_CA_L=PARIS
AM_CERTS_OPENBAO_PKI_CA_ST=PARIS
+16 -3
View File
@@ -411,6 +411,10 @@ func (repo groupRepository) RetrieveByIDAndUser(ctx context.Context, domainID, u
func (repo groupRepository) RetrieveAll(ctx context.Context, pm groups.PageMeta) (groups.Page, error) {
query := buildQuery(pm)
if pm.RootGroup {
query += " AND nlevel(g.path) = 1 "
}
orderClause := ""
var orderBy string
switch pm.Order {
@@ -843,6 +847,18 @@ func (repo groupRepository) RetrieveChildrenGroups(ctx context.Context, domainID
func (repo groupRepository) RetrieveUserGroups(ctx context.Context, domainID, userID string, pm groups.PageMeta) (groups.Page, error) {
query := buildQuery(pm)
if pm.RootGroup {
query += (` AND
NOT EXISTS (
SELECT 1
FROM groups anc
JOIN final_groups fg
ON fg.id = anc.id
WHERE anc.domain_id = g.domain_id
AND anc.path @> g.path
AND anc.id <> g.id
)`)
}
return repo.retrieveGroups(ctx, domainID, userID, query, pm)
}
@@ -1169,9 +1185,6 @@ func buildQuery(gm groups.PageMeta, ids ...string) string {
if len(gm.Metadata) > 0 {
queries = append(queries, "g.metadata @> :metadata")
}
if gm.RootGroup {
queries = append(queries, "nlevel(g.path) = 1")
}
if len(queries) > 0 {
return fmt.Sprintf("WHERE %s", strings.Join(queries, " AND "))
}