This commit is contained in:
Florian Scholdei
2019-05-17 17:09:17 +02:00
4 changed files with 138 additions and 2 deletions

View File

@@ -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!",

View File

@@ -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!",

View File

@@ -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<Props> {
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 (
<>
<Subtitle subtitle={t("deleteRole.subtitle")} />
<div className="columns">
<div className="column">
<ErrorNotification error={error} />
<DeleteButton
label={t("deleteRole.button")}
action={action}
loading={loading}
/>
</div>
</div>
</>
);
}
}
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)));

View File

@@ -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<Props> {
role={this.props.role}
submitForm={role => this.updateRepositoryRole(role)}
/>
<hr/>
<DeleteRepositoryRole role={this.props.role}/>
</>
);
}