Skip to content

Commit fa2223c

Browse files
committed
skip fga check for support user when cloning into a program
1 parent cf54084 commit fa2223c

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

internal/graphapi/control_clone.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,21 +214,25 @@ func (r *mutationResolver) cloneControls(ctx context.Context, controlsToClone []
214214
return nil, generated.ErrPermissionDenied
215215
}
216216

217-
allow, err := r.db.Authz.CheckAccess(ctx, fgax.AccessCheck{
218-
ObjectType: generated.TypeProgram,
219-
ObjectID: *programID,
220-
Relation: fgax.CanEdit,
221-
SubjectID: caller.SubjectID,
222-
SubjectType: caller.SubjectType(),
223-
})
224-
if err != nil {
225-
return nil, err
226-
}
217+
// support users should skip this check but for other users,
218+
// we still want to verify they have edit access to the program
219+
if !caller.Has(auth.CapOrgSupport) {
220+
allow, err := r.db.Authz.CheckAccess(ctx, fgax.AccessCheck{
221+
ObjectType: generated.TypeProgram,
222+
ObjectID: *programID,
223+
Relation: fgax.CanEdit,
224+
SubjectID: caller.SubjectID,
225+
SubjectType: caller.SubjectType(),
226+
})
227+
if err != nil {
228+
return nil, err
229+
}
227230

228-
if !allow {
229-
logger.Error().Str("organization_id", caller.OrganizationID).Str("user_id", caller.SubjectID).Msg("no access to edit specified program")
231+
if !allow {
232+
logger.Error().Str("organization_id", caller.OrganizationID).Str("user_id", caller.SubjectID).Msg("no access to edit specified program")
230233

231-
return nil, generated.ErrPermissionDenied
234+
return nil, generated.ErrPermissionDenied
235+
}
232236
}
233237
}
234238

internal/graphapi/control_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,18 @@ func TestMutationCreateControlsByClone(t *testing.T) {
821821
client: suite.client.api,
822822
ctx: sharedTestUser1.UserCtx,
823823
},
824+
{
825+
name: "happy path for support user, all controls under standard with program",
826+
request: testclient.CloneControlInput{
827+
ControlIDs: controlIDs,
828+
ProgramID: &program.ID,
829+
},
830+
expectedControls: controls,
831+
expectedStandard: &publicStandard.ShortName,
832+
expectedNumProgram: 1,
833+
client: suite.client.api,
834+
ctx: newSupportCtx(sharedTestUser1.UserCtx, sharedTestUser1.OrganizationID),
835+
},
824836
{
825837
name: "all controls under standard with program no access",
826838
request: testclient.CloneControlInput{

0 commit comments

Comments
 (0)