Skip to content

Commit 1e6a495

Browse files
committed
adding additional roles to groups graph
1 parent 5cfa822 commit 1e6a495

10 files changed

Lines changed: 107 additions & 6 deletions

File tree

internal/ent/interceptors/orgmembers.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ func getFunctionalRoles(ctx context.Context, userID string) ([]string, error) {
106106
return []string{}, nil
107107
}
108108

109+
return GetFunctionalRolesForSubject(ctx, auth.UserSubjectType, userID, caller.OrganizationID)
110+
}
111+
112+
// GetFunctionalRolesForSubject returns the display names of the functional/organization roles
113+
// assigned to the given subject on the organization. The subject is a user or a group tupleset
114+
// (e.g. subjectType "group" with subjectID "<groupID>#member"), matching how the roles were assigned.
115+
func GetFunctionalRolesForSubject(ctx context.Context, subjectType, subjectID, orgID string) ([]string, error) {
116+
caller, ok := auth.CallerFromContext(ctx)
117+
if !ok || caller == nil {
118+
return []string{}, nil
119+
}
120+
109121
roles, err := fgamodel.OrganizationRoles()
110122
if err != nil {
111123
return []string{}, err
@@ -117,9 +129,9 @@ func getFunctionalRoles(ctx context.Context, userID string) ([]string, error) {
117129
}
118130

119131
req := fgax.ListAccess{
120-
SubjectType: auth.UserSubjectType,
121-
SubjectID: userID,
122-
ObjectID: caller.OrganizationID,
132+
SubjectType: subjectType,
133+
SubjectID: subjectID,
134+
ObjectID: orgID,
123135
ObjectType: fgax.Kind(generated.TypeOrganization),
124136
Relations: ids,
125137
Context: utils.NewOrganizationContextKey(caller.SubjectEmail),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
efaaa795e6ec05a60fe60bbee7308865268f3285a68ef9ea6bab6eeb1cb05108
1+
34d59bef43a62206be0291012a8e57d4184b89772d83c1766206867d3aebb9dd
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6cf47179f1aae3893e66f2e20a0d85d5734ede4a24bd270f2cbbae791c9cd0c4
1+
9c6cb803fee1b0a2dee46297913841b284f99c2cf7349d45ae9bb0587204094f

internal/graphapi/clientschema/schema.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33874,6 +33874,10 @@ type Group implements Node {
3387433874
"""
3387533875
last: Int
3387633876
): GroupPermissionConnection!
33877+
"""
33878+
additionalRoles are the functional/organization roles assigned to the group on top of object permissions
33879+
"""
33880+
additionalRoles: [String!]
3387733881
}
3387833882
"""
3387933883
Return response for createBulkGroup mutation

internal/graphapi/generated/ent.generated.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type EvidenceResolver interface {
5757
}
5858
type GroupResolver interface {
5959
Permissions(ctx context.Context, obj *generated.Group, after *entgql.Cursor[string], first *int, before *entgql.Cursor[string], last *int) (*model.GroupPermissionConnection, error)
60+
AdditionalRoles(ctx context.Context, obj *generated.Group) ([]string, error)
6061
}
6162
type IdentityHolderResolver interface {
6263
HasPendingWorkflow(ctx context.Context, obj *generated.IdentityHolder) (bool, error)
@@ -90755,6 +90756,29 @@ func (ec *executionContext) fieldContext_Group_permissions(ctx context.Context,
9075590756
return fc, nil
9075690757
}
9075790758

90759+
func (ec *executionContext) _Group_additionalRoles(ctx context.Context, field graphql.CollectedField, obj *generated.Group) (ret graphql.Marshaler) {
90760+
return graphql.ResolveField(
90761+
ctx,
90762+
ec.OperationContext,
90763+
field,
90764+
func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
90765+
return ec.fieldContext_Group_additionalRoles(ctx, field)
90766+
},
90767+
func(ctx context.Context) (any, error) {
90768+
return ec.Resolvers.Group().AdditionalRoles(ctx, obj)
90769+
},
90770+
nil,
90771+
func(ctx context.Context, selections ast.SelectionSet, v []string) graphql.Marshaler {
90772+
return ec.marshalOString2ᚕstringᚄ(ctx, selections, v)
90773+
},
90774+
true,
90775+
false,
90776+
)
90777+
}
90778+
func (ec *executionContext) fieldContext_Group_additionalRoles(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
90779+
return graphql.NewScalarFieldContext("Group", field, true, true, errors.New("field of type String does not have child fields"))
90780+
}
90781+
9075890782
func (ec *executionContext) _GroupConnection_edges(ctx context.Context, field graphql.CollectedField, obj *generated.GroupConnection) (ret graphql.Marshaler) {
9075990783
return graphql.ResolveField(
9076090784
ctx,
@@ -432904,6 +432928,39 @@ func (ec *executionContext) _Group(ctx context.Context, sel ast.SelectionSet, ob
432904432928
continue
432905432929
}
432906432930

432931+
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
432932+
case "additionalRoles":
432933+
field := field
432934+
432935+
innerFunc := func(ctx context.Context, _ *graphql.FieldSet) (res graphql.Marshaler) {
432936+
defer func() {
432937+
if r := recover(); r != nil {
432938+
ec.Error(ctx, ec.Recover(ctx, r))
432939+
}
432940+
}()
432941+
res = ec._Group_additionalRoles(ctx, field, obj)
432942+
return res
432943+
}
432944+
432945+
if field.Deferrable != nil {
432946+
dfs, ok := deferred[field.Deferrable.Label]
432947+
di := 0
432948+
if ok {
432949+
dfs.AddField(field)
432950+
di = len(dfs.Values) - 1
432951+
} else {
432952+
dfs = graphql.NewFieldSet([]graphql.CollectedField{field})
432953+
deferred[field.Deferrable.Label] = dfs
432954+
}
432955+
dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler {
432956+
return innerFunc(ctx, dfs)
432957+
})
432958+
432959+
// don't run the out.Concurrently() call below
432960+
out.Values[i] = graphql.Null
432961+
continue
432962+
}
432963+
432907432964
out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) })
432908432965
default:
432909432966
panic("unknown field " + strconv.Quote(field.Name))

internal/graphapi/generated/root_.generated.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/graphapi/groupextended.resolvers.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/graphapi/schema/groupextended.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ extend type Group {
138138
"""
139139
last: Int
140140
): GroupPermissionConnection!
141+
"""
142+
additionalRoles are the functional/organization roles assigned to the group on top of object permissions
143+
"""
144+
additionalRoles: [String!]
141145
}
142146

143147
"""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e1ce94baccdac8be08e35c5a18aa287607897b4aae0b132075d68eba91eefdff
1+
7cba36adb60f3907481738c4840db8921b01fce4e2b1446cb8c8e52b793b7ed8

internal/graphapi/testclient/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)