Skip to content

Commit 6558c2b

Browse files
authored
fix: access restricted label refresh (#2846)
1 parent 747c2bc commit 6558c2b

4 files changed

Lines changed: 89 additions & 9 deletions

File tree

src/course-unit/CourseUnit.test.jsx

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,6 +2541,87 @@ describe('<CourseUnit />', () => {
25412541
expect(discussionButton).not.toBeChecked();
25422542
});
25432543

2544+
it('should update the group access in the unit sidebar', async () => {
2545+
const user = userEvent.setup();
2546+
2547+
setConfig({
2548+
...getConfig(),
2549+
ENABLE_UNIT_PAGE_NEW_DESIGN: 'true',
2550+
});
2551+
render(<RootWrapper />);
2552+
2553+
axiosMock
2554+
.onGet(getCourseSectionVerticalApiUrl(courseId))
2555+
.reply(200, {
2556+
...courseSectionVerticalMock,
2557+
});
2558+
axiosMock
2559+
.onPost(getXBlockBaseApiUrl(courseSectionVerticalMock.xblock_info.id))
2560+
.reply(200, {
2561+
...courseSectionVerticalMock,
2562+
});
2563+
axiosMock
2564+
.onGet(getCourseSectionVerticalApiUrl(blockId))
2565+
.reply(200, {
2566+
...courseSectionVerticalMock,
2567+
xblock_info: {
2568+
...courseSectionVerticalMock.xblock_info,
2569+
user_partition_info: {
2570+
selected_partition_index: 0,
2571+
selected_groups_label: 'Group A',
2572+
selectable_partitions: [{
2573+
id: 10,
2574+
name: 'Content Groups',
2575+
scheme: 'cohort',
2576+
groups: [
2577+
{
2578+
deleted: false,
2579+
id: 1,
2580+
name: 'Group A',
2581+
selected: true,
2582+
},
2583+
{
2584+
deleted: false,
2585+
id: 2,
2586+
name: 'Group B',
2587+
selected: false,
2588+
},
2589+
{
2590+
deleted: false,
2591+
id: 3,
2592+
name: 'Group C',
2593+
selected: false,
2594+
},
2595+
],
2596+
}],
2597+
},
2598+
},
2599+
});
2600+
await executeThunk(fetchCourseSectionVerticalData(courseId), store.dispatch);
2601+
await executeThunk(fetchCourseSectionVerticalData(blockId, courseId), store.dispatch);
2602+
2603+
// Move to settings
2604+
expect(await screen.findByRole('heading', { name: /draft \(unpublished changes\)/i })).toBeInTheDocument();
2605+
const settingsTab = screen.getByRole('tab', { name: /settings/i });
2606+
expect(settingsTab).toBeInTheDocument();
2607+
await user.click(settingsTab);
2608+
2609+
// Select groub
2610+
const groupCombobox = screen.getByTestId('group-type-select');
2611+
await user.selectOptions(groupCombobox, 'Content Groups');
2612+
await user.click(screen.getByRole('checkbox', { name: /Group A/i }));
2613+
await user.click(screen.getByRole('checkbox', { name: /Group B/i }));
2614+
await user.click(screen.getByRole('button', { name: /Save changes/i }));
2615+
2616+
// Check that the group access is being updated
2617+
await waitFor(() => {
2618+
expect(axiosMock.history.post.length).toBeGreaterThan(0);
2619+
});
2620+
2621+
expect(axiosMock.history.post[0].url).toBe(getXBlockBaseApiUrl(courseSectionVerticalMock.xblock_info.id));
2622+
expect(axiosMock.history.post[0].data).toMatch(/"group_access":\{"10":\[1,2\]\}/);
2623+
});
2624+
25442625
it('should one group in the visibility field in the unit sidebar', async () => {
25452626
setConfig({
25462627
...getConfig(),

src/course-unit/unit-sidebar/unit-info/UnitInfoSidebar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ const UnitInfoSettings = () => {
9595
isVisible,
9696
groupAccess,
9797
isDiscussionEnabled,
98-
() => sendMessageToIframe(messageTypes.completeManageXBlockAccess, { locator: id }),
98+
() => sendMessageToIframe(messageTypes.refreshXBlock, null),
9999
id,
100100
));
101101
};
102102

103-
/* istanbul ignore next */
104103
const handleSaveGroups = async (data, { resetForm }) => {
105104
const groupAccess = {};
106105
if (data.selectedPartitionIndex >= 0) {

src/course-unit/unit-sidebar/unit-info/UnitVisibilityInfo.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface UnitVisibilityInfoProps {
2323
},
2424
}
2525

26-
interface UnitvisibilityInfoContentProps {
26+
interface UnitVisibilityInfoContentProps {
2727
visibleToStaffOnly: boolean,
2828
userPartitionInfo?: {
2929
selectablePartitions: Record<string, any>[],
@@ -82,10 +82,10 @@ const LegacyVisibilityInfo = ({
8282
);
8383
};
8484

85-
const UnitvisibilityInfoContent = ({
85+
const UnitVisibilityInfoContent = ({
8686
visibleToStaffOnly,
8787
userPartitionInfo,
88-
}: UnitvisibilityInfoContentProps) => {
88+
}: UnitVisibilityInfoContentProps) => {
8989
const intl = useIntl();
9090
const { setCurrentTabKey } = useUnitSidebarContext();
9191

@@ -149,7 +149,7 @@ const UnitVisibilityInfo = ({
149149
<FormattedMessage {...messages.visibilityVisibleToTitle} />
150150
</span>
151151
{isUnitPageNewDesignEnabled() ? (
152-
<UnitvisibilityInfoContent
152+
<UnitVisibilityInfoContent
153153
visibleToStaffOnly={visibleToStaffOnly}
154154
userPartitionInfo={userPartitionInfo}
155155
/>

src/generic/configure-modal/UnitTab.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import classNames from 'classnames';
88
import { COURSE_BLOCK_NAMES } from '../../constants';
99
import messages from './messages';
1010

11-
export type UserpartitionInfo = {
11+
export type UserPartitionInfo = {
1212
selectablePartitions: {
1313
groups: {
1414
deleted: boolean,
@@ -35,7 +35,7 @@ export interface UnitTabProps {
3535
},
3636
setFieldValue: (key: string, value: any) => void,
3737
showWarning: boolean,
38-
userPartitionInfo: UserpartitionInfo,
38+
userPartitionInfo: UserPartitionInfo,
3939
}
4040

4141
export const DiscussionEditComponent = ({
@@ -56,7 +56,7 @@ export const DiscussionEditComponent = ({
5656
export interface AccessEditComponentProps {
5757
selectedPartitionIndex: number,
5858
setFieldValue: (key: string, value: any) => void,
59-
userPartitionInfo: UserpartitionInfo,
59+
userPartitionInfo: UserPartitionInfo,
6060
selectedGroups: string[],
6161
}
6262

0 commit comments

Comments
 (0)