Skip to content
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

CSCFC4EMSCR-612 Hide create content buttons from group members #234

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions mscr-ui/src/common/utils/has-permission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ import { Roles } from '../interfaces/format.interface';

// Need to specify the actions permitted for each type of user
const actions = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this long list of actions, if we are not using it or have plan to use? Are they important for any context?

// 'CREATE_SCHEMA',
// 'EDIT_SCHEMA',
// 'EDIT_SCHEMA_METADATA',
// 'EDIT_SCHEMA_FILES',
// 'DELETE_SCHEMA',
// 'CREATE_CROSSWALK',
// 'EDIT_CROSSWALK_MAPPINGS',
// 'EDIT_CROSSWALK_METADATA',
// 'EDIT_CROSSWALK_FILES',
// 'DELETE_CROSSWALK',
'CREATE_CONTENT',
'EDIT_CONTENT',
'MAKE_MSCR_COPY',
] as const;
Expand Down Expand Up @@ -77,7 +76,7 @@ export default function HasPermission({ action, owner }: hasPermissionProps) {
}

export function checkPermission({ user, action, owner }: checkPermissionProps) {
if (action == 'EDIT_CONTENT'||'MAKE_MSCR_COPY') {
if (action == 'EDIT_CONTENT' || action == 'CREATE_CONTENT' || action == 'MAKE_MSCR_COPY') {
if (owner?.includes(user.id)) {
//user is the owner, Check for personal Contents
return true;
Expand Down
99 changes: 53 additions & 46 deletions mscr-ui/src/modules/workspace/group-home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import FormModal, { ModalType } from '@app/modules/form';
import Link from 'next/link';
import { SpinnerWrapper } from '@app/modules/crosswalk-view/crosswalk-view.styles';
import SpinnerOverlay from '@app/common/components/spinner-overlay';
import HasPermission from '@app/common/utils/has-permission';

interface GroupHomeProps {
user: MscrUser;
Expand All @@ -34,6 +35,10 @@ export default function GroupWorkspace({
pid,
contentType,
}: GroupHomeProps) {
const hasCreatePermission = HasPermission({
action: 'CREATE_CONTENT',
owner: [pid],
});
const { t } = useTranslation('common');
const router = useRouter();
const lang = router.locale ?? '';
Expand Down Expand Up @@ -122,52 +127,54 @@ export default function GroupWorkspace({
</TitleDescriptionWrapper>
}
/>
<Separator isLarge />
<div>
<ButtonBlock>
{contentType == 'SCHEMA' ? (
<>
<ModalVisibilityButton
setVisible={setRegisterSchemaModalVisible}
label={t('content-form.button.schema-register')}
/>
<FormModal
modalType={ModalType.RegisterNewFull}
contentType={Type.Schema}
visible={registerSchemaModalVisible}
setVisible={setRegisterSchemaModalVisible}
organizationPid={pid}
/>
</>
) : (
<>
<ModalVisibilityButton
setVisible={setRegisterCrosswalkModalVisible}
label={t('content-form.button.crosswalk-register')}
/>
<FormModal
modalType={ModalType.RegisterNewFull}
contentType={Type.Crosswalk}
visible={registerCrosswalkModalVisible}
setVisible={setRegisterCrosswalkModalVisible}
organizationPid={pid}
/>
<ModalVisibilityButton
setVisible={setCreateCrosswalkModalVisible}
label={t('content-form.button.crosswalk-create')}
/>
<FormModal
modalType={ModalType.RegisterNewMscr}
contentType={Type.Crosswalk}
visible={createCrosswalkModalVisible}
setVisible={setCreateCrosswalkModalVisible}
organizationPid={pid}
/>
</>
)}
</ButtonBlock>
</div>
<Separator isLarge />
{hasCreatePermission &&
<div>
<Separator isLarge />
<ButtonBlock>
{contentType == 'SCHEMA' ? (
<>
<ModalVisibilityButton
setVisible={setRegisterSchemaModalVisible}
label={t('content-form.button.schema-register')}
/>
<FormModal
modalType={ModalType.RegisterNewFull}
contentType={Type.Schema}
visible={registerSchemaModalVisible}
setVisible={setRegisterSchemaModalVisible}
organizationPid={pid}
/>
</>
) : (
<>
<ModalVisibilityButton
setVisible={setRegisterCrosswalkModalVisible}
label={t('content-form.button.crosswalk-register')}
/>
<FormModal
modalType={ModalType.RegisterNewFull}
contentType={Type.Crosswalk}
visible={registerCrosswalkModalVisible}
setVisible={setRegisterCrosswalkModalVisible}
organizationPid={pid}
/>
<ModalVisibilityButton
setVisible={setCreateCrosswalkModalVisible}
label={t('content-form.button.crosswalk-create')}
/>
<FormModal
modalType={ModalType.RegisterNewMscr}
contentType={Type.Crosswalk}
visible={createCrosswalkModalVisible}
setVisible={setCreateCrosswalkModalVisible}
organizationPid={pid}
/>
</>
)}
</ButtonBlock>
<Separator isLarge />
</div>
}
{data?.hits.hits && data?.hits.hits.length < 1 ? (
<div>
{contentType == 'SCHEMA'
Expand Down
Loading