Skip to content

ADR: Custom Roles API #469

Closed
Closed

Description

@rodmgwgu

The openedx-authz REST API will be extended to support the Custom Roles feature. This ADR specifies the API contract: the endpoints, their request/response shapes, authorization, validation rules, and how they relate to the existing roles/catalog/assignment APIs. It is the single source of truth for the backend contract; the per-feature backend issues listed below implement against it.

Use cases to cover

  • CRUD for custom roles
    • Create a user_defined role for a single resource type with name, description and an initial permission set.
    • Read — custom roles appear in the existing catalog (GET /api/authz/v1/roles/, ADR 0028) distinguished by definition_kind (static / user_defined).
    • Update — rename / edit description (metadata) and add/remove permissions.
    • Delete — remove a custom role, with the two deletion paths below.
  • Add or remove permissions to a custom role, applying dependency closure (selecting a permission pulls in its required dependencies; see the permission-dependencies epic EPIC: Permission dependencies mapping #559).
  • Duplicate role (from a standard or custom source): copy the source's resource type and permission set into a new user_defined role; the resource type cannot be changed; only the definition is copied, not member assignments.
  • Reassign role members to another role (used by delete-with-reassign and as a standalone operation).
  • Delete paths:
    • Delete + revoke ("Delete anyway"): delete the role and unassign all its members.
    • Reassign + delete ("Reassign & Delete"): reassign all members to a replacement role, then delete.
  • Impact reporting: expose how many users and scopes a role affects, so the edit banner ("assigned to N members") and the delete/reassign modals can show counts before acting. Confirm whether the existing user/assignment endpoints (ADR 0024, assignment_count + member listing) already return this in one call or whether a dedicated endpoint is needed.

Decisions to record

  • Authorization — superuser-only for writes. Create, update (metadata + permissions), duplicate and delete of custom roles are restricted to platform superusers. (This removes privilege-escalation concerns, since a superuser already holds every permission.) Assign and revoke keep the existing per-resource-type assignment permissions. Reading the catalog is unchanged (ADR 0028). No new gating permission is introduced for the write path.
  • Single resource type per custom role. A custom role applies to exactly one resource type (Courses or Libraries); the create/duplicate endpoints enforce this. Multi-resource-type roles are out of scope for this phase (the old Support more than one scope type per role #466 was dropped).
  • Terminology. The user-facing term for Courses / Libraries is "resource type"; backend keys remain scope_types and the course-v1 / lib namespaces (ADR 0028) — the decision governs UI/prose, not the wire format.
  • Name & description. Name is validated for uniqueness; description is free text stored as entered by the admin (not localized — custom-role names/descriptions are explicitly out of i18n scope).
  • Casbin lifecycle. Create/update/delete render or remove the role's Casbin p rows in the same transaction as the definition changes, following the pattern ADR 0025 uses for static definitions.
  • Audit. Lifecycle events are audited — the audit model is specified in its own ADR (see the Custom roles audit trail epic).

Realizing issues (implemented against this contract)

Create an ADR specifying the contract above.

Metadata

Metadata

Assignees

Labels

willow

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions