Skip to content

Commit

Permalink
disabled delete and fixed enabled for non admins
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Jun 10, 2021
1 parent 508a02a commit 07ea9af
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { useMetadataEntity } from '../../../hooks/api';
import Translate from '../../../../i18n/components/translate';
import { noop } from 'lodash';

import { useIsAdmin } from '../../../../core/user/UserContext';

export function DeleteSourceConfirmation ({children}) {

const { del, response } = useMetadataEntity('source');
Expand All @@ -34,9 +36,11 @@ export function DeleteSourceConfirmation ({children}) {
}
}

const isAdmin = useIsAdmin();

return (
<>
{children(onDeleteSource)}
{children(isAdmin ? onDeleteSource : false)}
<Modal show={!!deleting} onHide={() => setDeleting(null)}>
<Modal.Header><Translate value="message.delete-source-title">Delete Metadata Source?</Translate></Modal.Header>
<Modal.Body className="d-flex align-content-center">
Expand Down
7 changes: 3 additions & 4 deletions ui/src/app/metadata/domain/source/component/SourceList.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function SourceList({ entities, onDelete, onEnable }) {
<th className="w-15"><Translate value="label.author">Author</Translate></th>
<th className="w-15"><Translate value="label.creation-date">Created Date</Translate></th>
<th className="text-center w-15"><Translate value="label.enabled">Enabled</Translate></th>
<th className="w-auto"></th>
{onDeleteSource && <th className="w-auto"></th>}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -66,7 +66,7 @@ export default function SourceList({ entities, onDelete, onEnable }) {
</td>


<td className="text-right">
{onDeleteSource && <td className="text-right">
<OverlayTrigger trigger={source.serviceEnabled ? ['hover', 'focus'] : []} placement="left"
overlay={
<Popover id={`delete-source-btn-${idx}`}>
Expand All @@ -83,8 +83,7 @@ export default function SourceList({ entities, onDelete, onEnable }) {
</Button>
</span>
</OverlayTrigger>
</td>

</td>}
</tr>
)}
</tbody>
Expand Down
17 changes: 16 additions & 1 deletion ui/src/app/metadata/hooks/schema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { useIsAdmin } from '../../core/user/UserContext';

const fillInRootProperties = (keys, ui) => {
return keys.reduce((sch, key, idx) => {
Expand Down Expand Up @@ -34,7 +35,21 @@ export function useUiSchema(definition, schema, current, locked = true) {
};
}, [mapped, step.locked, locked]);

return {uiSchema: isLocked, step};
const isAdmin = useIsAdmin();

const hideEnableFromNonAdmins = React.useMemo(() => {
if (!isAdmin) {
return {
...isLocked,
serviceEnabled: {
'ui:widget': 'hidden'
}
};
}
return isLocked;
}, [isAdmin, isLocked]);

return { uiSchema: hideEnableFromNonAdmins, step};
}


Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/metadata/view/MetadataOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function MetadataOptions () {
current={true}
enabled={type === 'source' ? metadata.serviceEnabled : metadata.enabled}
model={metadata}>
{type === 'source' &&
{type === 'source' && onDeleteSource &&
<button className="btn btn-outline btn-sm btn-danger align-self-start"
disabled={metadata.serviceEnabled}
onClick={() => onDeleteSource(metadata.id, redirectOnDelete)}>
Expand Down

0 comments on commit 07ea9af

Please sign in to comment.