Skip to content

Conversation

@bra-i-am
Copy link
Contributor

@bra-i-am bra-i-am commented Sep 26, 2025

Warning

This PR depends on #5 for getting the roles and permissions metadata.
TODO: Add a toast when trying to add an already-assigned role to a user

This pull request adds a complete "Add New Team Member" workflow to the Libraries Team Manager, allowing users to add new members to a library and assign them roles.

Main changes

  • Added new API methods (addTeamMembers, getTeamRoles) and types (AddTeamMembersRequest, PutTeamMembersResponse, TeamRole) to support adding team members and fetching available roles. [1] [2]
  • Introduced React Query hooks (useAddTeamMember, useTeamRoles) for adding team members and fetching roles.
  • Created UI components: AddNewTeamMemberTrigger (button and toast), AddNewTeamMemberModal (form and modal), and integrated them into the team manager page. [1] [2] [3]
  • Updated context (LibraryAuthZProvider) and props to use the new TeamRole type for richer role information, ensuring role descriptions and user counts are available throughout the UI. [1] [2]
  • Enhanced the AuthZTitle component to accept React elements as actions, enabling the new trigger button and future extensibility. [1] [2]

Evidence

Screencast.from.15-10-25.16.45.16.webm

Testing instructions

  1. Create and set up a local environment (Tutor recommended)
  2. Run LMS and CMS, then clone the repo in the current branch and run the dev server npm run dev
  3. Add the URL to the CORS_WHITELIST in both LMS/CMS settings.py
# admin console MFE
CORS_ORIGIN_WHITELIST.append("http://apps.local.openedx.io:2025")
LOGIN_REDIRECT_WHITELIST.append("apps.local.openedx.io:2025")
CSRF_TRUSTED_ORIGINS.append("http://apps.local.openedx.io:2025")
  1. Go to the Studio and create a library
  2. Navigate to http://apps.local.openedx.io:2025/admin-console/authz/libraries/< your_library_id >
  3. Install the plugin https://github.com/openedx/openedx-authz by running tutor dev exec lms pip install git+https://github.com/openedx/openedx-authz
  4. Run the migrations tutor dev exec lms python manage.py lms migrate openedx_authz
  5. Load the default policies by running tutor dev exec lms python manage.py lms load_policies
  6. Click the button "Add New Team Member"
  7. Type a username or email, select a role, and click save; if the user exists, it should be displayed in the team members table; otherwise, you should see a proper error

Additional Information

@openedx-webhooks
Copy link

openedx-webhooks commented Sep 26, 2025

Thanks for the pull request, @bra-i-am!

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.


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.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 26, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Sep 26, 2025
@sarina
Copy link
Contributor

sarina commented Sep 29, 2025

@bra-i-am #2 merged, could you rebase and mark ready for review?

@codecov
Copy link

codecov bot commented Sep 29, 2025

Codecov Report

❌ Patch coverage is 96.12403% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.89%. Comparing base (b507311) to head (a273c49).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../AddNewTeamMemberModal/AddNewTeamMemberTrigger.tsx 95.83% 3 Missing ⚠️
...-module/libraries-manager/LibrariesTeamManager.tsx 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master       #3      +/-   ##
==========================================
+ Coverage   89.96%   91.89%   +1.93%     
==========================================
  Files          25       28       +3     
  Lines         269      395     +126     
  Branches       34       54      +20     
==========================================
+ Hits          242      363     +121     
- Misses         27       31       +4     
- Partials        0        1       +1     

☔ View full report in Codecov by Sentry.
📢 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.

@bra-i-am bra-i-am marked this pull request as ready for review September 29, 2025 20:36
@bra-i-am
Copy link
Contributor Author

@sarina, this PR is ready, thanks!

@bra-i-am bra-i-am requested a review from dcoa September 29, 2025 20:37
@bra-i-am bra-i-am changed the title feat: add button for adding new team members feat: add button & modal for adding new team members Sep 29, 2025
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Ready for Review in Contributions Sep 29, 2025
src/types.ts Outdated
slug: string;
}

export interface TeamRole {
Copy link
Contributor

@dcoa dcoa Sep 29, 2025

Choose a reason for hiding this comment

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

Important

The API contract for getting the roles and permissions is under validation here openedx/openedx-authz#16 (comment), waiting for the backend team feedback, it should not impact hardly what is managed in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding to this we decided that for the MVP the backend will retrieve only the mapping of roles and permission and any extra data will leave in the frontend (short-term). Here the PR with the metadata information #5

@bra-i-am hope for your review there and I hope the changes here are minimal after that.

@dcoa dcoa requested a review from holaontiveros September 30, 2025 02:07
@sarina
Copy link
Contributor

sarina commented Sep 30, 2025

@bra-i-am can you please ensure your PR title contains the FC number (FC-99 in this case) when you're working on Axim funded contribution projects? This helps the team who triages incoming PRs to the project know we have these under control. Thanks!

@sarina sarina added the FC Relates to an Axim Funded Contribution project label Sep 30, 2025
return camelCaseObject(res.data);
};

