summaryrefslogtreecommitdiffstats
path: root/webapp/components/admin_console/audits.jsx
blob: 5e0e03607b11b9ec166483de63a2d365330169d9 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import LoadingScreen from '../loading_screen.jsx';
import AuditTable from '../audit_table.jsx';
import ComplianceReports from './compliance_reports.jsx';

import AdminStore from 'stores/admin_store.jsx';

import * as AsyncClient from 'utils/async_client.jsx';

import {FormattedMessage} from 'react-intl';

import React from 'react';

export default class Audits extends React.Component {
    constructor(props) {
        super(props);

        this.onAuditListenerChange = this.onAuditListenerChange.bind(this);
        this.reload = this.reload.bind(this);

        this.state = {
            audits: AdminStore.getAudits()
        };
    }

    componentDidMount() {
        AdminStore.addAuditChangeListener(this.onAuditListenerChange);
        AsyncClient.getServerAudits();
    }

    componentWillUnmount() {
        AdminStore.removeAuditChangeListener(this.onAuditListenerChange);
    }

    onAuditListenerChange() {
        this.setState({
            audits: AdminStore.getAudits()
        });
    }

    reload() {
        AdminStore.saveAudits(null);
        this.setState({
            audits: null
        });

        AsyncClient.getServerAudits();
    }

    render() {
        var content = null;

        if (global.window.mm_license.IsLicensed !== 'true') {
            return <div/>;
        }

        if (this.state.audits === null) {
            content = <LoadingScreen/>;
        } else {
            content = (
                <div style={{margin: '10px'}}>
                    <AuditTable
                        audits={this.state.audits}
                        showUserId={true}
                        showIp={true}
                        showSession={true}
                    />
                </div>
            );
        }

        return (
            <div>
                <ComplianceReports/>

                <div className='panel audit-panel'>
                    <h3>
                        <FormattedMessage
                            id='admin.audits.title'
                            defaultMessage='User Activity Logs'
                        />
                        <button
                            type='submit'
                            className='btn btn-link pull-right'
                            onClick={this.reload}
                        >
                            <i className='fa fa-refresh'/>
                            <FormattedMessage
                                id='admin.audits.reload'
                                defaultMessage='Reload User Activity Logs'
                            />
                        </button>
                    </h3>
                    <div className='audit-panel__table'>
                        {content}
                    </div>
                </div>
            </div>
        );
    }
}