Skip to content

Wires the custom role creation with the api endpoint, handling loading, error and success states - #297

Open
jacobo-dominguez-wgu wants to merge 4 commits into
masterfrom
jacobo/create-role-wizard-3
Open

jacobo-dominguez-wgu wants to merge 4 commits into
masterfrom
jacobo/create-role-wizard-3

Conversation

@jacobo-dominguez-wgu

Copy link
Copy Markdown
Contributor

Description

Connects the Create button of the create custom role wizard to the new create endpoint, on top of the permissions step from #295, handles loading, error and success states with proper feedback.

Closes openedx/openedx-authz#573.
Design figma
Requires openedx/openedx-authz#647

Approach

  • Request: Create sends display_name (trimmed), scope_types (a one-item list with the role's resource type) and permissions to POST /api/authz/v1/roles/. The permissions sent are every permission the role grants: the user's choices plus the ones they require. They are sent in catalog order, so the request matches the count in the summary panel.
  • Pending: Create shows "Creating" with a spinner. Back, Cancel, the close button and Esc are blocked until the request finishes.
  • Success: the wizard closes and a toast says the role was created. The user stays on the Roles and permissions table. The catalog and table queries are invalidated, so the new role appears in the table, in the clone picker and in the assign role wizard without a reload.
  • Name taken (409): the wizard goes back to the first step.
    • The name field shows an error and gets focus, and the step 1 marker in the Stepper header shows an error.
    • Next stays blocked while the name matches the rejected one. The comparison ignores case and surrounding spaces, as the server's does.
    • The alert closes on the first edit to the name. The other choices are kept.
  • Invalid (400) and forbidden (403): an alert on the permissions step shows our own message. The server's message is in English and isn't translated, so it isn't shown.
  • Any other failure: the alert shows the app's usual error message with a Retry button. It stays inside the wizard because the modal blocks clicks outside it, so a toast's Retry couldn't be used.
  • Alert layout: the alert floats over the bottom of the step content, just above the footer, so it never scrolls out of view and doesn't push the content up. The assign role wizard now uses the same classes.

Notes for reviewers

  • Built against an open backend PR. openedx-authz#647 is still open, and it's stacked. The tests mock its current contract (201 returns the new role in the shape of a roles-list item; 409, 400, 403).
  • The status code decides the message. 400 responses come in two shapes, DRF field errors or { message } (raised in the #647 review), so the wizard ignores the response body.
  • Who sees the button isn't changed here. The endpoint only accepts staff and superusers, but the button still shows for anyone who can open the tab. Those users get the 403 alert. Hiding the button for them is a separate work item.
  • aria-invalid on the name field. Paragon's isInvalid only styles the field, and a taken name passes the browser's own validation. Without the attribute, screen readers wouldn't announce the error.

Testing

Setup

  1. Backend: needs to run feat: add the endpoint to create custom roles openedx-authz#647.
  2. Frontend: check out jacobo/create-role-wizard-3 and run npm run dev.
  3. User: A staff or superuser account.
  4. Log in as the staff user and open the Roles and permissions tab.

1. Create a role from scratch

  1. Click Create Custom Role. Enter QA Designer and choose Libraries, then click Next.
  2. Select a few permissions, then click Create.
  3. Check:
    • While the request runs, the button shows Creating with a spinner. Back is disabled, and Esc and the header close button do nothing.
    • The wizard closes, and the toast "The QA Designer role was created." appears.
    • QA Designer is in the table without a reload. It shows 0 members and today's date under last updated.
    • In DevTools → Network, the request is POST /api/authz/v1/roles/ with {display_name, scope_types: ["lib"], permissions} and a 201 response.

2. Create a role by cloning

  1. Open the wizard, enter QA Course Clone, choose Clone from role, pick Course Staff, then click Next.
  2. Change one permission and click Create.
  3. Check:
    • The role is created with resource type courses.
    • QA Designer from step 1 now shows in the clone picker under custom roles.

3. Name taken (409)

  1. Open the wizard, enter qa designer (lowercase, with spaces), choose Libraries, then click Next.
  2. Select a permission and click Create.
  3. Check:
    • The wizard goes back to Name & Resource.
    • The name field is red, with "A role with this name already exists." under it, and has focus.
    • The step 1 bubble in the header shows the error icon.
    • The floating alert says the name already exists.
    • Next does nothing. A screen reader, such as VoiceOver, announces why.
  4. Type one character.
    • The alert closes, the field and step errors clear, and Next works.
  5. Delete that character.
    • The field error and the blocked Next come back, but the alert doesn't.
  6. Change the name to QA Designer 2 and click Next.
    • Your permissions are still selected.
    • Clicking Create creates the role.

4. Network failure (Retry)

  1. As the staff user, fill the wizard up to the permissions step.
  2. In DevTools → Network, right-click any request and choose Block request URL. Edit the pattern to */api/authz/v1/roles/.
  3. Click Create.
    • The alert shows the generic error message with a Retry button and has focus.
  4. Remove the block, then click Retry.
    • The role is created and the wizard closes.

Demo

Screen.Recording.2026-11-26.at.10.31.49.AM.mov

@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 Nov 26, 2026
@openedx-webhooks

openedx-webhooks commented Nov 26, 2026 •

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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Nov 26, 2026
@jacobo-dominguez-wgu
jacobo-dominguez-wgu changed the base branch from master to jacobo/create-role-wizard-2 November 26, 2026 16:42
@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from 1a3e51b to cab9518 Compare November 26, 2026 16:48
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #297      +/-   ##
==========================================
+ Coverage   99.16%   99.29%   +0.12%     
==========================================
  Files         103      110       +7     
  Lines        1923     2129     +206     
  Branches      620      682      +62     
==========================================
+ Hits         1907     2114     +207     
+ Misses         16       15       -1     

☔ 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.

@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, adding my initial comments.

canRetry: boolean;
// A taken name is fixed in the name field, which takes focus in place of the alert.
isNameTaken?: boolean;
}// Why Next does nothing, so a screen reader can be told; `null` when there is nothing to fix.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems this comment is missplaced?

@rodmgwgu

Copy link
Copy Markdown

Although not directly related with the changes in this PR, there is a weird layering issue with the error message, it is partially hidden by the side info bar, in this case it hides the Dismiss and Retry buttons.

Screenshot 2026-11-26 at 4 29 53 p m

@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from 41b288b to c84c1aa Compare November 27, 2026 21:55
@jacobo-dominguez-wgu

Copy link
Copy Markdown
Contributor Author

Although not directly related with the changes in this PR, there is a weird layering issue with the error message, it is partially hidden by the side info bar, in this case it hides the Dismiss and Retry buttons.

Screenshot 2026-11-26 at 4 29 53 p m

This has been fixed, thanks!
image

@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from c84c1aa to 3a2e3fa Compare December 1, 2026 22:09
Comment thread src/authz-module/index.scss Resolved
@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch 2 times, most recently from 022eb76 to a629379 Compare December 2, 2026 21:55
@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
@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from a629379 to 2bd34a4 Compare December 3, 2026 15:32
@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from 2bd34a4 to 0db356c Compare December 3, 2026 20:55
Comment thread src/authz-module/index.scss Resolved
Comment thread src/authz-module/index.scss Resolved
@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from 0db356c to 78434ff Compare December 4, 2026 17:19

@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 the fixes!, LGTM!

@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from 78434ff to 01573da Compare December 4, 2026 18:45
Base automatically changed from jacobo/create-role-wizard-2 to master December 4, 2026 19:01
@jacobo-dominguez-wgu
jacobo-dominguez-wgu force-pushed the jacobo/create-role-wizard-3 branch from 24020d4 to b959c39 Compare December 4, 2026 19:01
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: Custom role creation call + status toast

5 participants