export const getTeamRoles = async (libraryId: string): Promise<TeamRole[]> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

[enhancement] not blocking for the current iteration but this endpoint can be used for other scopes within the AuthZ module, a more generic parameter is better.

});

/**
* React Query hook to add new team members to a specific library.
Copy link
Contributor

Choose a reason for hiding this comment

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

*
* @example
* ```tsx
* const { data: teamRoles, isLoading, isError } = useTeamRoles('lib:123');
Copy link
Contributor

Choose a reason for hiding this comment

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

[not blocking]

Suggested change
* const { data: teamRoles, isLoading, isError } = useTeamRoles('lib:123');
* const { data: teamRoles } = useTeamRoles('lib:123');

useSuspenseQuery does not return isLoading, isError , those are managed by Suspense and ErrorBoundary respectively.

<ModalDialog.CloseButton variant="tertiary" disabled={isLoading}>
{intl.formatMessage(messages['libraries.authz.manage.add.member.cancel.button'])}
</ModalDialog.CloseButton>
<Button
Copy link
Contributor

Choose a reason for hiding this comment

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

[enhancement] not blocking, Paragon has a component to work with buttons and states https://paragon-openedx.netlify.app/components/statefulbutton/

}));
};

const handleAddTeamMember = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is only one thing that is missing here, that is after a partial success the input, should display the error users in red (o just display the error users for now) and remove the completed ones.

Initial input
image
After submitting
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Solved 👍

/>
)}

{additionMessage && (
Copy link
Contributor

Choose a reason for hiding this comment

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

[enhancement] In the future should be reusable component across the application, for know is perfect, thank you

@bra-i-am bra-i-am changed the title feat: add button & modal for adding new team members feat: add button & modal for adding new team members [FC-99] Oct 2, 2025
@bra-i-am bra-i-am changed the title feat: add button & modal for adding new team members [FC-99] feat: add button & modal for adding new team members [FC-99] Oct 2, 2025
@bra-i-am bra-i-am changed the title feat: add button & modal for adding new team members [FC-99] feat: [FC-99] add button & modal for adding new team members Oct 2, 2025
@bra-i-am bra-i-am marked this pull request as draft October 8, 2025 21:08
<AddNewTeamMemberModal
isOpen={isOpen}
isError={isError}
close={close}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a extra function is needed here to reset the state when a error happens, something like:

  const handleClose = () => {
    setFormValues(DEFAULT_FORM_VALUES);
    setIsError(false)
    close();
  }

Copy link
Contributor

Choose a reason for hiding this comment

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

Solved 👍

@dcoa
Copy link
Contributor

dcoa commented Oct 21, 2025

@brian-smith-tcril
I just want to double check before removing the commit, I'm not being able to replicate the comma issue with both commits applied.

Screencast.from.2025-10-22.01-24-15.webm

However, I create a issue for finding a better way to manage the issue #14

render(<AuthZTitle {...defaultProps} actions={actions} />);

expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
expect(screen.getByTestId('custom-action')).toBeInTheDocument();
Copy link
Contributor

@jacobo-dominguez-wgu jacobo-dominguez-wgu Oct 21, 2025

Choose a reason for hiding this comment

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

A getByText query would be more focused on what the user sees on screen, since we are moving away from querying from testId

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for highlighting this, I will manage all that testId refactors in a separate PR, after the ulmo cut.

@brian-smith-tcril
Copy link

@brian-smith-tcril I just want to double check before removing the commit, I'm not being able to replicate the comma issue with both commits applied.

Screencast.from.2025-10-22.01-24-15.webm
However, I create a issue for finding a better way to manage the issue #14

Very odd. I just tried again and it's working as expected for me now. Must have been an environment issue on my side. Sorry about that!

Copy link

@brian-smith-tcril brian-smith-tcril left a comment

Choose a reason for hiding this comment

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

LGTM!

The non-blocking issues have been documented:

Copy link
Contributor

@jacobo-dominguez-wgu jacobo-dominguez-wgu left a comment

Choose a reason for hiding this comment

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

Tested on the sandbox and looks fine, good work!

@brian-smith-tcril brian-smith-tcril merged commit 52fbb7e into openedx:master Oct 21, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Ready for Review to Done in Contributions Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants