Skip to content

Commit

Permalink
HMS-5197: Fixes List snapshot being disabled for read only users (#407)
Browse files Browse the repository at this point in the history
* HMS-5197: Fixes List snapshot being disabled for read only users

* Update lint
  • Loading branch information
Andrewgdewar authored Jan 10, 2025
1 parent 89e4826 commit 0785455
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
56 changes: 30 additions & 26 deletions src/Pages/Repositories/ContentListTable/ContentListTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,26 @@ const ContentListTable = () => {
]
: []
: [
{
isDisabled: actionTakingPlace || rowData?.status === 'Pending',
title: 'Edit',
onClick: () => {
navigate(`${rowData.uuid}/${EDIT_ROUTE}`);
},
},
...(rowData.origin === ContentOrigin.UPLOAD
...(rbac?.repoWrite
? [
{
isDisabled: actionTakingPlace || rowData?.status === 'Pending',
title: 'Upload content',
title: 'Edit',
onClick: () => {
navigate(`${rowData.uuid}/${UPLOAD_ROUTE}`);
navigate(`${rowData.uuid}/${EDIT_ROUTE}`);
},
},
...(rowData.origin === ContentOrigin.UPLOAD
? [
{
isDisabled: actionTakingPlace || rowData?.status === 'Pending',
title: 'Upload content',
onClick: () => {
navigate(`${rowData.uuid}/${UPLOAD_ROUTE}`);
},
},
]
: []),
]
: []),
...(features?.snapshots?.accessible
Expand All @@ -330,7 +334,7 @@ const ContentListTable = () => {
navigate(`${rowData.uuid}/snapshots`);
},
},
...(rowData.origin !== ContentOrigin.UPLOAD
...(rbac?.repoWrite && rowData.origin !== ContentOrigin.UPLOAD
? [
{
id: 'actions-column-snapshot',
Expand Down Expand Up @@ -358,7 +362,7 @@ const ContentListTable = () => {
: []),
]
: []),
...(!rowData?.snapshot
...(rbac?.repoWrite && !rowData?.snapshot
? [
{
isDisabled: actionTakingPlace || rowData?.status == 'Pending',
Expand All @@ -368,11 +372,15 @@ const ContentListTable = () => {
},
]
: []),
{ isSeparator: true },
{
title: 'Delete',
onClick: () => navigate(`${DELETE_ROUTE}?repoUUID=${rowData.uuid}`),
},
...(rbac?.repoWrite
? [
{ isSeparator: true },
{
title: 'Delete',
onClick: () => navigate(`${DELETE_ROUTE}?repoUUID=${rowData.uuid}`),
},
]
: []),
],
[actionTakingPlace, checkedRepositories, isRedHatRepository],
);
Expand Down Expand Up @@ -630,15 +638,11 @@ const ContentListTable = () => {
<Hide hide={!rowActions(rowData)?.length}>
<Td isActionCell>
<ConditionalTooltip
content={
rowData?.status == 'Pending'
? showPendingTooltip(
rowData?.last_snapshot_task?.status,
rowData.status,
)
: 'You do not have the required permissions to perform this action.'
}
show={!isRedHatRepository && !rbac?.repoWrite}
content={showPendingTooltip(
rowData?.last_snapshot_task?.status,
rowData.status,
)}
show={!isRedHatRepository && rowData?.status === 'Pending'}
setDisabled
>
<ActionsColumn items={rowActions(rowData)} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable quotes */
import {
Button,
Flex,
Expand Down
2 changes: 1 addition & 1 deletion src/components/SharedTables/AdvisoriesTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function AdvisoriesTable({
</Tr>
</Thead>
</Hide>
{[...new Map(errataList.map(e => [e.errata_id, e])).values()].map(
{[...new Map(errataList.map((e) => [e.errata_id, e])).values()].map(
(
{
errata_id,
Expand Down
14 changes: 12 additions & 2 deletions src/middleware/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ import { useFetchSubscriptionsQuery } from 'services/Subscriptions/SubscriptionQ
const getRegistry = _getRegistry as unknown as () => { register: ({ notifications }) => void };
const { appname } = PackageJson.insights;

// Add permissions here
export enum RbacPermissions {
'repoRead', // If the user doesn't have this permission, they won't see the app, it is thus presumed true.
'repoWrite',
'templateWrite',
'templateRead',
}

export interface AppContextInterface {
rbac?: Record<string, boolean>;
rbac?: Record<keyof typeof RbacPermissions, boolean>;
features: Features | null;
isFetchingPermissions: boolean;
subscriptions?: Subscriptions;
Expand All @@ -29,7 +37,9 @@ export interface AppContextInterface {
export const AppContext = createContext({} as AppContextInterface);

export const ContextProvider = ({ children }: { children: ReactNode }) => {
const [rbac, setRbac] = useState<Record<string, boolean> | undefined>(undefined);
const [rbac, setRbac] = useState<Record<keyof typeof RbacPermissions, boolean> | undefined>(
undefined,
);
const [zeroState, setZeroState] = useState(true);
const [features, setFeatures] = useState<Features | null>(null);
const chrome = useChrome();
Expand Down

0 comments on commit 0785455

Please sign in to comment.