Skip to content

[Feature Request] Set program owner by default to user creating program #1509

@golanglemonade

Description

@golanglemonade

When creating a program, there is a programOwnerID field (user) edge. By default, if this is not set on the mutation, it should default to the user creating the program:

  1. Add a new hook to programs: https://github.com/theopenlane/core/blob/main/internal/ent/hooks/program.go
  2. It should:
    1. Only occur on OpCreate mutations
    2. It should check if m.ProgramOwnerID() is set and not an empty string
    3. If it is not set, it should should check auth.GetAuthzSubjectType(ctx), , if that is auth.UserSubjectType then
    4. Get the SubjectID using auth.GetSubjectIDFromContext(ctx)
    5. If that is not an empty string, set m.SetProgramOwnerID(userID)
    6. continue to next mutation next.Mutate(ctx, m)
  3. Add this hook to the programs schema and run task generate

Update program tests:

  1. Update Create tests so it checks for a non empty programOwnerID on requests done by JWT or Personal Access tokens, and that it is empty on requests done with the api client.
  2. You will need to update the testclient query before updating the tests to add the programOwnerID field. After adding, you'll need to run task generate:gql

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions