Skip to content

feat: delete custom roles from the detail page and the roles table - #304

Open
jacobo-dominguez-wgu wants to merge 1 commit into
masterfrom
feat/remove-custom-roles
Open

jacobo-dominguez-wgu wants to merge 1 commit into
masterfrom
feat/remove-custom-roles

Conversation

@jacobo-dominguez-wgu

Copy link
Copy Markdown
Contributor

Description

Adding delete feature to custom roles from the detailed role view and the roles table actions.
Closes openedx/openedx-authz#585
Design figma

Approach

  • New DeleteRoleModal, opened from two places:
    • the role detail page menu, replacing the console.log stub;
    • a new Delete item in the roles table row menu.
  • Who sees Delete: only custom roles, and only users who can manage roles (staff or superuser, via useCanManageRoles). This matches the permission the endpoint checks. Standard roles never reach the flow.
  • Role with no members: shows a single confirmation, then DELETE /api/authz/v1/roles/<role>/.
  • Role with members:
    • The modal shows the live member count and warns that access is revoked permanently.
    • A required checkbox ("I understand this will revoke access for N members immediately.") enables Delete anyway, which sends ?assignments=revoke.
    • The checkbox clears whenever the member count changes, so the user confirms the number they see.
  • Error handling:
    • 409 means members were assigned after the page loaded. The server removes nothing, and the modal shows an inline warning and asks again with the refreshed count.
    • Any other error shows a retry toast, and the modal stays open.
  • After a successful delete:
    • A success toast is shown.
    • The complete role catalog, the roles table, the role's assignments and the team members are refreshed.
    • On the detail page, the user is sent back to the roles list, because the deleted role's page would only show Not Found.
  • Data layer: deleteRole in data/api.ts and useDeleteRole in data/hooks.ts.

Out of scope: reassigning members before deleting (step 2 of the original design). That feature was dropped in openedx/openedx-authz#585 (comment), so the modal has no "Reassign members" action. The confirmation checkbox is an addition to the Figma design.

Testing

1. Delete a role with no members (roles table)

  1. Go to Roles & Permissions. In Role A's row, open the ⋮ menu and click Delete.
  2. The modal title is Delete "Role A"?. The body says the role isn't assigned to anyone. There is no checkbox, and the button reads Delete.
  3. Click Delete. The button shows "Deleting...", then the modal closes. A toast says The role "Role A" was deleted., and Role A disappears from the table.

2. Delete a role with members (detail page)

  1. Open Role B's detail page. In the ⋮ menu next to the title, click Delete.
  2. The body shows the member count padded to two digits, e.g. "assigned to 02 team members", and warns that access is revoked permanently.
  3. Delete anyway is disabled. Check the box: the button becomes enabled. Uncheck it: the button is disabled again.
  4. Check the box and click Delete anyway.
  5. The modal closes, the success toast shows, and you land on the Roles & Permissions tab. Role B is no longer listed.
  6. Open the Team Members tab, or the audit page of one of Role B's former members. The role no longer appears in their assignments.
  7. Open Role B's old detail URL. It shows Not Found.

Dependencies

Demo

Screen.Recording.2026-12-01.at.3.11.12.PM.mov

LLM Usage

Kiro helped with the implementation and tests A human guided the decisions and reviewed the result.

@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Dec 1, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @jacobo-dominguez-wgu!

This repository is currently maintained by @openedx/committers-frontend.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (d953abb) to head (a26b8f3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #304      +/-   ##
==========================================
+ Coverage   99.14%   99.17%   +0.03%     
==========================================
  Files          99      101       +2     
  Lines        1748     1816      +68     
  Branches      556      577      +21     
==========================================
+ Hits         1733     1801      +68     
  Misses         15       15              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jacobo-dominguez-wgu
jacobo-dominguez-wgu requested review from dcoa, diana-villalvazo-wgu and rodmgwgu and removed request for rodmgwgu December 1, 2026 21:53
@mphilbrick211 mphilbrick211 added the mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). label Dec 2, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Dec 2, 2026

@rodmgwgu rodmgwgu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, tested in my local and is working correctly, just adding some findings for improvement.

await waitFor(() => expect(screen.getByRole('checkbox')).not.toBeChecked());
});

it('offers no reassign action', () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not needed

expect(onDeleted).not.toHaveBeenCalled();
});

it('stays open and offers a retry toast on other errors', async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the retry toast appear behind the modal shadow?

{isCustom && canManageRoles && (
<DeleteRoleModal
isOpen={isDeleteRoleOpen}
role={role}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this page role.userCount comes from the complete catalog, and assigning or revoking members only invalidates the roles table (invalidateCatalogRoles), so the count here can stay stale for up to 30 minutes. For example, if a role has 2 members and I assign 3 more from this page, the modal still says "02 members", and "Delete anyway" sends assignments=revoke, which removes all 5 with no 409.

Can we load the live count when the modal opens, e.g. with GET /api/authz/v1/roles/<role_id>/? The JSDoc in deleteRole and DeleteRoleModal should also say the 409 only covers a role sent without assignments=revoke.


await waitFor(() => expect(mockRemoveRole).toHaveBeenCalled());
expect(close).not.toHaveBeenCalled();
expect(onDeleted).not.toHaveBeenCalled();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I change the catch to always call showErrorToast, all the tests still pass, so nothing checks that a 409 doesn't show the retry toast. Can we assert that "Retry" isn't shown here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). mao-onboarding Reviewing this will help onboard devs from an Axim mission-aligned organization (MAO). open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

Frontend: Delete confirmation + reassign-before-delete modals

5 participants