Skip to content

Commit 5eddd0c

Browse files
authored
Permission Error handling and Tooltips for upload file, object action buttons (#2338)
![Screen Shot 2022-09-26 at 11 51 34 AM](https://user-images.githubusercontent.com/65002498/192357633-2f551441-8c27-450e-873e-1766d388cdb0.png) <img width="706" alt="Screen Shot 2022-09-23 at 11 38 59 AM" src="https://user-images.githubusercontent.com/65002498/192035299-093f814e-4821-4610-8fc5-c20565ea7c38.png"> <img width="642" alt="Screen Shot 2022-09-23 at 11 47 15 AM" src="https://user-images.githubusercontent.com/65002498/192036512-f8891625-e050-42fd-9c43-173dd61c4df3.png">
1 parent 5cf2b73 commit 5eddd0c

File tree

6 files changed

+232
-84
lines changed

6 files changed

+232
-84
lines changed

portal-ui/src/common/SecureComponent/permissions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,13 +435,13 @@ export const CONSOLE_UI_RESOURCE = "console-ui";
435435

436436
export const permissionTooltipHelper = (scopes: string[], name: string) => {
437437
return (
438-
"You require additional permissions in order to enable " +
438+
"You require additional permissions in order to " +
439439
name +
440440
". Please ask your MinIO administrator to grant you " +
441441
scopes +
442442
" permission" +
443443
(scopes.length > 1 ? "s" : "") +
444-
" in order to enable " +
444+
" in order to " +
445445
name +
446446
"."
447447
);

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ActionsListSection.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import ObjectActionButton from "./ObjectActionButton";
1919
import { withStyles } from "@mui/styles";
2020
import createStyles from "@mui/styles/createStyles";
2121
import { detailsPanel } from "../../../../Common/FormComponents/common/styleLibrary";
22+
import TooltipWrapper from "../../../../Common/TooltipWrapper/TooltipWrapper";
2223

2324
const styles = () =>
2425
createStyles({
@@ -52,12 +53,14 @@ const ActionsListSection = ({
5253
{items.map((actionItem, index) => {
5354
return (
5455
<li key={`action-element-${index.toString()}`}>
55-
<ObjectActionButton
56-
label={actionItem.label}
57-
icon={actionItem.icon}
58-
onClick={actionItem.action}
59-
disabled={actionItem.disabled}
60-
/>
56+
<TooltipWrapper tooltip={actionItem.tooltip || ""}>
57+
<ObjectActionButton
58+
label={actionItem.label}
59+
icon={actionItem.icon}
60+
onClick={actionItem.action}
61+
disabled={actionItem.disabled}
62+
/>
63+
</TooltipWrapper>
6164
</li>
6265
);
6366
})}

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjects.tsx

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ import ScreenTitle from "../../../../Common/ScreenTitle/ScreenTitle";
7171
import { AppState, useAppDispatch } from "../../../../../../store";
7272
import PageLayout from "../../../../Common/Layout/PageLayout";
7373

74-
import { IAM_SCOPES } from "../../../../../../common/SecureComponent/permissions";
74+
import {
75+
IAM_SCOPES,
76+
permissionTooltipHelper,
77+
} from "../../../../../../common/SecureComponent/permissions";
7578
import {
7679
hasPermission,
7780
SecureComponent,
@@ -1055,11 +1058,23 @@ const ListObjects = () => {
10551058

10561059
const onDrop = useCallback(
10571060
(acceptedFiles: any[]) => {
1058-
if (acceptedFiles && acceptedFiles.length > 0) {
1061+
if (acceptedFiles && acceptedFiles.length > 0 && canUpload) {
10591062
let newFolderPath: string = acceptedFiles[0].path;
10601063
uploadObject(acceptedFiles, newFolderPath);
10611064
}
1065+
if (!canUpload) {
1066+
dispatch(
1067+
setErrorSnackMessage({
1068+
errorMessage: "Upload not allowed",
1069+
detailedError: permissionTooltipHelper(
1070+
[IAM_SCOPES.S3_PUT_OBJECT],
1071+
"upload objects to this location"
1072+
),
1073+
})
1074+
);
1075+
}
10621076
},
1077+
// eslint-disable-next-line react-hooks/exhaustive-deps
10631078
[uploadObject]
10641079
);
10651080

@@ -1221,6 +1236,10 @@ const ListObjects = () => {
12211236
uploadPath = uploadPath.concat(currentPath);
12221237
}
12231238

1239+
const canDownload = hasPermission(bucketName, [IAM_SCOPES.S3_GET_OBJECT]);
1240+
const canDelete = hasPermission(bucketName, [IAM_SCOPES.S3_DELETE_OBJECT]);
1241+
const canUpload = hasPermission(uploadPath, [IAM_SCOPES.S3_PUT_OBJECT]);
1242+
12241243
const onClosePanel = (forceRefresh: boolean) => {
12251244
dispatch(setSelectedObjectView(null));
12261245
dispatch(setVersionsModeEnabled({ status: false }));
@@ -1272,23 +1291,28 @@ const ListObjects = () => {
12721291
{
12731292
action: downloadSelected,
12741293
label: "Download",
1275-
disabled: selectedObjects.length === 0,
1294+
disabled: !canDownload || selectedObjects.length === 0,
12761295
icon: <DownloadIcon />,
1277-
tooltip: "Download Selected",
1296+
tooltip: canDownload
1297+
? "Download Selected"
1298+
: permissionTooltipHelper(
1299+
[IAM_SCOPES.S3_GET_OBJECT],
1300+
"download objects from this bucket"
1301+
),
12781302
},
12791303
{
12801304
action: openShare,
12811305
label: "Share",
12821306
disabled: selectedObjects.length !== 1 || !canShareFile,
12831307
icon: <ShareIcon />,
1284-
tooltip: "Share Selected File",
1308+
tooltip: canShareFile ? "Share Selected File" : "Sharing unavailable",
12851309
},
12861310
{
12871311
action: openPreview,
12881312
label: "Preview",
12891313
disabled: selectedObjects.length !== 1 || !canPreviewFile,
12901314
icon: <PreviewIcon />,
1291-
tooltip: "Preview Selected File",
1315+
tooltip: canPreviewFile ? "Preview Selected File" : "Preview unavailable",
12921316
},
12931317
{
12941318
action: () => {
@@ -1297,10 +1321,13 @@ const ListObjects = () => {
12971321
label: "Delete",
12981322
icon: <DeleteIcon />,
12991323
disabled:
1300-
!hasPermission(bucketName, [IAM_SCOPES.S3_DELETE_OBJECT]) ||
1301-
selectedObjects.length === 0 ||
1302-
!displayDeleteObject,
1303-
tooltip: "Delete Selected Files",
1324+
!canDelete || selectedObjects.length === 0 || !displayDeleteObject,
1325+
tooltip: canDelete
1326+
? "Delete Selected Files"
1327+
: permissionTooltipHelper(
1328+
[IAM_SCOPES.S3_DELETE_OBJECT],
1329+
"delete objects in this bucket"
1330+
),
13041331
},
13051332
];
13061333

0 commit comments

Comments
 (0)