Skip to content

Commit

Permalink
fix: restrict available orgs on library creation
Browse files Browse the repository at this point in the history
  • Loading branch information
pomegranited committed Jan 14, 2025
1 parent a25a09e commit 552ffcc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/library-authoring/create-library/CreateLibrary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ describe('<CreateLibrary />', () => {
userEvent.click(titleInput);
userEvent.type(titleInput, 'Test Library Name');

// We cannot create a new org, and so we're restricted to the allowed list
const orgOptions = screen.getByTestId('autosuggest-iconbutton');
userEvent.click(orgOptions);
expect(screen.getByText('org1')).toBeInTheDocument();
['org2', 'org3', 'org4', 'org5'].forEach((org) => expect(screen.queryByText(org)).not.toBeInTheDocument());

const orgInput = await screen.findByRole('combobox', { name: /organization/i });
userEvent.click(orgInput);
userEvent.type(orgInput, 'NewOrg');
Expand All @@ -108,7 +114,6 @@ describe('<CreateLibrary />', () => {
axiosMock.onGet(getStudioHomeApiUrl()).reply(200, {
...studioHomeMock,
allow_to_create_new_org: true,
allowToCreateNewOrg: true,
});
axiosMock.onPost(getContentLibraryV2CreateApiUrl()).reply(200, {
id: 'library-id',
Expand All @@ -120,6 +125,11 @@ describe('<CreateLibrary />', () => {
userEvent.click(titleInput);
userEvent.type(titleInput, 'Test Library Name');

// We can create a new org, so we're also allowed to use any existing org
const orgOptions = screen.getByTestId('autosuggest-iconbutton');
userEvent.click(orgOptions);
['org1', 'org2', 'org3', 'org4', 'org5'].forEach((org) => expect(screen.queryByText(org)).toBeInTheDocument());

const orgInput = await screen.findByRole('combobox', { name: /organization/i });
userEvent.click(orgInput);
userEvent.type(orgInput, 'NewOrg');
Expand Down
19 changes: 15 additions & 4 deletions src/library-authoring/create-library/CreateLibrary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,22 @@ const CreateLibrary = () => {
} = useCreateLibraryV2();

const {
data: organizationListData,
data: allOrganizations,
isLoading: isOrganizationListLoading,
} = useOrganizationListData();

const { studioHomeData: { allowToCreateNewOrg } } = useStudioHome();
const {
studioHomeData: {
allowedOrganizationsForLibraries,
allowToCreateNewOrg,
},
} = useStudioHome();

const organizations = (
allowToCreateNewOrg
? allOrganizations
: allowedOrganizationsForLibraries
) || [];

const handleOnClickCancel = () => {
navigate('/libraries');
Expand Down Expand Up @@ -111,9 +122,9 @@ const CreateLibrary = () => {
)}
placeholder={intl.formatMessage(messages.orgPlaceholder)}
>
{organizationListData ? organizationListData.map((org) => (
{organizations.map((org) => (
<Form.AutosuggestOption key={org} id={org}>{org}</Form.AutosuggestOption>
)) : []}
))}
</Form.Autosuggest>
<FormikErrorFeedback name="org">
<Form.Text>{intl.formatMessage(messages.orgHelp)}</Form.Text>
Expand Down
1 change: 1 addition & 0 deletions src/studio-home/__mocks__/studioHomeMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ module.exports = {
platformName: 'Your Platform Name Here',
userIsActive: true,
allowToCreateNewOrg: false,
allowedOrganizationsForLibraries: ['org1'],
};

0 comments on commit 552ffcc

Please sign in to comment.