Skip to content

Commit 714025b

Browse files
authored
Tuples for user group sometimes being created in personal org (#2320)
1 parent 91761b0 commit 714025b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

internal/ent/hooks/group.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func groupCreateHook(ctx context.Context, m *generated.GroupMutation) error {
232232
publicGroup = groupSetting.Visibility == enums.VisibilityPublic
233233
}
234234

235-
org, err := auth.GetOrganizationIDFromContext(ctx)
235+
org, err := getTupleOrgID(ctx, m)
236236
if err != nil {
237237
return err
238238
}
@@ -255,6 +255,15 @@ func groupCreateHook(ctx context.Context, m *generated.GroupMutation) error {
255255
return nil
256256
}
257257

258+
func getTupleOrgID(ctx context.Context, m *generated.GroupMutation) (string, error) {
259+
// in instances of managed groups, this will be set so use it
260+
if id, ok := m.OwnerID(); ok && id != "" {
261+
return id, nil
262+
}
263+
264+
return auth.GetOrganizationIDFromContext(ctx)
265+
}
266+
258267
// createGroupParentTuple creates a relationship tuple for a group
259268
func createGroupParentTuple(orgID, groupID string, isPublic bool) ([]fgax.TupleKey, error) {
260269
const (

0 commit comments

Comments
 (0)