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

HMS-5197: Fixes List snapshot being disabled for read only users #407

Merged
merged 2 commits into from
Jan 10, 2025
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
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
Loading