summaryrefslogtreecommitdiffstats
path: root/web/react/components/admin_console/demote_own_role_modal.jsx
blob: 18747e33ef3857237d80279103724f3dcd52058c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// 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
};