Skip to content

Commit c417cc3

Browse files
adfostAdam Staffordbexsoft
authored
Edit access rules (#959)
Co-authored-by: Adam Stafford <adamstafford@Adams-MacBook-Pro.local> Co-authored-by: Alex <33497058+bexsoft@users.noreply.github.com>
1 parent ec47df3 commit c417cc3

File tree

4 files changed

+163
-4
lines changed

4 files changed

+163
-4
lines changed

portal-ui/src/screens/Console/Buckets/BucketDetails/AccessRulePanel.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import TableWrapper from "../../Common/TableWrapper/TableWrapper";
2626
import api from "../../../../common/api";
2727
import AddAccessRuleModal from "./AddAccessRule";
2828
import DeleteAccessRuleModal from "./DeleteAccessRule";
29+
import EditAccessRuleModal from "./EditAccessRule";
2930
import { CreateIcon } from "../../../../icons";
3031
import Grid from "@material-ui/core/Grid";
3132
import {
@@ -130,6 +131,9 @@ const AccessRule = ({
130131
const [deleteAccessRuleOpen, setDeleteAccessRuleOpen] =
131132
useState<boolean>(false);
132133
const [accessRuleToDelete, setAccessRuleToDelete] = useState<string>("");
134+
const [editAccessRuleOpen, setEditAccessRuleOpen] = useState<boolean>(false);
135+
const [accessRuleToEdit, setAccessRuleToEdit] = useState<string>("");
136+
const [initialAccess, setInitialAccess] = useState<string>("");
133137

134138
const bucketName = match.params["bucketName"];
135139

@@ -147,6 +151,14 @@ const AccessRule = ({
147151
setAccessRuleToDelete(accessRule.prefix);
148152
},
149153
},
154+
{
155+
type: "view",
156+
onClick: (accessRule: any) => {
157+
setAccessRuleToEdit(accessRule.prefix);
158+
setInitialAccess(accessRule.access)
159+
setEditAccessRuleOpen(true);
160+
},
161+
},
150162
];
151163

152164
useEffect(() => {
@@ -174,6 +186,11 @@ const AccessRule = ({
174186
setLoadingAccessRules(true);
175187
};
176188

189+
const closeEditAccessRuleModal = () => {
190+
setEditAccessRuleOpen(false);
191+
setLoadingAccessRules(true);
192+
};
193+
177194
return (
178195
<Fragment>
179196
{addAccessRuleOpen && (
@@ -191,6 +208,15 @@ const AccessRule = ({
191208
toDelete={accessRuleToDelete}
192209
/>
193210
)}
211+
{editAccessRuleOpen && (
212+
<EditAccessRuleModal
213+
modalOpen={editAccessRuleOpen}
214+
onClose={closeEditAccessRuleModal}
215+
bucket={bucketName}
216+
toEdit={accessRuleToEdit}
217+
initial={initialAccess}
218+
/>
219+
)}
194220
<Grid item xs={12} className={classes.actionsTray}>
195221
<h1 className={classes.sectionTitle}>Access Rules</h1>
196222
<Button

portal-ui/src/screens/Console/Buckets/BucketDetails/AddAccessRule.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const AddAccessRule = ({
6969

7070
const resetForm = () => {
7171
setPrefix("");
72-
setSelectedAccess("none");
72+
setSelectedAccess("readonly");
7373
};
7474

7575
const createProcess = () => {

portal-ui/src/screens/Console/Buckets/BucketDetails/DeleteAccessRule.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

1717
import React from "react";
18-
import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper";
1918
import {
2019
Button,
2120
Dialog,
2221
DialogActions,
2322
DialogContent,
2423
DialogContentText,
2524
DialogTitle,
26-
Grid,
27-
LinearProgress,
2825
} from "@material-ui/core";
2926
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
3027
import { modalBasic } from "../../Common/FormComponents/common/styleLibrary";
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// This file is part of MinIO Console Server
2+
// Copyright (c) 2021 MinIO, Inc.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
import React, {useState} from "react";
18+
import ModalWrapper from "../../Common/ModalWrapper/ModalWrapper";
19+
import { Button, Grid } from "@material-ui/core";
20+
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
21+
import { modalBasic } from "../../Common/FormComponents/common/styleLibrary";
22+
import { connect } from "react-redux";
23+
import api from "../../../../common/api";
24+
import { ErrorResponseHandler } from "../../../../common/types";
25+
import { setErrorSnackMessage } from "../../../../actions";
26+
import { AppState } from "../../../../store";
27+
import SelectWrapper from "../../Common/FormComponents/SelectWrapper/SelectWrapper";
28+
29+
const mapState = (state: AppState) => ({
30+
session: state.console.session,
31+
});
32+
33+
const connector = connect(mapState, { setErrorSnackMessage });
34+
35+
interface IEditAccessRule {
36+
classes: any;
37+
modalOpen: boolean;
38+
onClose: () => any;
39+
bucket: string;
40+
toEdit: string;
41+
initial: string;
42+
}
43+
44+
const styles = (theme: Theme) =>
45+
createStyles({
46+
buttonContainer: {
47+
textAlign: "right",
48+
},
49+
pathLabel: {
50+
marginTop: 0,
51+
marginBottom: 32,
52+
},
53+
...modalBasic,
54+
});
55+
56+
const EditAccessRule = ({
57+
modalOpen,
58+
onClose,
59+
classes,
60+
bucket,
61+
toEdit,
62+
initial
63+
}: IEditAccessRule) => {
64+
const [selectedAccess, setSelectedAccess] = useState<any>(initial);
65+
66+
const accessOptions = [
67+
{ label: "readonly", value: "readonly" },
68+
{ label: "writeonly", value: "writeonly" },
69+
{ label: "readwrite", value: "readwrite" },
70+
];
71+
72+
const resetForm = () => {
73+
setSelectedAccess(initial);
74+
};
75+
76+
const createProcess = () => {
77+
api
78+
.invoke("PUT", `/api/v1/bucket/${bucket}/access-rules`, {
79+
prefix: toEdit,
80+
access: selectedAccess,
81+
})
82+
.then((res: any) => {
83+
onClose();
84+
})
85+
.catch((err: ErrorResponseHandler) => {
86+
setErrorSnackMessage(err);
87+
onClose();
88+
});
89+
};
90+
91+
return (
92+
<React.Fragment>
93+
<ModalWrapper
94+
modalOpen={modalOpen}
95+
title={`Edit Access Rule for ${toEdit}`}
96+
onClose={onClose}
97+
>
98+
<Grid container>
99+
<Grid item xs={12}>
100+
<SelectWrapper
101+
id="access"
102+
name="Access"
103+
onChange={(e) => {
104+
setSelectedAccess(e.target.value);
105+
}}
106+
label="Access"
107+
value={selectedAccess}
108+
options={accessOptions}
109+
disabled={false}
110+
/>
111+
</Grid>
112+
<Grid item xs={12} className={classes.buttonContainer}>
113+
<button
114+
type="button"
115+
color="primary"
116+
className={classes.clearButton}
117+
onClick={resetForm}
118+
>
119+
Clear
120+
</button>
121+
<Button
122+
type="submit"
123+
variant="contained"
124+
color="primary"
125+
onClick={createProcess}
126+
>
127+
Save
128+
</Button>
129+
</Grid>
130+
</Grid>
131+
</ModalWrapper>
132+
</React.Fragment>
133+
);
134+
};
135+
136+
export default withStyles(styles)(connector(EditAccessRule));

0 commit comments

Comments
 (0)