diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/CommunityProfileForm.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/CommunityProfileForm.js index 9b42c4ce8..9aeef6fe2 100644 --- a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/CommunityProfileForm.js +++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/CommunityProfileForm.js @@ -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 ( - + @@ -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; diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/DangerZone.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/DangerZone.js index 5d1255524..9316b944a 100644 --- a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/DangerZone.js +++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/DangerZone.js @@ -15,49 +15,68 @@ import { RenameCommunitySlugButton } from "./RenameCommunitySlugButton"; import PropTypes from "prop-types"; import { DeleteCommunityModal } from "./DeleteCommunityModal"; -const DangerZone = ({ community, onError }) => ( - -
- {i18next.t("Danger zone")} -
- - -
- {i18next.t("Change identifier")} +const DangerZone = ({ community, onError, permissions }) => { + if (permissions.can_delete || permissions.can_rename) { + return ( + +
+ {i18next.t("Danger zone")}
-

- {i18next.t( - "Changing your community's unique identifier can have unintended side effects." + + {permissions.can_rename && ( + <> + +

+ {i18next.t("Change identifier")} +
+

+ {i18next.t( + "Changing your community's unique identifier can have unintended side effects." + )} +

+ + + + + )} -

- - - - - -
- {i18next.t("Delete community")} -
-

{i18next.t("Once deleted, it will be gone forever. Please be certain.")}

-
- - { - const client = new CommunityApi(); - await client.delete(community.id); - }} - /> - - -
-); + {permissions.can_delete && ( + <> + +
+ {i18next.t("Delete community")} +
+

+ {i18next.t( + "Once deleted, it will be gone forever. Please be certain." + )} +

+
+ + { + const client = new CommunityApi(); + await client.delete(community.id); + }} + /> + + + )} + + + ); + } else { + return null; + } +}; DangerZone.propTypes = { community: PropTypes.object.isRequired, onError: PropTypes.func.isRequired, + permissions: PropTypes.object.isRequired, }; export default DangerZone; diff --git a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js index cbd1fb28d..04820474e 100644 --- a/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js +++ b/invenio_communities/assets/semantic-ui/js/invenio_communities/settings/profile/index.js @@ -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( , domContainer ); diff --git a/invenio_communities/templates/semantic-ui/invenio_communities/details/settings/profile.html b/invenio_communities/templates/semantic-ui/invenio_communities/details/settings/profile.html index a0b2277c4..214291b6d 100644 --- a/invenio_communities/templates/semantic-ui/invenio_communities/details/settings/profile.html +++ b/invenio_communities/templates/semantic-ui/invenio_communities/details/settings/profile.html @@ -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 }}' > {%- endblock settings_body %} diff --git a/invenio_communities/views/communities.py b/invenio_communities/views/communities.py index 9f6babc00..64053e974 100644 --- a/invenio_communities/views/communities.py +++ b/invenio_communities/views/communities.py @@ -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"]: