Merge pull request #1966 from ttyniwa/feature/warning_when_demote_own_role_from_system_admin
PLT-588 Add a warning when a user demotes themselves from System Admi…
Этот коммит содержится в:
@@ -3,8 +3,26 @@
|
|||||||
|
|
||||||
import * as Client from '../../utils/client.jsx';
|
import * as Client from '../../utils/client.jsx';
|
||||||
import * as Utils from '../../utils/utils.jsx';
|
import * as Utils from '../../utils/utils.jsx';
|
||||||
|
import UserStore from '../../stores/user_store.jsx';
|
||||||
|
import ConfirmModal from '../confirm_modal.jsx';
|
||||||
|
import TeamStore from '../../stores/team_store.jsx';
|
||||||
|
|
||||||
import {FormattedMessage} from 'mm-intl';
|
import {injectIntl, intlShape, defineMessages, FormattedMessage} from 'mm-intl';
|
||||||
|
|
||||||
|
var messages = defineMessages({
|
||||||
|
confirmDemoteRoleTitle: {
|
||||||
|
id: 'admin.user_item.confirmDemoteRoleTitle',
|
||||||
|
defaultMessage: 'Confirm demotion from System Admin role'
|
||||||
|
},
|
||||||
|
confirmDemotion: {
|
||||||
|
id: 'admin.user_item.confirmDemotion',
|
||||||
|
defaultMessage: 'Confirm Demotion'
|
||||||
|
},
|
||||||
|
confirmDemoteDescription: {
|
||||||
|
id: 'admin.user_item.confirmDemoteDescription',
|
||||||
|
defaultMessage: 'If you demote yourself from the System Admin role and there is not another user with System Admin privileges, you\'ll need to re-assign a System Admin by accessing the Mattermost server through a terminal and running the following command.'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default class UserItem extends React.Component {
|
export default class UserItem extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -16,25 +34,38 @@ export default class UserItem extends React.Component {
|
|||||||
this.handleMakeAdmin = this.handleMakeAdmin.bind(this);
|
this.handleMakeAdmin = this.handleMakeAdmin.bind(this);
|
||||||
this.handleMakeSystemAdmin = this.handleMakeSystemAdmin.bind(this);
|
this.handleMakeSystemAdmin = this.handleMakeSystemAdmin.bind(this);
|
||||||
this.handleResetPassword = this.handleResetPassword.bind(this);
|
this.handleResetPassword = this.handleResetPassword.bind(this);
|
||||||
|
this.handleDemote = this.handleDemote.bind(this);
|
||||||
|
this.handleDemoteSubmit = this.handleDemoteSubmit.bind(this);
|
||||||
|
this.handleDemoteCancel = this.handleDemoteCancel.bind(this);
|
||||||
|
|
||||||
this.state = {};
|
this.state = {
|
||||||
|
serverError: null,
|
||||||
|
showDemoteModal: false,
|
||||||
|
user: null,
|
||||||
|
role: null
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMakeMember(e) {
|
handleMakeMember(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const data = {
|
const me = UserStore.getCurrentUser();
|
||||||
user_id: this.props.user.id,
|
if (this.props.user.id === me.id) {
|
||||||
new_roles: ''
|
this.handleDemote(this.props.user, '');
|
||||||
};
|
} else {
|
||||||
|
const data = {
|
||||||
|
user_id: this.props.user.id,
|
||||||
|
new_roles: ''
|
||||||
|
};
|
||||||
|
|
||||||
Client.updateRoles(data,
|
Client.updateRoles(data,
|
||||||
() => {
|
() => {
|
||||||
this.props.refreshProfiles();
|
this.props.refreshProfiles();
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
this.setState({serverError: err.message});
|
this.setState({serverError: err.message});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMakeActive(e) {
|
handleMakeActive(e) {
|
||||||
@@ -63,19 +94,24 @@ export default class UserItem extends React.Component {
|
|||||||
|
|
||||||
handleMakeAdmin(e) {
|
handleMakeAdmin(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const data = {
|
const me = UserStore.getCurrentUser();
|
||||||
user_id: this.props.user.id,
|
if (this.props.user.id === me.id) {
|
||||||
new_roles: 'admin'
|
this.handleDemote(this.props.user, 'admin');
|
||||||
};
|
} else {
|
||||||
|
const data = {
|
||||||
|
user_id: this.props.user.id,
|
||||||
|
new_roles: 'admin'
|
||||||
|
};
|
||||||
|
|
||||||
Client.updateRoles(data,
|
Client.updateRoles(data,
|
||||||
() => {
|
() => {
|
||||||
this.props.refreshProfiles();
|
this.props.refreshProfiles();
|
||||||
},
|
},
|
||||||
(err) => {
|
(err) => {
|
||||||
this.setState({serverError: err.message});
|
this.setState({serverError: err.message});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMakeSystemAdmin(e) {
|
handleMakeSystemAdmin(e) {
|
||||||
@@ -100,6 +136,54 @@ export default class UserItem extends React.Component {
|
|||||||
this.props.doPasswordReset(this.props.user);
|
this.props.doPasswordReset(this.props.user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleDemote(user, role) {
|
||||||
|
this.setState({
|
||||||
|
serverError: this.state.serverError,
|
||||||
|
showDemoteModal: true,
|
||||||
|
user,
|
||||||
|
role
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDemoteCancel() {
|
||||||
|
this.setState({
|
||||||
|
serverError: null,
|
||||||
|
showDemoteModal: false,
|
||||||
|
user: null,
|
||||||
|
role: null
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleDemoteSubmit() {
|
||||||
|
const data = {
|
||||||
|
user_id: this.props.user.id,
|
||||||
|
new_roles: this.state.role
|
||||||
|
};
|
||||||
|
|
||||||
|
Client.updateRoles(data,
|
||||||
|
() => {
|
||||||
|
this.setState({
|
||||||
|
serverError: null,
|
||||||
|
showDemoteModal: false,
|
||||||
|
user: null,
|
||||||
|
role: null
|
||||||
|
});
|
||||||
|
|
||||||
|
const teamUrl = TeamStore.getCurrentTeamUrl();
|
||||||
|
if (teamUrl) {
|
||||||
|
window.location.href = teamUrl;
|
||||||
|
} else {
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
this.setState({
|
||||||
|
serverError: err.message
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let serverError = null;
|
let serverError = null;
|
||||||
if (this.state.serverError) {
|
if (this.state.serverError) {
|
||||||
@@ -247,6 +331,20 @@ export default class UserItem extends React.Component {
|
|||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const me = UserStore.getCurrentUser();
|
||||||
|
let makeDemoteModal = null;
|
||||||
|
if (this.props.user.id === me.id) {
|
||||||
|
makeDemoteModal = (
|
||||||
|
<ConfirmModal
|
||||||
|
show={this.state.showDemoteModal}
|
||||||
|
title={this.props.intl.formatMessage(messages.confirmDemoteRoleTitle)}
|
||||||
|
message={[this.props.intl.formatMessage(messages.confirmDemoteDescription), React.createElement('br'), React.createElement('br'), './platform -assign_role -team_name="yourteam" -email="name@yourcompany.com" -role="system_admin"', serverError]}
|
||||||
|
confirm_button={this.props.intl.formatMessage(messages.confirmDemotion)}
|
||||||
|
onConfirm={this.handleDemoteSubmit}
|
||||||
|
onCancel={this.handleDemoteCancel}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
@@ -293,6 +391,7 @@ export default class UserItem extends React.Component {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
{makeDemoteModal}
|
||||||
{serverError}
|
{serverError}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -301,7 +400,10 @@ export default class UserItem extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
UserItem.propTypes = {
|
UserItem.propTypes = {
|
||||||
|
intl: intlShape.isRequired,
|
||||||
user: React.PropTypes.object.isRequired,
|
user: React.PropTypes.object.isRequired,
|
||||||
refreshProfiles: React.PropTypes.func.isRequired,
|
refreshProfiles: React.PropTypes.func.isRequired,
|
||||||
doPasswordReset: React.PropTypes.func.isRequired
|
doPasswordReset: React.PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default injectIntl(UserItem);
|
||||||
|
|||||||
@@ -396,6 +396,9 @@
|
|||||||
"admin.user_item.makeActive": "Make Active",
|
"admin.user_item.makeActive": "Make Active",
|
||||||
"admin.user_item.makeInactive": "Make Inactive",
|
"admin.user_item.makeInactive": "Make Inactive",
|
||||||
"admin.user_item.resetPwd": "Reset Password",
|
"admin.user_item.resetPwd": "Reset Password",
|
||||||
|
"admin.user_item.confirmDemoteRoleTitle": "Confirm demotion from System Admin role",
|
||||||
|
"admin.user_item.confirmDemotion": "Confirm Demotion",
|
||||||
|
"admin.user_item.confirmDemoteDescription": "If you demote yourself from the System Admin role and there is not another user with System Admin privileges, you'll need to re-assign a System Admin by accessing the Mattermost server through a terminal and running the following command.",
|
||||||
"authorize.title": "An application would like to connect to your {teamName} account",
|
"authorize.title": "An application would like to connect to your {teamName} account",
|
||||||
"authorize.app": "The app <strong>{appName}</strong> would like the ability to access and modify your basic information.",
|
"authorize.app": "The app <strong>{appName}</strong> would like the ability to access and modify your basic information.",
|
||||||
"authorize.access": "Allow <strong>{appName}</strong> access?",
|
"authorize.access": "Allow <strong>{appName}</strong> access?",
|
||||||
|
|||||||
@@ -396,6 +396,9 @@
|
|||||||
"admin.user_item.resetPwd": "Reiniciar Contraseña",
|
"admin.user_item.resetPwd": "Reiniciar Contraseña",
|
||||||
"admin.user_item.sysAdmin": "Admin de Sistema",
|
"admin.user_item.sysAdmin": "Admin de Sistema",
|
||||||
"admin.user_item.teamAdmin": "Admin de Equipo",
|
"admin.user_item.teamAdmin": "Admin de Equipo",
|
||||||
|
"admin.user_item.confirmDemoteRoleTitle": "Confirm demotion from System Admin role",
|
||||||
|
"admin.user_item.confirmDemotion": "Confirm Demotion",
|
||||||
|
"admin.user_item.confirmDemoteDescription": "If you demote yourself from the System Admin role and there is not another user with System Admin privileges, you'll need to re-assign a System Admin by accessing the Mattermost server through a terminal and running the following command.",
|
||||||
"authorize.access": "¿Permitir acceso a {appName}?",
|
"authorize.access": "¿Permitir acceso a {appName}?",
|
||||||
"authorize.allow": "Permitir",
|
"authorize.allow": "Permitir",
|
||||||
"authorize.app": "La app {appName} quiere tener la abilidad de accesar y modificar tu información básica.",
|
"authorize.app": "La app {appName} quiere tener la abilidad de accesar y modificar tu información básica.",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user