Skip to content

Commit

Permalink
[Workspace] refactor: Remove permission validation in workspace form (#…
Browse files Browse the repository at this point in the history
…9065)

* refactor: remove permission verification in workspace form

Signed-off-by: tygao <[email protected]>

* Changeset file for PR #9065 created/updated

* remove extra import in test

Signed-off-by: tygao <[email protected]>

---------

Signed-off-by: tygao <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Yulong Ruan <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 9d21b81 commit c61c7cd
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 512 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9065.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refactor:
- Remove permission validation in workspace form ([#9065](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9065))
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ export enum WorkspaceFormErrorCode {
InvalidWorkspaceName,
WorkspaceNameMissing,
UseCaseMissing,
InvalidPermissionType,
InvalidPermissionModes,
PermissionUserIdMissing,
PermissionUserGroupMissing,
DuplicateUserIdPermissionSetting,
DuplicateUserGroupPermissionSetting,
PermissionSettingOwnerMissing,
InvalidDataSource,
DuplicateDataSource,
InvalidColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
*/

import { renderHook, act } from '@testing-library/react-hooks';

import { applicationServiceMock } from '../../../../../core/public/mocks';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspaceOperationType, WorkspacePermissionItemType } from './constants';
import { WorkspaceOperationType } from './constants';
import { WorkspaceFormSubmitData, WorkspaceFormErrorCode } from './types';
import { useWorkspaceForm } from './use_workspace_form';
import { waitFor } from '@testing-library/dom';
Expand Down Expand Up @@ -81,46 +79,6 @@ describe('useWorkspaceForm', () => {
);
expect(onSubmitMock).not.toHaveBeenCalled();
});
it('should return "Add workspace owner." and not call onSubmit', async () => {
const { renderResult, onSubmitMock } = setup({
defaultValues: {
id: 'foo',
name: 'test-workspace-name',
},
permissionEnabled: true,
});
expect(renderResult.result.current.formErrors).toEqual({});

act(() => {
renderResult.result.current.setPermissionSettings([
{
id: 0,
modes: [WorkspacePermissionMode.LibraryWrite, WorkspacePermissionMode.Write],
type: WorkspacePermissionItemType.User,
},
{
id: 1,
modes: [WorkspacePermissionMode.LibraryWrite, WorkspacePermissionMode.Write],
type: WorkspacePermissionItemType.Group,
},
]);
});
act(() => {
renderResult.result.current.handleFormSubmit({ preventDefault: jest.fn() });
});

expect(renderResult.result.current.formErrors).toEqual(
expect.objectContaining({
permissionSettings: {
overall: {
code: WorkspaceFormErrorCode.PermissionSettingOwnerMissing,
message: 'Add a workspace owner.',
},
},
})
);
expect(onSubmitMock).not.toHaveBeenCalled();
});
it('should call onSubmit with workspace name and features', async () => {
const { renderResult, onSubmitMock } = setup({
defaultValues: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const useWorkspaceForm = ({
application,
defaultValues,
onSubmit,
permissionEnabled,
onAppLeave,
}: WorkspaceFormProps) => {
const applications = useApplications(application);
Expand Down Expand Up @@ -109,10 +108,7 @@ export const useWorkspaceForm = ({
(item.type === WorkspacePermissionItemType.User && !!item.userId) ||
(item.type === WorkspacePermissionItemType.Group && !!item.group)
);
const currentFormErrors: WorkspaceFormErrors = validateWorkspaceForm(
currentFormData,
!!permissionEnabled
);
const currentFormErrors: WorkspaceFormErrors = validateWorkspaceForm(currentFormData);
setFormErrors(currentFormErrors);
if (getNumberOfErrors(currentFormErrors) > 0) {
return;
Expand All @@ -125,7 +121,7 @@ export const useWorkspaceForm = ({
setIsEditing(false);
}
},
[onSubmit, permissionEnabled]
[onSubmit]
);

const handleSubmitPermissionSettings = async (settings: WorkspacePermissionSetting[]) => {
Expand Down
Loading

0 comments on commit c61c7cd

Please sign in to comment.