Skip to content

Commit

Permalink
settings: Hide community rename based on permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcastro2 authored and zzacharo committed Sep 27, 2023
1 parent e34ae2a commit 7f6e3e6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,15 @@ class CommunityProfileForm extends Component {
};

render() {
const { types, customFields, community, hasLogo, defaultLogo, logoMaxSize } =
this.props;
const {
types,
customFields,
community,
hasLogo,
defaultLogo,
logoMaxSize,
permissions,
} = this.props;
const { error } = this.state;
return (
<Formik
Expand Down Expand Up @@ -587,7 +594,11 @@ class CommunityProfileForm extends Component {
</Grid.Row>
<Grid.Row className="danger-zone">
<Grid.Column as="section" width={16}>
<DangerZone community={community} onError={this.setGlobalError} />
<DangerZone
community={community}
onError={this.setGlobalError}
permissions={permissions}
/>
</Grid.Column>
</Grid.Row>
</Grid>
Expand All @@ -605,6 +616,7 @@ CommunityProfileForm.propTypes = {
logoMaxSize: PropTypes.number.isRequired,
customFields: PropTypes.object.isRequired,
types: PropTypes.array.isRequired,
permissions: PropTypes.object.isRequired,
};

export default CommunityProfileForm;
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,68 @@ import { RenameCommunitySlugButton } from "./RenameCommunitySlugButton";
import PropTypes from "prop-types";
import { DeleteCommunityModal } from "./DeleteCommunityModal";

const DangerZone = ({ community, onError }) => (
<Segment className="negative rel-mt-2">
<Header as="h2" className="negative">
{i18next.t("Danger zone")}
</Header>
<Grid>
<Grid.Column mobile={16} tablet={10} computer={12}>
<Header as="h3" size="small">
{i18next.t("Change identifier")}
const DangerZone = ({ community, onError, permissions }) => {
if (permissions.can_delete || permissions.can_rename) {
return (
<Segment className="negative rel-mt-2">
<Header as="h2" className="negative">
{i18next.t("Danger zone")}
</Header>
<p>
{i18next.t(
"Changing your community's unique identifier can have unintended side effects."
<Grid>
{permissions.can_rename && (
<>
<Grid.Column mobile={16} tablet={10} computer={12}>
<Header as="h3" size="small">
{i18next.t("Change identifier")}
</Header>
<p>
{i18next.t(
"Changing your community's unique identifier can have unintended side effects."
)}
</p>
</Grid.Column>
<Grid.Column mobile={16} tablet={6} computer={4} floated="right">
<RenameCommunitySlugButton community={community} onError={onError} />
</Grid.Column>
</>
)}
</p>
</Grid.Column>
<Grid.Column mobile={16} tablet={6} computer={4} floated="right">
<RenameCommunitySlugButton community={community} onError={onError} />
</Grid.Column>
<Grid.Column mobile={16} tablet={10} computer={12} floated="left">
<Header as="h3" size="small">
{i18next.t("Delete community")}
</Header>
<p>{i18next.t("Once deleted, it will be gone forever. Please be certain.")}</p>
</Grid.Column>
<Grid.Column mobile={16} tablet={6} computer={4} floated="right">
<DeleteCommunityModal
community={community}
label={i18next.t("Delete community")}
redirectURL="/communities"
onDelete={async () => {
const client = new CommunityApi();
await client.delete(community.id);
}}
/>
</Grid.Column>
</Grid>
</Segment>
);
{permissions.can_delete && (
<>
<Grid.Column mobile={16} tablet={10} computer={12} floated="left">
<Header as="h3" size="small">
{i18next.t("Delete community")}
</Header>
<p>
{i18next.t(
"Once deleted, it will be gone forever. Please be certain."
)}
</p>
</Grid.Column>
<Grid.Column mobile={16} tablet={6} computer={4} floated="right">
<DeleteCommunityModal
community={community}
label={i18next.t("Delete community")}
redirectURL="/communities"
onDelete={async () => {
const client = new CommunityApi();
await client.delete(community.id);
}}
/>
</Grid.Column>
</>
)}
</Grid>
</Segment>
);
} else {
return null;
}
};

DangerZone.propTypes = {
community: PropTypes.object.isRequired,
onError: PropTypes.func.isRequired,
permissions: PropTypes.object.isRequired,
};

export default DangerZone;
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const hasLogo = JSON.parse(domContainer.dataset.hasLogo);
const types = JSON.parse(domContainer.dataset.types);
const logoMaxSize = JSON.parse(domContainer.dataset.logoMaxSize);
const customFields = JSON.parse(domContainer.dataset.customFields);
const permissions = JSON.parse(domContainer.dataset.permissions);

ReactDOM.render(
<CommunityProfileForm
Expand All @@ -26,6 +27,7 @@ ReactDOM.render(
types={types}
logoMaxSize={logoMaxSize}
customFields={customFields}
permissions={permissions}
/>,
domContainer
);
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
data-types='{{ types | tojson }}'
data-logo-max-size='{{ logo_quota | tojson }}'
data-custom-fields='{{ custom_fields | tojson }}'
data-permissions='{{ permissions | tojson }}'
>
</div>
{%- endblock settings_body %}
2 changes: 2 additions & 0 deletions invenio_communities/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def communities_settings(pid_value, community, community_ui):
"search_requests",
"search_invites",
"manage_access",
"rename",
"delete",
]
)
if not permissions["can_update"]:
Expand Down

0 comments on commit 7f6e3e6

Please sign in to comment.