-
Notifications
You must be signed in to change notification settings - Fork 216
feat: adding permissions checks related to course section and units #3200
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
Open
jacobo-dominguez-wgu
wants to merge
3
commits into
openedx:master
Choose a base branch
from
WGU-Open-edX:feat/course-access-content-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/course-outline/outline-sidebar/info-sidebar/PublishButon.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { | ||
| initializeMocks, | ||
| render, | ||
| screen, | ||
| userEvent, | ||
| } from '@src/testUtils'; | ||
|
|
||
| import messages from '../messages'; | ||
| import { PublishButon } from './PublishButon'; | ||
|
|
||
| const mockCourseAuthoringContext = { | ||
| canPublishCourseContent: true, | ||
| }; | ||
|
|
||
| jest.mock('@src/CourseAuthoringContext', () => ({ | ||
| useCourseAuthoringContext: () => mockCourseAuthoringContext, | ||
| })); | ||
|
|
||
| const onClickMock = jest.fn(); | ||
|
|
||
| // The button's accessible name is the publish label plus the draft status, | ||
| // e.g. "Publish Changes (Draft)". | ||
| const publishButtonName = new RegExp(messages.publishContainerButton.defaultMessage, 'i'); | ||
|
|
||
| describe('<PublishButon />', () => { | ||
| beforeEach(() => { | ||
| initializeMocks(); | ||
| mockCourseAuthoringContext.canPublishCourseContent = true; | ||
| onClickMock.mockClear(); | ||
| }); | ||
|
|
||
| it('renders the publish button when the user can publish course content', async () => { | ||
| render(<PublishButon onClick={onClickMock} />); | ||
|
|
||
| expect( | ||
| await screen.findByRole('button', { name: publishButtonName }), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls onClick when the button is clicked', async () => { | ||
| const user = userEvent.setup(); | ||
| render(<PublishButon onClick={onClickMock} />); | ||
|
|
||
| await user.click(await screen.findByRole('button', { name: publishButtonName })); | ||
| expect(onClickMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('does not render the button when the user cannot publish course content', () => { | ||
| mockCourseAuthoringContext.canPublishCourseContent = false; | ||
| render(<PublishButon onClick={onClickMock} />); | ||
|
|
||
| expect( | ||
| screen.queryByRole('button', { name: publishButtonName }), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
35 changes: 21 additions & 14 deletions
35
src/course-outline/outline-sidebar/info-sidebar/PublishButon.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,29 @@ | ||
| import { FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
| import { Button } from '@openedx/paragon'; | ||
| import { useCourseAuthoringContext } from '@src/CourseAuthoringContext'; | ||
| import messages from '../messages'; | ||
|
|
||
| interface Props { | ||
| onClick: () => void; | ||
| } | ||
|
|
||
| export const PublishButon = ({ onClick }: Props) => ( | ||
| <Button | ||
| variant="outline-primary w-100 rounded status-button draft-status" | ||
| className="m-1" | ||
| onClick={onClick} | ||
| > | ||
| <strong className="mr-1"> | ||
| <FormattedMessage | ||
| {...messages.publishContainerButton} | ||
| /> | ||
| </strong> | ||
| <FormattedMessage {...messages.draftText} /> | ||
| </Button> | ||
| ); | ||
| export const PublishButon = ({ onClick }: Props) => { | ||
| const { canPublishCourseContent } = useCourseAuthoringContext(); | ||
|
|
||
| if (!canPublishCourseContent) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <Button | ||
| variant="outline-primary w-100 rounded status-button draft-status" | ||
| className="m-1" | ||
| onClick={onClick} | ||
| > | ||
| <strong className="mr-1"> | ||
| <FormattedMessage {...messages.publishContainerButton} /> | ||
| </strong> | ||
| <FormattedMessage {...messages.draftText} /> | ||
| </Button> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thank you for removing the class here, could you please do the same in unit (the second object in the array)?
Uh oh!
There was an error while loading. Please reload this page.
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.
Thank you I dont have any extra comments