diff --git a/scm-ui/public/locales/de/config.json b/scm-ui/public/locales/de/config.json index 71ab66ff22..d26552c30d 100644 --- a/scm-ui/public/locales/de/config.json +++ b/scm-ui/public/locales/de/config.json @@ -14,7 +14,7 @@ "createButton": "Berechtigungsrolle erstellen", "name": "Name", "type": "Typ", - "verbs": "Verben", + "verbs": "Berechtigungen", "button": { "edit": "Bearbeiten" }, @@ -33,6 +33,16 @@ "name": "Name", "system": "System" }, + "deleteRole" : { + "button": "Löschen", + "subtitle": "Berechtigungsrolle löschen", + "confirmAlert": { + "title": "Berechtigungsrolle löschen", + "message": "Soll die Berechtigungsrolle wirklich gelöscht werden? Alle Nutzer dieser Rolle verlieren Ihre Berechtigungen.", + "submit": "Ja", + "cancel": "Nein" + } + }, "config-form": { "submit": "Speichern", "submit-success-notification": "Einstellungen wurden erfolgreich geändert!", diff --git a/scm-ui/public/locales/en/config.json b/scm-ui/public/locales/en/config.json index 66ddea3ee2..a57a962ced 100644 --- a/scm-ui/public/locales/en/config.json +++ b/scm-ui/public/locales/en/config.json @@ -23,7 +23,7 @@ }, "name": "Name", "type": "Type", - "verbs": "Verbs", + "verbs": "Permissions", "system": "System", "form": { "name": "Name", @@ -31,6 +31,16 @@ "submit": "Save" } }, + "deleteRole" : { + "button": "Delete", + "subtitle": "Delete Permission Role", + "confirmAlert": { + "title": "Delete Permission Role", + "message": "Do you really want to delete this permission role? All users who own this role will lose their permissions.", + "submit": "Yes", + "cancel": "No" + } + }, "config-form": { "submit": "Submit", "submit-success-notification": "Configuration changed successfully!", diff --git a/scm-ui/src/config/roles/containers/DeleteRepositoryRole.js b/scm-ui/src/config/roles/containers/DeleteRepositoryRole.js new file mode 100644 index 0000000000..a00cc21840 --- /dev/null +++ b/scm-ui/src/config/roles/containers/DeleteRepositoryRole.js @@ -0,0 +1,113 @@ +// @flow +import React from "react"; +import { translate } from "react-i18next"; +import type { RepositoryRole } from "@scm-manager/ui-types"; +import { + Subtitle, + DeleteButton, + confirmAlert, + ErrorNotification +} from "@scm-manager/ui-components"; +import { connect } from "react-redux"; +import { withRouter } from "react-router-dom"; +import type { History } from "history"; +import { + deleteRole, + getDeleteRoleFailure, + isDeleteRolePending +} from "../modules/roles"; + +type Props = { + loading: boolean, + error: Error, + role: RepositoryRole, + confirmDialog?: boolean, + deleteRole: (role: RepositoryRole, callback?: () => void) => void, + + // context props + history: History, + t: string => string +}; + +class DeleteRepositoryRole extends React.Component { + static defaultProps = { + confirmDialog: true + }; + + roleDeleted = () => { + this.props.history.push("/config/roles/"); + }; + + deleteRole = () => { + this.props.deleteRole(this.props.role, this.roleDeleted); + }; + + confirmDelete = () => { + const { t } = this.props; + confirmAlert({ + title: t("deleteRole.confirmAlert.title"), + message: t("deleteRole.confirmAlert.message"), + buttons: [ + { + label: t("deleteRole.confirmAlert.submit"), + onClick: () => this.deleteRole() + }, + { + label: t("deleteRole.confirmAlert.cancel"), + onClick: () => null + } + ] + }); + }; + + isDeletable = () => { + return this.props.role._links.delete; + }; + + render() { + const { loading, error, confirmDialog, t } = this.props; + const action = confirmDialog ? this.confirmDelete : this.deleteRole; + + if (!this.isDeletable()) { + return null; + } + + return ( + <> + +
+
+ + +
+
+ + ); + } +} + +const mapStateToProps = (state, ownProps) => { + const loading = isDeleteRolePending(state, ownProps.role.name); + const error = getDeleteRoleFailure(state, ownProps.role.name); + return { + loading, + error + }; +}; + +const mapDispatchToProps = dispatch => { + return { + deleteRole: (role: RepositoryRole, callback?: () => void) => { + dispatch(deleteRole(role, callback)); + } + }; +}; + +export default connect( + mapStateToProps, + mapDispatchToProps +)(withRouter(translate("config")(DeleteRepositoryRole))); diff --git a/scm-ui/src/config/roles/containers/EditRepositoryRole.js b/scm-ui/src/config/roles/containers/EditRepositoryRole.js index 6dc783bec3..15e3bee6ae 100644 --- a/scm-ui/src/config/roles/containers/EditRepositoryRole.js +++ b/scm-ui/src/config/roles/containers/EditRepositoryRole.js @@ -11,6 +11,7 @@ import { import { ErrorNotification, Subtitle } from "@scm-manager/ui-components"; import type { RepositoryRole } from "@scm-manager/ui-types"; import type { History } from "history"; +import DeleteRepositoryRole from "./DeleteRepositoryRole"; type Props = { disabled: boolean, @@ -49,6 +50,8 @@ class EditRepositoryRole extends React.Component { role={this.props.role} submitForm={role => this.updateRepositoryRole(role)} /> +
+ ); }