Skip to content

Commit b1788c2

Browse files
bexsoftBenjamin Perez
andauthored
Disabled Object Locking button when permissions are not set (#2226)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net> Signed-off-by: Benjamin Perez <benjamin@bexsoft.net> Co-authored-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 2e1401f commit b1788c2

File tree

1 file changed

+35
-10
lines changed
  • portal-ui/src/screens/Console/Buckets/ListBuckets/AddBucket

1 file changed

+35
-10
lines changed

portal-ui/src/screens/Console/Buckets/ListBuckets/AddBucket/AddBucket.tsx

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717
import React, { Fragment, useEffect } from "react";
1818
import Grid from "@mui/material/Grid";
19-
import { Button, LinearProgress, Box } from "@mui/material";
19+
import { Box, Button, LinearProgress } from "@mui/material";
2020
import { Theme } from "@mui/material/styles";
21+
import { useNavigate } from "react-router-dom";
2122
import createStyles from "@mui/styles/createStyles";
2223
import withStyles from "@mui/styles/withStyles";
2324
import { containerForHeader } from "../../../Common/FormComponents/common/styleLibrary";
@@ -51,7 +52,8 @@ import {
5152
} from "./addBucketsSlice";
5253
import { addBucketAsync } from "./addBucketThunks";
5354
import AddBucketName from "./AddBucketName";
54-
import { useNavigate } from "react-router-dom";
55+
import { IAM_SCOPES } from "../../../../../common/SecureComponent/permissions";
56+
import { hasPermission } from "../../../../../common/SecureComponent";
5557

5658
const styles = (theme: Theme) =>
5759
createStyles({
@@ -142,6 +144,11 @@ const AddBucket = ({ classes }: IsetProps) => {
142144
(state: AppState) => state.addBucket.navigateTo
143145
);
144146

147+
const lockingAllowed = hasPermission("*", [
148+
IAM_SCOPES.S3_PUT_BUCKET_VERSIONING,
149+
IAM_SCOPES.S3_PUT_BUCKET_OBJECT_LOCK_CONFIGURATION,
150+
]);
151+
145152
const resForm = () => {
146153
dispatch(resetForm());
147154
};
@@ -178,15 +185,31 @@ const AddBucket = ({ classes }: IsetProps) => {
178185
<br />
179186
<b>Object Locking</b> prevents objects from being deleted.
180187
Required to support retention and legal hold. Can only be
181-
enabled at bucket creation.
188+
enabled at bucket creation.{" "}
189+
{!lockingAllowed ? (
190+
<Fragment>
191+
<br />
192+
<span>
193+
To enable this option{" "}
194+
<i>s3:PutBucketObjectLockConfiguration</i> and{" "}
195+
<i>s3:PutBucketVersioning</i> permissions must be set.
196+
</span>
197+
</Fragment>
198+
) : (
199+
""
200+
)}
182201
<br />
183202
<br />
184203
<b>Quota</b> limits the amount of data in the bucket.
185-
<br />
186-
<br />
187-
<b>Retention</b> imposes rules to prevent object deletion for
188-
a period of time. Versioning must be enabled in order to set
189-
bucket retention policies.
204+
{lockingAllowed && (
205+
<Fragment>
206+
<br />
207+
<br />
208+
<b>Retention</b> imposes rules to prevent object deletion
209+
for a period of time. Versioning must be enabled in order
210+
to set bucket retention policies.
211+
</Fragment>
212+
)}
190213
<br />
191214
<br />
192215
<b>Bucket Naming Rules</b>
@@ -340,7 +363,9 @@ const AddBucket = ({ classes }: IsetProps) => {
340363
value="locking"
341364
id="locking"
342365
name="locking"
343-
disabled={lockingFieldDisabled || !distributedSetup}
366+
disabled={
367+
lockingFieldDisabled || !distributedSetup || !lockingAllowed
368+
}
344369
checked={lockingEnabled}
345370
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
346371
dispatch(setEnableObjectLocking(event.target.checked));
@@ -399,7 +424,7 @@ const AddBucket = ({ classes }: IsetProps) => {
399424
</Grid>
400425
</React.Fragment>
401426
)}
402-
{versioningEnabled && distributedSetup && (
427+
{versioningEnabled && distributedSetup && lockingAllowed && (
403428
<Grid item xs={12}>
404429
<FormSwitchWrapper
405430
value="bucket_retention"

0 commit comments

Comments
 (0)