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

Set personal preset by default #68

Merged
merged 3 commits into from
Nov 1, 2022
Merged
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
182 changes: 86 additions & 96 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,73 @@ export const App = () => {
base64file: '',
loading: false,
});
const [presets] = useState({
personal: {
basicAcl: 'eacl-public-read-write',
eACLParams: [{
"operation": "GET",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "HEAD",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "PUT",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "DELETE",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "SEARCH",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "RANGE",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "RANGEHASH",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}],
},
shared: {
preset: 'shared',
basicAcl: 'eacl-public-read-write',
eACLParams: [{
"operation": "PUT",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "DELETE",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}],
},
custom: {
preset: 'custom',
basicAcl: '',
eACLParams: [],
}
});
const [containerForm, setContainerForm] = useState({
containerName: '',
placementPolicy: '',
basicAcl: '',
eACLParams: [],
preset: 'custom',
basicAcl: presets.personal.basicAcl,
eACLParams: presets.personal.eACLParams,
preset: 'personal',
});
const [walletData, setWalletData] = useState(null);

Expand Down Expand Up @@ -103,6 +164,16 @@ export const App = () => {
}
}, [wcSdk.isConnected()]); // eslint-disable-line react-hooks/exhaustive-deps

const onResetContainerForm = () => {
setContainerForm({
containerName: '',
placementPolicy: '',
basicAcl: presets.personal.basicAcl,
eACLParams: presets.personal.eACLParams,
preset: 'personal',
});
}

const onAuth = async (type, operation, params = {}) => {
let body = {};
if (type === 'container') {
Expand Down Expand Up @@ -233,27 +304,15 @@ export const App = () => {
setLoadingForm(false);
onPopup('success', 'New container with EACL has been created');
setLoadContainers(true);
setContainerForm({
containerName: '',
placementPolicy: '',
basicAcl: '',
eACLParams: [],
preset: 'custom',
});
onResetContainerForm();
setAttributes([]);
onModal();
});
} else {
setLoadingForm(false);
onPopup('success', 'New container has been created');
setLoadContainers(true);
setContainerForm({
containerName: '',
placementPolicy: '',
basicAcl: '',
eACLParams: [],
preset: 'custom',
});
onResetContainerForm();
setAttributes([]);
onModal();
}
Expand Down Expand Up @@ -665,13 +724,7 @@ export const App = () => {
setLoadingForm(false);
setAttributes([]);
setError({ active: false, type: [], text: '' });
setContainerForm({
containerName: '',
placementPolicy: '',
basicAcl: '',
eACLParams: [],
preset: 'custom',
});
onResetContainerForm();
}}
/>
<div className="modal_scroll">
Expand All @@ -683,13 +736,7 @@ export const App = () => {
setLoadingForm(false);
setAttributes([]);
setError({ active: false, type: [], text: '' });
setContainerForm({
containerName: '',
placementPolicy: '',
basicAcl: '',
eACLParams: [],
preset: 'custom',
});
onResetContainerForm();
}}
>
<img
Expand Down Expand Up @@ -809,78 +856,21 @@ export const App = () => {
</Form.Field>
<Form.Field>
<Form.Label>Access Control</Form.Label>
{[{
preset: 'personal',
basicAcl: 'eacl-public-read-write',
eACLParams: [{
"operation": "GET",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "HEAD",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "PUT",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "DELETE",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "SEARCH",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "RANGE",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "RANGEHASH",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}],
}, {
preset: 'shared',
basicAcl: 'eacl-public-read-write',
eACLParams: [{
"operation": "PUT",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}, {
"operation": "DELETE",
"action": "DENY",
"filters": [],
"targets": [{ "keys": [], "role": "OTHERS" }],
}],
}, {
preset: 'custom',
basicAcl: '',
eACLParams: [],
}].map((basicPresetExample) => (
{Object.keys(presets).map((basicPresetExample) => (
<Tag
key={basicPresetExample.preset}
key={basicPresetExample}
className={isLoadingForm ? "tag_disabled" : ""}
onClick={() => {
if (containerForm.preset !== basicPresetExample.preset) {
if (containerForm.preset !== basicPresetExample) {
setContainerForm({
...containerForm,
basicAcl: basicPresetExample.basicAcl,
eACLParams: basicPresetExample.eACLParams,
preset: basicPresetExample.preset,
basicAcl: presets[basicPresetExample].basicAcl,
eACLParams: presets[basicPresetExample].eACLParams,
preset: basicPresetExample,
})}
}
}
style={basicPresetExample.preset === containerForm.preset ? {
style={basicPresetExample === containerForm.preset ? {
margin: '5px 5px 0 0',
cursor: 'pointer',
background: '#21b87e',
Expand All @@ -889,7 +879,7 @@ export const App = () => {
margin: '5px 5px 0 0',
cursor: 'pointer',
}}
>{basicPresetExample.preset}</Tag>
>{basicPresetExample}</Tag>
))}
</Form.Field>
<Form.Field>
Expand Down