Skip to content

Who is signed in, and their memberships with abilities (OFN-4816) - #5299

Merged
midigofrank merged 7 commits into
v3from
ofn-4816-me-memberships
Dec 4, 2026
Merged

midigofrank merged 7 commits into
v3from
ofn-4816-me-memberships

Conversation

@midigofrank

@midigofrank midigofrank commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Who is signed in, and their memberships with abilities (OFN-4816)

The new front end has no way to ask who is signed in or what they may do in a project. This adds two v3 reads; the front end builds its session context from them.

Routes

  • GET /api/v3/me: the signed-in person's email, first_name, last_name, mfa_enabled, support_user and instance role (user or superuser), as a users resource.
  • GET /api/v3/me/memberships: the caller's own project_users rows as project-membership resources, paged and ordered by project name. Each carries role, abilities and relationships to its project and user.
  • Both are v3 only, with no v2 route. MeController follows ProjectController: the Version plug and a V3.MeJSON view.

Abilities

  • Four, each mapped to one Lightning.Policies.ProjectUsers action and answered by ProjectUsers.permitted?/2:

    Ability Action
    can_edit_project :edit_project
    can_edit_workflows :edit_workflow
    can_run :run_workflow
    can_manage_members :add_project_user (adding and removing pass for the same roles)
  • The mapping is Projects.abilities/0. The names are API keys; the actions behind them can be renamed freely as long as the list follows. Tests fail if a mapped action stops being a policy action, or if the OpenAPI Abilities keys drift from the mapping.

  • Scopes are read once per page with Scope.fetch_all/2, never per row.

  • In a project whose MFA requirement the caller hasn't met, every ability is false, because that's the policy's answer.

  • include=members on projects is unchanged and carries no abilities.

Who may call

  • People only. A new rule, Policies.Users :read_own_account, sends the service account and repo connections 403 forbidden. It names no token grant: a person holds every grant, and naming one would send a repo connection insufficient_scope, pointing it at a grant that couldn't help.

Which projects are listed

  • Exactly the ones GET /api/v3/projects lists (paginate_projects_for/3): projects scheduled for deletion and sandboxes are left out.

Other changes

  • One builder per resource type: ProjectJSON.membership/1 is public and the user builder moved to UserJSON.member/1, shared by include=members and the new views. Membership ids match include=members.
  • OpenAPI: both paths. first_name, last_name, mfa_enabled and support_user are nullable, as they are in the database.
  • API.md route rows and a CHANGELOG entry.

Not done

  • A bad page value falls back to the default, as on every list, rather than a 400; Filters.page/1 never refuses.
  • Telling a member locked out by MFA from a viewer: both get every ability false. Proposed: mfa_required from ProjectUsers.blocked_by_mfa?/1, which is additive.
  • Live updates of memberships and abilities (OFN-4822).
  • Listing the projects a support user reaches through support access. They have no membership, so neither /me/memberships nor GET /api/v3/projects lists them; GET /api/v3/projects/:id opens one.

Checked

  • v3/me/reading_test.exs: exact attributes for a session and a personal access token; a superuser sees role: "superuser" and a support user support_user: true; the service account (with every grant) and a repo connection get 403 on both routes.
  • v3/me/memberships_test.exs: the whole body for one membership; only the caller's rows; paging and the next link; ids match include=members; the projects listed match GET /api/v3/projects, with a scheduled and a sandbox project in the setup.
  • For owner, admin, editor and viewer, every ability equals ProjectUsers.permitted? for its action. The test also fails if every role gets the same answers.
  • Unmet MFA: listed, every ability false. 401 with no auth, via sentinel_sweep_test.
  • The OpenAPI Abilities keys equal the mapping's names, and each mapped action is a ProjectUsers action (checked to fail on a rename).
  • Full suite (before the abilities change): 7,460 tests, 1 failure, a Postgres deadlock in setup_utils_test.exs that passes alone (logged). Redocly lint, mix credo --strict and mix format pass. After it: 990 tests across the API controllers, policies and projects, 0 failures.
  • Not yet checked live through a session cookie (owner versus viewer).

Client side: OpenFn/lightning-ui#166.

…/me (OFN-4816)

GET /api/v3/me reads the signed-in person's account (email, names,
mfa_enabled and instance role). GET /api/v3/me/memberships pages through
their own project_users rows as project-membership resources, each with
can_edit_workflows, can_run and can_manage_members, each the answer of one
ProjectUsers action on the scope Scope.fetch_all/2 reads for the page.
People only: Policies.Users :read_own_account refuses the service account
and repo connections with 403 forbidden, whatever their grants.
@github-project-automation github-project-automation Bot moved this to New Issues in Core Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

Security Review ✅

  • S0 (project scoping): paginate_memberships_for/2 (lib/lightning/projects.ex:1245) filters project_users by pu.user_id == ^user_id from Scope.actor, never from params; per-project abilities come from Scope.fetch_all/2 so MFA-unmet projects answer false.
  • S1 (authorization): Both actions gated by plug AuthorizeAction, {:users, :read_own_account} (lib/lightning_web/controllers/api/me_controller.ex:25); the new :read_own_account clause (lib/lightning/policies/users.ex:35) refuses non-%User{} actors, covered in reading_test.exs for user, service account, and repo connection.
  • S2 (audit trail): N/A — both routes are read-only GETs.

…-4816)

abilities on each of /api/v3/me/memberships' memberships is now
ProjectUsers.actions() mapped to permitted?/2 on the page's scopes, keyed
by the action's name, with no rename table. The OpenAPI lists each as a
required boolean, and a test holds that list to actions/0. The policy's
moduledoc says renaming or removing an action is a breaking API change.
abilities on each membership is now Projects.abilities/0 (access_project,
edit_project, edit_workflow, run_workflow, add_project_user), each answered
by ProjectUsers.permitted?/2 on the page's scopes. Tests hold the OpenAPI
Abilities schema to that list and every entry to ProjectUsers.actions(), so
a renamed action fails the build, and pin that access_project is false
exactly when blocked_by_mfa? is true for a listed membership.
The signed-in person's users.support_user, as stored, beside role and
mfa_enabled. The column allows null, so the OpenAPI marks it nullable.
abilities is now can_edit_project, can_edit_workflows, can_run and
can_manage_members, from the keyword list Projects.abilities/0, each
answered by ProjectUsers.permitted?/2 for its action on the page's scopes.
access_project is dropped. The mapping shields the policy, so the
ProjectUsers moduledoc no longer calls its actions API keys; the warning
that renaming a key breaks clients sits on @abilities.
@midigofrank
midigofrank merged commit 1fd16eb into v3 Dec 4, 2026
5 of 6 checks passed
@midigofrank
midigofrank deleted the ofn-4816-me-memberships branch December 4, 2026 08:43
@github-project-automation github-project-automation Bot moved this from New Issues to Done in Core Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant