Этот коммит содержится в:
Tatsuya Niwa
2016-01-26 23:05:26 +09:00
родитель 27f7b9d121
Коммит d8c4705bba
2 изменённых файлов: 36 добавлений и 109 удалений

Просмотреть файл

@@ -1,88 +0,0 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import * as Client from '../../utils/client.jsx';
const Modal = ReactBootstrap.Modal;
export default class DemoteOwnRoleModal extends React.Component {
constructor(props) {
super(props);
this.doDemote = this.doDemote.bind(this);
this.doCancel = this.doCancel.bind(this);
this.state = {
serverError: null
};
}
doDemote() {
const data = {
user_id: this.props.user.id,
new_roles: this.props.role
};
Client.updateRoles(data,
() => {
this.setState({serverError: null});
this.props.onModalSubmit();
},
(err) => {
this.setState({serverError: err.message});
}
);
}
doCancel() {
this.setState({serverError: null});
this.props.onModalDismissed();
}
render() {
let serverError = null;
if (this.state.serverError) {
serverError = <div className='has-error'><label className='has-error control-label'>{this.state.serverError}</label></div>;
}
return (
<Modal
show={this.props.show}
onHide={this.doCancel}
>
<Modal.Header closeButton={true}>
<h4 className='modal-title'>{'Confirm demotion from System Admin role'}</h4>
</Modal.Header>
<Modal.Body>
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.<br/><br/>./platform -assign_role -team_name="yourteam" -email="name@yourcompany.com" -role="system_admin"
{serverError}
</Modal.Body>
<Modal.Footer>
<button
type='button'
className='btn btn-default'
onClick={this.doCancel}
>
{'Cancel'}
</button>
<button
type='button'
className='btn btn-danger'
data-dismiss='modal'
onClick={this.doDemote}
>
{'Confirm Demotion'}
</button>
</Modal.Footer>
</Modal>
);
}
}
DemoteOwnRoleModal.propTypes = {
user: React.PropTypes.object,
role: React.PropTypes.string,
show: React.PropTypes.bool.isRequired,
onModalSubmit: React.PropTypes.func,
onModalDismissed: React.PropTypes.func
};

Просмотреть файл

@@ -4,7 +4,7 @@
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 UserStore from '../../stores/user_store.jsx';
import DemoteOwnRoleModal from './demote_own_role_modal.jsx'; import ConfirmModal from '../confirm_modal.jsx';
import {FormattedMessage} from 'mm-intl'; import {FormattedMessage} from 'mm-intl';
@@ -18,9 +18,9 @@ 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.doDemote = this.doDemote.bind(this); this.handleDemote = this.handleDemote.bind(this);
this.doDemoteSubmit = this.doDemoteSubmit.bind(this); this.handleDemoteSubmit = this.handleDemoteSubmit.bind(this);
this.doDemoteDismiss = this.doDemoteDismiss.bind(this); this.handleDemoteCancel = this.handleDemoteCancel.bind(this);
this.state = { this.state = {
serverError: null, serverError: null,
@@ -34,7 +34,7 @@ export default class UserItem extends React.Component {
e.preventDefault(); e.preventDefault();
var me = UserStore.getCurrentUser(); var me = UserStore.getCurrentUser();
if (this.props.user.id === me.id) { if (this.props.user.id === me.id) {
this.doDemote(this.props.user, ''); this.handleDemote(this.props.user, '');
} else { } else {
const data = { const data = {
user_id: this.props.user.id, user_id: this.props.user.id,
@@ -80,7 +80,7 @@ export default class UserItem extends React.Component {
e.preventDefault(); e.preventDefault();
var me = UserStore.getCurrentUser(); var me = UserStore.getCurrentUser();
if (this.props.user.id === me.id) { if (this.props.user.id === me.id) {
this.doDemote(this.props.user, 'admin'); this.handleDemote(this.props.user, 'admin');
} else { } else {
const data = { const data = {
user_id: this.props.user.id, user_id: this.props.user.id,
@@ -120,7 +120,7 @@ export default class UserItem extends React.Component {
this.props.doPasswordReset(this.props.user); this.props.doPasswordReset(this.props.user);
} }
doDemote(user, role) { handleDemote(user, role) {
this.setState({ this.setState({
serverError: this.state.serverError, serverError: this.state.serverError,
showDemoteModal: true, showDemoteModal: true,
@@ -129,22 +129,36 @@ export default class UserItem extends React.Component {
}); });
} }
doDemoteDismiss() { handleDemoteCancel() {
this.setState({ this.setState({
serverError: this.state.serverError, serverError: null,
showDemoteModal: false, showDemoteModal: false,
user: null, user: null,
role: null role: null
}); });
} }
doDemoteSubmit() { handleDemoteSubmit() {
const data = {
user_id: this.props.user.id,
new_roles: this.props.role
};
Client.updateRoles(data,
() => {
this.setState({ this.setState({
serverError: this.state.serverError, serverError: null,
showDemoteModal: false, showDemoteModal: false,
user: null, user: null,
role: null role: null
}); });
},
(err) => {
this.setState({
serverError: err.message
});
}
);
} }
render() { render() {
@@ -298,12 +312,13 @@ export default class UserItem extends React.Component {
let makeDemoteModal = null; let makeDemoteModal = null;
if (this.props.user.id === me.id) { if (this.props.user.id === me.id) {
makeDemoteModal = ( makeDemoteModal = (
<DemoteOwnRoleModal <ConfirmModal
user={this.state.user}
role={this.state.role}
show={this.state.showDemoteModal} show={this.state.showDemoteModal}
onModalSubmit={this.doDemoteSubmit} title='Confirm demotion from System Admin role'
onModalDismissed={this.doDemoteDismiss} message={[`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.`,<br/>,<br/>,`./platform -assign_role -team_name="yourteam" -email="name@yourcompany.com" -role="system_admin"`,serverError]}
confirm_button='Confirm Demotion'
onConfirm={this.handleDemoteSubmit}
onCancel={this.handleDemoteCancel}
/> />
); );
} }