From 6558c2b1eda24524187f24ce4ebb080f3a44de4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Fri, 30 Jan 2026 19:09:42 -0300 Subject: [PATCH] fix: access restricted label refresh (#2846) --- src/course-unit/CourseUnit.test.jsx | 81 +++++++++++++++++++ .../unit-info/UnitInfoSidebar.tsx | 3 +- .../unit-info/UnitVisibilityInfo.tsx | 8 +- src/generic/configure-modal/UnitTab.tsx | 6 +- 4 files changed, 89 insertions(+), 9 deletions(-) diff --git a/src/course-unit/CourseUnit.test.jsx b/src/course-unit/CourseUnit.test.jsx index 377a8197d..2d58f1d8b 100644 --- a/src/course-unit/CourseUnit.test.jsx +++ b/src/course-unit/CourseUnit.test.jsx @@ -2541,6 +2541,87 @@ describe('', () => { expect(discussionButton).not.toBeChecked(); }); + it('should update the group access in the unit sidebar', async () => { + const user = userEvent.setup(); + + setConfig({ + ...getConfig(), + ENABLE_UNIT_PAGE_NEW_DESIGN: 'true', + }); + render(); + + axiosMock + .onGet(getCourseSectionVerticalApiUrl(courseId)) + .reply(200, { + ...courseSectionVerticalMock, + }); + axiosMock + .onPost(getXBlockBaseApiUrl(courseSectionVerticalMock.xblock_info.id)) + .reply(200, { + ...courseSectionVerticalMock, + }); + axiosMock + .onGet(getCourseSectionVerticalApiUrl(blockId)) + .reply(200, { + ...courseSectionVerticalMock, + xblock_info: { + ...courseSectionVerticalMock.xblock_info, + user_partition_info: { + selected_partition_index: 0, + selected_groups_label: 'Group A', + selectable_partitions: [{ + id: 10, + name: 'Content Groups', + scheme: 'cohort', + groups: [ + { + deleted: false, + id: 1, + name: 'Group A', + selected: true, + }, + { + deleted: false, + id: 2, + name: 'Group B', + selected: false, + }, + { + deleted: false, + id: 3, + name: 'Group C', + selected: false, + }, + ], + }], + }, + }, + }); + await executeThunk(fetchCourseSectionVerticalData(courseId), store.dispatch); + await executeThunk(fetchCourseSectionVerticalData(blockId, courseId), store.dispatch); + + // Move to settings + expect(await screen.findByRole('heading', { name: /draft \(unpublished changes\)/i })).toBeInTheDocument(); + const settingsTab = screen.getByRole('tab', { name: /settings/i }); + expect(settingsTab).toBeInTheDocument(); + await user.click(settingsTab); + + // Select groub + const groupCombobox = screen.getByTestId('group-type-select'); + await user.selectOptions(groupCombobox, 'Content Groups'); + await user.click(screen.getByRole('checkbox', { name: /Group A/i })); + await user.click(screen.getByRole('checkbox', { name: /Group B/i })); + await user.click(screen.getByRole('button', { name: /Save changes/i })); + + // Check that the group access is being updated + await waitFor(() => { + expect(axiosMock.history.post.length).toBeGreaterThan(0); + }); + + expect(axiosMock.history.post[0].url).toBe(getXBlockBaseApiUrl(courseSectionVerticalMock.xblock_info.id)); + expect(axiosMock.history.post[0].data).toMatch(/"group_access":\{"10":\[1,2\]\}/); + }); + it('should one group in the visibility field in the unit sidebar', async () => { setConfig({ ...getConfig(), diff --git a/src/course-unit/unit-sidebar/unit-info/UnitInfoSidebar.tsx b/src/course-unit/unit-sidebar/unit-info/UnitInfoSidebar.tsx index 9ab706963..7adc8d9ee 100644 --- a/src/course-unit/unit-sidebar/unit-info/UnitInfoSidebar.tsx +++ b/src/course-unit/unit-sidebar/unit-info/UnitInfoSidebar.tsx @@ -95,12 +95,11 @@ const UnitInfoSettings = () => { isVisible, groupAccess, isDiscussionEnabled, - () => sendMessageToIframe(messageTypes.completeManageXBlockAccess, { locator: id }), + () => sendMessageToIframe(messageTypes.refreshXBlock, null), id, )); }; - /* istanbul ignore next */ const handleSaveGroups = async (data, { resetForm }) => { const groupAccess = {}; if (data.selectedPartitionIndex >= 0) { diff --git a/src/course-unit/unit-sidebar/unit-info/UnitVisibilityInfo.tsx b/src/course-unit/unit-sidebar/unit-info/UnitVisibilityInfo.tsx index 9f6b69b3b..d5536ea68 100644 --- a/src/course-unit/unit-sidebar/unit-info/UnitVisibilityInfo.tsx +++ b/src/course-unit/unit-sidebar/unit-info/UnitVisibilityInfo.tsx @@ -23,7 +23,7 @@ interface UnitVisibilityInfoProps { }, } -interface UnitvisibilityInfoContentProps { +interface UnitVisibilityInfoContentProps { visibleToStaffOnly: boolean, userPartitionInfo?: { selectablePartitions: Record[], @@ -82,10 +82,10 @@ const LegacyVisibilityInfo = ({ ); }; -const UnitvisibilityInfoContent = ({ +const UnitVisibilityInfoContent = ({ visibleToStaffOnly, userPartitionInfo, -}: UnitvisibilityInfoContentProps) => { +}: UnitVisibilityInfoContentProps) => { const intl = useIntl(); const { setCurrentTabKey } = useUnitSidebarContext(); @@ -149,7 +149,7 @@ const UnitVisibilityInfo = ({ {isUnitPageNewDesignEnabled() ? ( - diff --git a/src/generic/configure-modal/UnitTab.tsx b/src/generic/configure-modal/UnitTab.tsx index ea189ed2d..3577a23c1 100644 --- a/src/generic/configure-modal/UnitTab.tsx +++ b/src/generic/configure-modal/UnitTab.tsx @@ -8,7 +8,7 @@ import classNames from 'classnames'; import { COURSE_BLOCK_NAMES } from '../../constants'; import messages from './messages'; -export type UserpartitionInfo = { +export type UserPartitionInfo = { selectablePartitions: { groups: { deleted: boolean, @@ -35,7 +35,7 @@ export interface UnitTabProps { }, setFieldValue: (key: string, value: any) => void, showWarning: boolean, - userPartitionInfo: UserpartitionInfo, + userPartitionInfo: UserPartitionInfo, } export const DiscussionEditComponent = ({ @@ -56,7 +56,7 @@ export const DiscussionEditComponent = ({ export interface AccessEditComponentProps { selectedPartitionIndex: number, setFieldValue: (key: string, value: any) => void, - userPartitionInfo: UserpartitionInfo, + userPartitionInfo: UserPartitionInfo, selectedGroups: string[], }