Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Sarah Funkhouser <[email protected]>
  • Loading branch information
golanglemonade committed Feb 5, 2025
1 parent d7858a0 commit 6ab7193
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 43 deletions.
6 changes: 6 additions & 0 deletions internal/graphapi/groupextended.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 55 additions & 43 deletions internal/graphapi/grouppermissionshelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,66 +56,72 @@ func convertToEntObject(obj any) (*EntObject, error) {
return &entObject, nil
}

// getGroupByIDWithPermissionsEdges returns a group object with all the permissions edges
// TODO (sfunk): This function is a good candidate for a generated function with the group permissions mixin
func getGroupByIDWithPermissionsEdges(ctx context.Context, groupID *string) (*generated.Group, error) {
if groupID != nil {
groupWithPermissions, err := withTransactionalMutation(ctx).Group.
Query().
Where(group.IDEQ(*groupID)).
// Control permissions
WithControlEditors().
WithControlViewers().
WithControlBlockedGroups().

// Control Objective permissions
WithControlObjectiveEditors().
WithControlObjectiveViewers().
WithControlObjectiveBlockedGroups().

// Program permissions
WithProgramViewers().
WithProgramEditors().
WithProgramBlockedGroups().

// Risk permissions
WithRiskViewers().
WithRiskEditors().
WithRiskBlockedGroups().

// Internal Policy permissions
WithInternalPolicyEditors().
WithInternalPolicyBlockedGroups().

// Procedure permissions
WithProcedureEditors().
WithProcedureBlockedGroups().

// Narrative permissions
WithNarrativeViewers().
WithNarrativeEditors().
WithNarrativeBlockedGroups().
Only(ctx)
if err != nil {
return nil, err
}
if groupID == nil || *groupID == "" {
return nil, nil
}

return groupWithPermissions, nil
groupWithPermissions, err := withTransactionalMutation(ctx).Group.
Query().
Where(group.IDEQ(*groupID)).
// Control permissions
WithControlEditors().
WithControlViewers().
WithControlBlockedGroups().

// Control Objective permissions
WithControlObjectiveEditors().
WithControlObjectiveViewers().
WithControlObjectiveBlockedGroups().

// Program permissions
WithProgramViewers().
WithProgramEditors().
WithProgramBlockedGroups().

// Risk permissions
WithRiskViewers().
WithRiskEditors().
WithRiskBlockedGroups().

// Internal Policy permissions
WithInternalPolicyEditors().
WithInternalPolicyBlockedGroups().

// Procedure permissions
WithProcedureEditors().
WithProcedureBlockedGroups().

// Narrative permissions
WithNarrativeViewers().
WithNarrativeEditors().
WithNarrativeBlockedGroups().
Only(ctx)
if err != nil {
return nil, err
}

return nil, nil
return groupWithPermissions, nil
}

func (r *mutationResolver) createGroupMembersViaClone(ctx context.Context, cloneGroupID *string, groupID string, existingMembers []*generated.GroupMembership) error {
if cloneGroupID == nil {
// if there is no clone group id, return
if cloneGroupID == nil || *cloneGroupID == "" {
return nil
}

// get all the members of the cloned group
clonedGroupMembers, err := withTransactionalMutation(ctx).GroupMembership.Query().Where(groupmembership.GroupID(*cloneGroupID)).All(ctx)
if err != nil {
return err
}

var memberInput []*generated.CreateGroupMembershipInput

// this happens after the original group mutation, so we need to ensure
// we don't add the same members to the group
for _, member := range clonedGroupMembers {
memberExists := false

Expand All @@ -134,6 +140,12 @@ func (r *mutationResolver) createGroupMembersViaClone(ctx context.Context, clone
}
}

// no members to add
if len(memberInput) == 0 {
return nil
}

// create all the group memberships
if _, err := r.CreateBulkGroupMembership(ctx, memberInput); err != nil {
return err
}
Expand Down

0 comments on commit 6ab7193

Please sign in to comment.