Repository navigation
fix: limit assignable roles to the user's manage-team permissions #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
dcoa marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||
| import { useMemo } from 'react'; | ||||||
| import { useIntl } from '@edx/frontend-platform/i18n'; | ||||||
| import { Person } from '@openedx/paragon/icons'; | ||||||
| import { useValidateUserPermissionsNonSuspense } from '@src/data/hooks'; | ||||||
| import { CONTENT_COURSE_PERMISSIONS, CONTENT_LIBRARY_PERMISSIONS } from '@src/authz-module/roles-permissions'; | ||||||
| import MultipleChoiceFilter from './MultipleChoiceFilter'; | ||||||
| import { MultipleChoiceFilterProps } from './types'; | ||||||
| import { getRolesFiltersOptions } from '../constants'; | ||||||
|
|
@@ -11,7 +13,27 @@ const RolesFilter = ({ | |||||
| filterButtonText, filterValue, setFilter, disabled, | ||||||
| }: RolesFilterProps) => { | ||||||
| const intl = useIntl(); | ||||||
| const rolesOptions = useMemo(() => getRolesFiltersOptions(intl), [intl]); | ||||||
| const { data: permissions } = useValidateUserPermissionsNonSuspense([ | ||||||
| { action: CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY_TEAM }, | ||||||
| { action: CONTENT_COURSE_PERMISSIONS.VIEW_COURSE_TEAM }, | ||||||
| ]); | ||||||
|
|
||||||
| // Only show role groups for the domains the user can view. Global roles stay | ||||||
| // hidden until a platform-wide permission is available to gate them on. | ||||||
| const allowedContexts = useMemo(() => { | ||||||
| const contexts = new Set<string>(); | ||||||
| permissions?.forEach((p) => { | ||||||
| if (!p.allowed) { return; } | ||||||
| if (p.action === CONTENT_LIBRARY_PERMISSIONS.VIEW_LIBRARY_TEAM) { contexts.add('library'); } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @bra-i-am, I made the nit changes. |
||||||
| if (p.action === CONTENT_COURSE_PERMISSIONS.VIEW_COURSE_TEAM) { contexts.add('course'); } | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit
Suggested change
|
||||||
| }); | ||||||
| return contexts; | ||||||
| }, [permissions]); | ||||||
|
|
||||||
| const rolesOptions = useMemo( | ||||||
| () => getRolesFiltersOptions(intl).filter((option) => allowedContexts.has(option.contextType)), | ||||||
| [intl, allowedContexts], | ||||||
| ); | ||||||
| return ( | ||||||
| <MultipleChoiceFilter | ||||||
| filterButtonText={filterButtonText} | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe this can be a constant because these permissions are used in
AssignRoleWizardPage.tsxtoo