diff options
Diffstat (limited to 'web/react/components')
-rw-r--r-- | web/react/components/admin_console/compliance_reports.jsx | 384 | ||||
-rw-r--r-- | web/react/components/admin_console/compliance_settings.jsx | 271 |
2 files changed, 655 insertions, 0 deletions
diff --git a/web/react/components/admin_console/compliance_reports.jsx b/web/react/components/admin_console/compliance_reports.jsx new file mode 100644 index 000000000..2a94b6f1d --- /dev/null +++ b/web/react/components/admin_console/compliance_reports.jsx @@ -0,0 +1,384 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import LoadingScreen from '../loading_screen.jsx'; +import * as Utils from '../../utils/utils.jsx'; +import AdminStore from '../../stores/admin_store.jsx'; +import UserStore from '../../stores/user_store.jsx'; + +import * as Client from '../../utils/client.jsx'; +import * as AsyncClient from '../../utils/async_client.jsx'; + +import {FormattedMessage, FormattedDate, FormattedTime} from 'mm-intl'; + +export default class ComplianceReports extends React.Component { + constructor(props) { + super(props); + + this.onComplianceReportsListenerChange = this.onComplianceReportsListenerChange.bind(this); + this.reload = this.reload.bind(this); + this.runReport = this.runReport.bind(this); + this.getDateTime = this.getDateTime.bind(this); + + this.state = { + reports: AdminStore.getComplianceReports(), + serverError: null + }; + } + + componentDidMount() { + AdminStore.addComplianceReportsChangeListener(this.onComplianceReportsListenerChange); + + if (global.window.mm_license.IsLicensed !== 'true' || global.window.mm_config.EnableCompliance !== 'true') { + return; + } + + AsyncClient.getComplianceReports(); + } + + componentWillUnmount() { + AdminStore.removeComplianceReportsChangeListener(this.onComplianceReportsListenerChange); + } + + onComplianceReportsListenerChange() { + this.setState({ + reports: AdminStore.getComplianceReports() + }); + } + + reload() { + AdminStore.saveComplianceReports(null); + this.setState({ + reports: null, + serverError: null + }); + + AsyncClient.getComplianceReports(); + } + + runReport(e) { + e.preventDefault(); + $('#run-button').button('loading'); + + var job = {}; + job.desc = ReactDOM.findDOMNode(this.refs.desc).value; + job.emails = ReactDOM.findDOMNode(this.refs.emails).value; + job.keywords = ReactDOM.findDOMNode(this.refs.keywords).value; + job.start_at = Date.parse(ReactDOM.findDOMNode(this.refs.from).value); + job.end_at = Date.parse(ReactDOM.findDOMNode(this.refs.to).value); + + Client.saveComplianceReports( + job, + () => { + ReactDOM.findDOMNode(this.refs.emails).value = ''; + ReactDOM.findDOMNode(this.refs.keywords).value = ''; + ReactDOM.findDOMNode(this.refs.desc).value = ''; + ReactDOM.findDOMNode(this.refs.from).value = ''; + ReactDOM.findDOMNode(this.refs.to).value = ''; + this.reload(); + $('#run-button').button('reset'); + }, + (err) => { + this.setState({serverError: err.message}); + $('#run-button').button('reset'); + } + ); + } + + getDateTime(millis) { + const date = new Date(millis); + return ( + <span style={{whiteSpace: 'nowrap'}}> + <FormattedDate + value={date} + day='2-digit' + month='short' + year='numeric' + /> + {' - '} + <FormattedTime + value={date} + hour='2-digit' + minute='2-digit' + /> + </span> + ); + } + + render() { + var content = null; + + if (global.window.mm_license.IsLicensed !== 'true' || global.window.mm_config.EnableCompliance !== 'true') { + return <div/>; + } + + if (this.state.reports === null) { + content = <LoadingScreen/>; + } else { + var list = []; + + for (var i = 0; i < this.state.reports.length; i++) { + const report = this.state.reports[i]; + + var params = ''; + if (report.type === 'adhoc') { + params = ( + <span> + <FormattedMessage + id='admin.compliance_reports.from' + defaultMessage='From:' + />{' '}{this.getDateTime(report.start_at)} + <br/> + <FormattedMessage + id='admin.compliance_reports.to' + defaultMessage='To:' + />{' '}{this.getDateTime(report.end_at)} + <br/> + <FormattedMessage + id='admin.compliance_reports.emails' + defaultMessage='Emails:' + />{' '}{report.emails} + <br/> + <FormattedMessage + id='admin.compliance_reports.keywords' + defaultMessage='Keywords:' + />{' '}{report.keywords} + </span>); + } + + var download = ''; + if (report.status === 'finished') { + download = ( + <a href={'/api/v1/admin/download_compliance_report/' + report.id}> + <FormattedMessage + id='admin.compliance_table.download' + defaultMessage='Download' + /> + </a> + ); + } + + var status = report.status; + if (report.status === 'finished') { + status = ( + <span style={{color: 'green'}}>{report.status}</span> + ); + } + + if (report.status === 'failed') { + status = ( + <span style={{color: 'red'}}>{report.status}</span> + ); + } + + var user = report.user_id; + var profile = UserStore.getProfile(report.user_id); + if (profile) { + user = profile.email; + } + + list[i] = ( + <tr key={report.id}> + <td style={{whiteSpace: 'nowrap'}}>{download}</td> + <td>{this.getDateTime(report.create_at)}</td> + <td>{status}</td> + <td>{report.count}</td> + <td>{report.type}</td> + <td style={{whiteSpace: 'nowrap'}}>{report.desc}</td> + <td>{user}</td> + <td style={{whiteSpace: 'nowrap'}}>{params}</td> + </tr> + ); + } + + content = ( + <div style={{margin: '10px'}}> + <table className='table'> + <thead> + <tr> + <th></th> + <th> + <FormattedMessage + id='admin.compliance_table.timestamp' + defaultMessage='Timestamp' + /> + </th> + <th> + <FormattedMessage + id='admin.compliance_table.status' + defaultMessage='Status' + /> + </th> + <th> + <FormattedMessage + id='admin.compliance_table.records' + defaultMessage='Records' + /> + </th> + <th> + <FormattedMessage + id='admin.compliance_table.type' + defaultMessage='Type' + /> + </th> + <th> + <FormattedMessage + id='admin.compliance_table.desc' + defaultMessage='Description' + /> + </th> + <th> + <FormattedMessage + id='admin.compliance_table.userId' + defaultMessage='Requested By' + /> + </th> + <th> + <FormattedMessage + id='admin.compliance_table.params' + defaultMessage='Params' + /> + </th> + </tr> + </thead> + <tbody> + {list} + </tbody> + </table> + </div> + ); + } + + let serverError = ''; + if (this.state.serverError) { + serverError = ( + <div + className='form-group has-error' + style={{marginTop: '10px'}} + > + <label className='control-label'>{this.state.serverError}</label> + </div> + ); + } + + return ( + <div className='panel'> + <h3> + <FormattedMessage + id='admin.compliance_reports.title' + defaultMessage='Compliance Reports' + /> + </h3> + + <table> + <tbody> + <tr> + <td colSpan='5' + style={{paddingBottom: '6px'}} + > + <FormattedMessage + id='admin.compliance_reports.desc' + defaultMessage='Job Name:' + /> + <input + style={{width: '425px'}} + type='text' + className='form-control' + id='desc' + ref='desc' + placeholder={Utils.localizeMessage('admin.compliance_reports.desc_placeholder', 'Ex "Audit 445 for HR"')} + /> + </td> + </tr> + <tr> + <td> + <FormattedMessage + id='admin.compliance_reports.from' + defaultMessage='From:' + /> + <input + type='text' + className='form-control' + id='from' + ref='from' + placeholder={Utils.localizeMessage('admin.compliance_reports.from_placeholder', 'Ex "2016-03-11"')} + /> + </td> + <td style={{paddingLeft: '4px'}}> + <FormattedMessage + id='admin.compliance_reports.to' + defaultMessage='To:' + /> + <input + type='text' + className='form-control' + id='to' + ref='to' + placeholder={Utils.localizeMessage('admin.compliance_reports.to_placeholder', 'Ex "2016-03-15"')} + /> + </td> + <td style={{paddingLeft: '4px'}}> + <FormattedMessage + id='admin.compliance_reports.emails' + defaultMessage='Emails:' + /> + <input + style={{width: '325px'}} + type='text' + className='form-control' + id='emails' + ref='emails' + placeholder={Utils.localizeMessage('admin.compliance_reports.emails_placeholder', 'Ex "bill@example.com, bob@example.com"')} + /> + </td> + <td style={{paddingLeft: '4px'}}> + <FormattedMessage + id='admin.compliance_reports.keywords' + defaultMessage='Keywords:' + /> + <input + style={{width: '250px'}} + type='text' + className='form-control' + id='keywords' + ref='keywords' + placeholder={Utils.localizeMessage('admin.compliance_reports.keywords_placeholder', 'Ex "shorting stock"')} + /> + </td> + <td> + <button + id='run-button' + type='submit' + className='btn btn-primary' + onClick={this.runReport} + style={{marginTop: '20px', marginLeft: '20px'}} + > + <FormattedMessage + id='admin.compliance_reports.run' + defaultMessage='Run' + /> + </button> + </td> + </tr> + </tbody> + </table> + {serverError} + <div style={{marginTop: '20px'}}> + <button + type='submit' + className='btn btn-primary' + onClick={this.reload} + > + <FormattedMessage + id='admin.compliance_reports.reload' + defaultMessage='Reload' + /> + </button> + </div> + <div className='compliance__panel'> + {content} + </div> + </div> + ); + } +} diff --git a/web/react/components/admin_console/compliance_settings.jsx b/web/react/components/admin_console/compliance_settings.jsx new file mode 100644 index 000000000..8e6ca6340 --- /dev/null +++ b/web/react/components/admin_console/compliance_settings.jsx @@ -0,0 +1,271 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import * as Client from '../../utils/client.jsx'; +import * as AsyncClient from '../../utils/async_client.jsx'; + +import {injectIntl, intlShape, defineMessages, FormattedMessage, FormattedHTMLMessage} from 'mm-intl'; + +var holders = defineMessages({ + saving: { + id: 'admin.compliance.saving', + defaultMessage: 'Saving Config...' + }, + directoryExample: { + id: 'admin.compliance.directoryExample', + defaultMessage: 'Ex "./data/"' + } +}); + +class ComplianceSettings extends React.Component { + constructor(props) { + super(props); + + this.handleSubmit = this.handleSubmit.bind(this); + this.handleChange = this.handleChange.bind(this); + this.handleEnable = this.handleEnable.bind(this); + this.handleDisable = this.handleDisable.bind(this); + + this.state = { + saveNeeded: false, + serverError: null, + enable: this.props.config.ComplianceSettings.Enable + }; + } + handleChange() { + this.setState({saveNeeded: true}); + } + handleEnable() { + this.setState({saveNeeded: true, enable: true}); + } + handleDisable() { + this.setState({saveNeeded: true, enable: false}); + } + handleSubmit(e) { + e.preventDefault(); + $('#save-button').button('loading'); + + const config = this.props.config; + config.ComplianceSettings.Enable = this.refs.Enable.checked; + config.ComplianceSettings.Directory = ReactDOM.findDOMNode(this.refs.Directory).value; + config.ComplianceSettings.EnableDaily = this.refs.EnableDaily.checked; + + Client.saveConfig( + config, + () => { + AsyncClient.getConfig(); + this.setState({ + serverError: null, + saveNeeded: false + }); + $('#save-button').button('reset'); + }, + (err) => { + this.setState({ + serverError: err.message, + saveNeeded: true + }); + $('#save-button').button('reset'); + } + ); + } + render() { + const {formatMessage} = this.props.intl; + let serverError = ''; + if (this.state.serverError) { + serverError = <div className='form-group has-error'><label className='control-label'>{this.state.serverError}</label></div>; + } + + let saveClass = 'btn'; + if (this.state.saveNeeded) { + saveClass = 'btn btn-primary'; + } + + const licenseEnabled = global.window.mm_license.IsLicensed === 'true' && global.window.mm_license.Compliance === 'true'; + + let bannerContent; + if (!licenseEnabled) { + bannerContent = ( + <div className='banner warning'> + <div className='banner__content'> + <FormattedHTMLMessage + id='admin.compliance.noLicense' + defaultMessage='<h4 class="banner__heading">Note:</h4><p>Compliance is an enterprise feature. Your current license does not support Compliance. Click <a href="http://mattermost.com"target="_blank">here</a> for information and pricing on enterprise licenses.</p>' + /> + </div> + </div> + ); + } + + return ( + <div className='wrapper--fixed'> + {bannerContent} + <h3> + <FormattedMessage + id='admin.compliance.title' + defaultMessage='Compliance Settings' + /> + </h3> + <form + className='form-horizontal' + role='form' + > + + <div className='form-group'> + <label + className='control-label col-sm-4' + htmlFor='Enable' + > + <FormattedMessage + id='admin.compliance.enableTitle' + defaultMessage='Enable Compliance:' + /> + </label> + <div className='col-sm-8'> + <label className='radio-inline'> + <input + type='radio' + name='Enable' + value='true' + ref='Enable' + defaultChecked={this.props.config.ComplianceSettings.Enable} + onChange={this.handleEnable} + disabled={!licenseEnabled} + /> + <FormattedMessage + id='admin.compliance.true' + defaultMessage='true' + /> + </label> + <label className='radio-inline'> + <input + type='radio' + name='Enable' + value='false' + defaultChecked={!this.props.config.ComplianceSettings.Enable} + onChange={this.handleDisable} + /> + <FormattedMessage + id='admin.compliance.false' + defaultMessage='false' + /> + </label> + <p className='help-text'> + <FormattedMessage + id='admin.compliance.enableDesc' + defaultMessage='When true, Mattermost allows compliance reporting' + /> + </p> + </div> + </div> + + <div className='form-group'> + <label + className='control-label col-sm-4' + htmlFor='Directory' + > + <FormattedMessage + id='admin.compliance.directoryTitle' + defaultMessage='Compliance Directory Location:' + /> + </label> + <div className='col-sm-8'> + <input + type='text' + className='form-control' + id='Directory' + ref='Directory' + placeholder={formatMessage(holders.directoryExample)} + defaultValue={this.props.config.ComplianceSettings.Directory} + onChange={this.handleChange} + disabled={!this.state.enable} + /> + <p className='help-text'> + <FormattedMessage + id='admin.compliance.directoryDescription' + defaultMessage='Directory to which compliance reports are written. If blank, will be set to ./data/.' + /> + </p> + </div> + </div> + + <div className='form-group'> + <label + className='control-label col-sm-4' + htmlFor='EnableDaily' + > + <FormattedMessage + id='admin.compliance.enableDailyTitle' + defaultMessage='Enable Daily Report:' + /> + </label> + <div className='col-sm-8'> + <label className='radio-inline'> + <input + type='radio' + name='EnableDaily' + value='true' + ref='EnableDaily' + defaultChecked={this.props.config.ComplianceSettings.EnableDaily} + onChange={this.handleChange} + disabled={!this.state.enable} + /> + <FormattedMessage + id='admin.compliance.true' + defaultMessage='true' + /> + </label> + <label className='radio-inline'> + <input + type='radio' + name='EnableDaily' + value='false' + defaultChecked={!this.props.config.ComplianceSettings.EnableDaily} + disabled={!this.state.enable} + /> + <FormattedMessage + id='admin.compliance.false' + defaultMessage='false' + /> + </label> + <p className='help-text'> + <FormattedMessage + id='admin.compliance.enableDesc' + defaultMessage='When true, Mattermost will generate a daily compliance report.' + /> + </p> + </div> + </div> + + <div className='form-group'> + <div className='col-sm-12'> + {serverError} + <button + disabled={!this.state.saveNeeded} + type='submit' + className={saveClass} + onClick={this.handleSubmit} + id='save-button' + data-loading-text={'<span class=\'glyphicon glyphicon-refresh glyphicon-refresh-animate\'></span> ' + formatMessage(holders.saving)} + > + <FormattedMessage + id='admin.compliance.save' + defaultMessage='Save' + /> + </button> + </div> + </div> + </form> + </div> + ); + } +} +ComplianceSettings.defaultProps = { +}; + +ComplianceSettings.propTypes = { + intl: intlShape.isRequired, + config: React.PropTypes.object +}; + +export default injectIntl(ComplianceSettings); |