mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
Merge pull request #2073 from mattermost/ee-updates
Some general updates to EE
This commit is contained in:
@@ -73,7 +73,8 @@ class AccessHistoryModal extends React.Component {
|
||||
content = (
|
||||
<AuditTable
|
||||
audits={this.state.audits}
|
||||
moreInfo={this.state.moreInfo}
|
||||
showIp={true}
|
||||
showSession={true}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ export default class AdminController extends React.Component {
|
||||
} else if (this.state.selected === 'ldap_settings') {
|
||||
tab = <LdapSettingsTab config={this.state.config} />;
|
||||
} else if (this.state.selected === 'license') {
|
||||
tab = <LicenseSettingsTab />;
|
||||
tab = <LicenseSettingsTab config={this.state.config} />;
|
||||
} else if (this.state.selected === 'team_users') {
|
||||
if (this.state.teams) {
|
||||
tab = <TeamUsersTab team={this.state.teams[this.state.selectedTeam]} />;
|
||||
|
||||
@@ -225,7 +225,7 @@ export default class AdminSidebar extends React.Component {
|
||||
>
|
||||
<FormattedMessage
|
||||
id='admin.sidebar.audits'
|
||||
defaultMessage='Audits'
|
||||
defaultMessage='Compliance and Auditing'
|
||||
/>
|
||||
</a>
|
||||
</li>
|
||||
@@ -454,6 +454,7 @@ export default class AdminSidebar extends React.Component {
|
||||
</ul>
|
||||
<ul className='nav nav__sub-menu padded'>
|
||||
{licenseSettings}
|
||||
{audits}
|
||||
<li>
|
||||
<a
|
||||
href='#'
|
||||
@@ -466,7 +467,6 @@ export default class AdminSidebar extends React.Component {
|
||||
/>
|
||||
</a>
|
||||
</li>
|
||||
{audits}
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -60,8 +60,9 @@ export default class Audits extends React.Component {
|
||||
<div style={{margin: '10px'}}>
|
||||
<AuditTable
|
||||
audits={this.state.audits}
|
||||
oneLine={true}
|
||||
showUserId={true}
|
||||
showIp={true}
|
||||
showSession={true}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -72,7 +73,7 @@ export default class Audits extends React.Component {
|
||||
<h3>
|
||||
<FormattedMessage
|
||||
id='admin.audits.title'
|
||||
defaultMessage='Server Audits'
|
||||
defaultMessage='User Activity'
|
||||
/>
|
||||
</h3>
|
||||
<button
|
||||
|
||||
@@ -109,7 +109,17 @@ class LicenseSettings extends React.Component {
|
||||
);
|
||||
licenseType = (
|
||||
<FormattedHTMLMessage
|
||||
id='admin.license.entrepriseType'
|
||||
id='admin.license.enterpriseType'
|
||||
values={{
|
||||
terms: global.window.mm_config.TermsOfServiceLink,
|
||||
name: global.window.mm_license.Name,
|
||||
company: global.window.mm_license.Company,
|
||||
users: global.window.mm_license.Users,
|
||||
issued: Utils.displayDate(parseInt(global.window.mm_license.IssuedAt, 10)) + ' ' + Utils.displayTime(parseInt(global.window.mm_license.IssuedAt, 10), true),
|
||||
start: Utils.displayDate(parseInt(global.window.mm_license.StartsAt, 10)),
|
||||
expires: Utils.displayDate(parseInt(global.window.mm_license.ExpiresAt, 10)),
|
||||
ldap: global.window.mm_license.LDAP
|
||||
}}
|
||||
defaultMessage='<div><p>This compiled release of Mattermost platform is provided under a <a href="http://mattermost.com" target="_blank">commercial license</a>
|
||||
from Mattermost, Inc. based on your subscription level and is subject to the <a href="{terms}" target="_blank">Terms of Service.</a></p>
|
||||
<p>Your subscription details are as follows:</p>
|
||||
@@ -126,6 +136,7 @@ class LicenseSettings extends React.Component {
|
||||
licenseKey = (
|
||||
<div className='col-sm-8'>
|
||||
<button
|
||||
disabled={this.props.config.LdapSettings.Enable}
|
||||
className='btn btn-danger'
|
||||
onClick={this.handleRemove}
|
||||
id='remove-button'
|
||||
@@ -256,7 +267,8 @@ class LicenseSettings extends React.Component {
|
||||
}
|
||||
|
||||
LicenseSettings.propTypes = {
|
||||
intl: intlShape.isRequired
|
||||
intl: intlShape.isRequired,
|
||||
config: React.PropTypes.object
|
||||
};
|
||||
|
||||
export default injectIntl(LicenseSettings);
|
||||
export default injectIntl(LicenseSettings);
|
||||
|
||||
@@ -183,389 +183,388 @@ const holders = defineMessages({
|
||||
loginFailure: {
|
||||
id: 'audit_table.loginFailure',
|
||||
defaultMessage: ' (Login failure)'
|
||||
},
|
||||
userId: {
|
||||
id: 'audit_table.userId',
|
||||
defaultMessage: 'User ID'
|
||||
}
|
||||
});
|
||||
|
||||
class AuditTable extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.handleMoreInfo = this.handleMoreInfo.bind(this);
|
||||
this.formatAuditInfo = this.formatAuditInfo.bind(this);
|
||||
this.handleRevokedSession = this.handleRevokedSession.bind(this);
|
||||
|
||||
this.state = {moreInfo: []};
|
||||
}
|
||||
handleMoreInfo(index) {
|
||||
var newMoreInfo = this.state.moreInfo;
|
||||
newMoreInfo[index] = true;
|
||||
this.setState({moreInfo: newMoreInfo});
|
||||
}
|
||||
handleRevokedSession(sessionId) {
|
||||
return this.props.intl.formatMessage(holders.sessionRevoked, {sessionId: sessionId});
|
||||
}
|
||||
formatAuditInfo(currentAudit) {
|
||||
const currentActionURL = currentAudit.action.replace(/\/api\/v[1-9]/, '');
|
||||
|
||||
const {formatMessage} = this.props.intl;
|
||||
let currentAuditDesc = '';
|
||||
|
||||
if (currentActionURL.indexOf('/channels') === 0) {
|
||||
const channelInfo = currentAudit.extra_info.split(' ');
|
||||
const channelNameField = channelInfo[0].split('=');
|
||||
|
||||
let channelURL = '';
|
||||
let channelObj;
|
||||
let channelName = '';
|
||||
if (channelNameField.indexOf('name') >= 0) {
|
||||
channelURL = channelNameField[channelNameField.indexOf('name') + 1];
|
||||
channelObj = ChannelStore.getByName(channelURL);
|
||||
if (channelObj) {
|
||||
channelName = channelObj.display_name;
|
||||
} else {
|
||||
channelName = channelURL;
|
||||
}
|
||||
}
|
||||
|
||||
switch (currentActionURL) {
|
||||
case '/channels/create':
|
||||
currentAuditDesc = formatMessage(holders.channelCreated, {channelName: channelName});
|
||||
break;
|
||||
case '/channels/create_direct':
|
||||
currentAuditDesc = formatMessage(holders.establishedDM, {username: Utils.getDirectTeammate(channelObj.id).username});
|
||||
break;
|
||||
case '/channels/update':
|
||||
currentAuditDesc = formatMessage(holders.nameUpdated, {channelName: channelName});
|
||||
break;
|
||||
case '/channels/update_desc': // support the old path
|
||||
case '/channels/update_header':
|
||||
currentAuditDesc = formatMessage(holders.headerUpdated, {channelName: channelName});
|
||||
break;
|
||||
default: {
|
||||
let userIdField = [];
|
||||
let userId = '';
|
||||
let username = '';
|
||||
|
||||
if (channelInfo[1]) {
|
||||
userIdField = channelInfo[1].split('=');
|
||||
|
||||
if (userIdField.indexOf('user_id') >= 0) {
|
||||
userId = userIdField[userIdField.indexOf('user_id') + 1];
|
||||
username = UserStore.getProfile(userId).username;
|
||||
}
|
||||
}
|
||||
|
||||
if (/\/channels\/[A-Za-z0-9]+\/delete/.test(currentActionURL)) {
|
||||
currentAuditDesc = formatMessage(holders.channelDeleted, {url: channelURL});
|
||||
} else if (/\/channels\/[A-Za-z0-9]+\/add/.test(currentActionURL)) {
|
||||
currentAuditDesc = formatMessage(holders.userAdded, {username: username, channelName: channelName});
|
||||
} else if (/\/channels\/[A-Za-z0-9]+\/remove/.test(currentActionURL)) {
|
||||
currentAuditDesc = formatMessage(holders.userRemoved, {username: username, channelName: channelName});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (currentActionURL.indexOf('/oauth') === 0) {
|
||||
const oauthInfo = currentAudit.extra_info.split(' ');
|
||||
|
||||
switch (currentActionURL) {
|
||||
case '/oauth/register': {
|
||||
const clientIdField = oauthInfo[0].split('=');
|
||||
|
||||
if (clientIdField[0] === 'client_id') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedRegisterApp, {id: clientIdField[1]});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case '/oauth/allow':
|
||||
if (oauthInfo[0] === 'attempt') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedAllowOAuthAccess);
|
||||
} else if (oauthInfo[0] === 'success') {
|
||||
currentAuditDesc = formatMessage(holders.successfullOAuthAccess);
|
||||
} else if (oauthInfo[0] === 'fail - redirect_uri did not match registered callback') {
|
||||
currentAuditDesc = formatMessage(holders.failedOAuthAccess);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/oauth/access_token':
|
||||
if (oauthInfo[0] === 'attempt') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedOAuthToken);
|
||||
} else if (oauthInfo[0] === 'success') {
|
||||
currentAuditDesc = formatMessage(holders.successfullOAuthToken);
|
||||
} else {
|
||||
const oauthTokenFailure = oauthInfo[0].split('-');
|
||||
|
||||
if (oauthTokenFailure[0].trim() === 'fail' && oauthTokenFailure[1]) {
|
||||
currentAuditDesc = formatMessage(oauthTokenFailure, {token: oauthTokenFailure[1].trim()});
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (currentActionURL.indexOf('/users') === 0) {
|
||||
const userInfo = currentAudit.extra_info.split(' ');
|
||||
|
||||
switch (currentActionURL) {
|
||||
case '/users/login':
|
||||
if (userInfo[0] === 'attempt') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedLogin);
|
||||
} else if (userInfo[0] === 'success') {
|
||||
currentAuditDesc = formatMessage(holders.successfullLogin);
|
||||
} else if (userInfo[0]) {
|
||||
currentAuditDesc = formatMessage(holders.failedLogin);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/users/revoke_session':
|
||||
currentAuditDesc = this.handleRevokedSession(userInfo[0].split('=')[1]);
|
||||
break;
|
||||
case '/users/newimage':
|
||||
currentAuditDesc = formatMessage(holders.updatePicture);
|
||||
break;
|
||||
case '/users/update':
|
||||
currentAuditDesc = formatMessage(holders.updateGeneral);
|
||||
break;
|
||||
case '/users/newpassword':
|
||||
if (userInfo[0] === 'attempted') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedPassword);
|
||||
} else if (userInfo[0] === 'completed') {
|
||||
currentAuditDesc = formatMessage(holders.successfullPassword);
|
||||
} else if (userInfo[0] === 'failed - tried to update user password who was logged in through oauth') {
|
||||
currentAuditDesc = formatMessage(holders.failedPassword);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/users/update_roles': {
|
||||
const userRoles = userInfo[0].split('=')[1];
|
||||
|
||||
currentAuditDesc = formatMessage(holders.updatedRol);
|
||||
if (userRoles.trim()) {
|
||||
currentAuditDesc += userRoles;
|
||||
} else {
|
||||
currentAuditDesc += formatMessage(holders.member);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case '/users/update_active': {
|
||||
const updateType = userInfo[0].split('=')[0];
|
||||
const updateField = userInfo[0].split('=')[1];
|
||||
|
||||
/* Either describes account activation/deactivation or a revoked session as part of an account deactivation */
|
||||
if (updateType === 'active') {
|
||||
if (updateField === 'true') {
|
||||
currentAuditDesc = formatMessage(holders.accountActive);
|
||||
} else if (updateField === 'false') {
|
||||
currentAuditDesc = formatMessage(holders.accountInactive);
|
||||
}
|
||||
|
||||
const actingUserInfo = userInfo[1].split('=');
|
||||
if (actingUserInfo[0] === 'session_user') {
|
||||
const actingUser = UserStore.getProfile(actingUserInfo[1]);
|
||||
const currentUser = UserStore.getCurrentUser();
|
||||
if (currentUser && actingUser && (Utils.isAdmin(currentUser.roles) || Utils.isSystemAdmin(currentUser.roles))) {
|
||||
currentAuditDesc += formatMessage(holders.by, {username: actingUser.username});
|
||||
} else if (currentUser && actingUser) {
|
||||
currentAuditDesc += formatMessage(holders.byAdmin);
|
||||
}
|
||||
}
|
||||
} else if (updateType === 'session_id') {
|
||||
currentAuditDesc = this.handleRevokedSession(updateField);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case '/users/send_password_reset':
|
||||
currentAuditDesc = formatMessage(holders.sentEmail, {email: userInfo[0].split('=')[1]});
|
||||
break;
|
||||
case '/users/reset_password':
|
||||
if (userInfo[0] === 'attempt') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedReset);
|
||||
} else if (userInfo[0] === 'success') {
|
||||
currentAuditDesc = formatMessage(holders.successfullReset);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/users/update_notify':
|
||||
currentAuditDesc = formatMessage(holders.updateGlobalNotifications);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (currentActionURL.indexOf('/hooks') === 0) {
|
||||
const webhookInfo = currentAudit.extra_info.split(' ');
|
||||
|
||||
switch (currentActionURL) {
|
||||
case '/hooks/incoming/create':
|
||||
if (webhookInfo[0] === 'attempt') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedWebhookCreate);
|
||||
} else if (webhookInfo[0] === 'success') {
|
||||
currentAuditDesc = formatMessage(holders.succcessfullWebhookCreate);
|
||||
} else if (webhookInfo[0] === 'fail - bad channel permissions') {
|
||||
currentAuditDesc = formatMessage(holders.failedWebhookCreate);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/hooks/incoming/delete':
|
||||
if (webhookInfo[0] === 'attempt') {
|
||||
currentAuditDesc = formatMessage(holders.attemptedWebhookDelete);
|
||||
} else if (webhookInfo[0] === 'success') {
|
||||
currentAuditDesc = formatMessage(holders.successfullWebhookDelete);
|
||||
} else if (webhookInfo[0] === 'fail - inappropriate conditions') {
|
||||
currentAuditDesc = formatMessage(holders.failedWebhookDelete);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (currentActionURL) {
|
||||
case '/logout':
|
||||
currentAuditDesc = formatMessage(holders.logout);
|
||||
break;
|
||||
case '/verify_email':
|
||||
currentAuditDesc = formatMessage(holders.verified);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If all else fails... */
|
||||
if (!currentAuditDesc) {
|
||||
/* Currently not called anywhere */
|
||||
if (currentAudit.extra_info.indexOf('revoked_all=') >= 0) {
|
||||
currentAuditDesc = formatMessage(holders.revokedAll);
|
||||
} else {
|
||||
let currentActionDesc = '';
|
||||
if (currentActionURL && currentActionURL.lastIndexOf('/') !== -1) {
|
||||
currentActionDesc = currentActionURL.substring(currentActionURL.lastIndexOf('/') + 1).replace('_', ' ');
|
||||
currentActionDesc = Utils.toTitleCase(currentActionDesc);
|
||||
}
|
||||
|
||||
let currentExtraInfoDesc = '';
|
||||
if (currentAudit.extra_info) {
|
||||
currentExtraInfoDesc = currentAudit.extra_info;
|
||||
|
||||
if (currentExtraInfoDesc.indexOf('=') !== -1) {
|
||||
currentExtraInfoDesc = currentExtraInfoDesc.substring(currentExtraInfoDesc.indexOf('=') + 1);
|
||||
}
|
||||
}
|
||||
currentAuditDesc = currentActionDesc + ' ' + currentExtraInfoDesc;
|
||||
}
|
||||
}
|
||||
|
||||
const currentDate = new Date(currentAudit.create_at);
|
||||
let currentAuditInfo = currentDate.toLocaleDateString(global.window.mm_locale, {month: 'short', day: '2-digit', year: 'numeric'}) + ' - ' + currentDate.toLocaleTimeString(global.window.mm_locale, {hour: '2-digit', minute: '2-digit'});
|
||||
|
||||
if (this.props.showUserId) {
|
||||
currentAuditInfo += ' | ' + formatMessage(holders.userId) + ': ' + currentAudit.user_id;
|
||||
}
|
||||
|
||||
currentAuditInfo += ' | ' + currentAuditDesc;
|
||||
|
||||
return currentAuditInfo;
|
||||
}
|
||||
render() {
|
||||
var accessList = [];
|
||||
|
||||
const {formatMessage} = this.props.intl;
|
||||
for (var i = 0; i < this.props.audits.length; i++) {
|
||||
const currentAudit = this.props.audits[i];
|
||||
const currentAuditInfo = this.formatAuditInfo(currentAudit);
|
||||
const audit = this.props.audits[i];
|
||||
const auditInfo = formatAuditInfo(audit, formatMessage);
|
||||
|
||||
let moreInfo;
|
||||
if (!this.props.oneLine) {
|
||||
moreInfo = (
|
||||
<a
|
||||
href='#'
|
||||
className='theme'
|
||||
onClick={this.handleMoreInfo.bind(this, i)}
|
||||
>
|
||||
<FormattedMessage
|
||||
id='audit_table.moreInfo'
|
||||
defaultMessage='More info'
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
let uContent;
|
||||
if (this.props.showUserId) {
|
||||
uContent = <td>{auditInfo.userId}</td>;
|
||||
}
|
||||
|
||||
if (this.state.moreInfo[i]) {
|
||||
if (!currentAudit.session_id) {
|
||||
currentAudit.session_id = 'N/A';
|
||||
|
||||
if (currentAudit.action.search('/users/login') >= 0) {
|
||||
if (currentAudit.extra_info === 'attempt') {
|
||||
currentAudit.session_id += formatMessage(holders.loginAttempt);
|
||||
} else {
|
||||
currentAudit.session_id += formatMessage(holders.loginFailure);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
moreInfo = (
|
||||
<div>
|
||||
<div>
|
||||
<FormattedMessage
|
||||
id='audit_table.ip'
|
||||
defaultMessage='IP: {ip}'
|
||||
values={{
|
||||
ip: currentAudit.ip_address
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<FormattedMessage
|
||||
id='audit_table.session'
|
||||
defaultMessage='Session ID: {id}'
|
||||
values={{
|
||||
id: currentAudit.session_id
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
let iContent;
|
||||
if (this.props.showIp) {
|
||||
iContent = <td>{auditInfo.ip}</td>;
|
||||
}
|
||||
|
||||
var divider = null;
|
||||
if (i < this.props.audits.length - 1) {
|
||||
divider = (<div className='divider-light'></div>);
|
||||
let sContent;
|
||||
if (this.props.showSession) {
|
||||
sContent = <td>{auditInfo.sessionId}</td>;
|
||||
}
|
||||
|
||||
let descStyle = {};
|
||||
if (auditInfo.desc.toLowerCase().indexOf('fail') !== -1) {
|
||||
descStyle.color = 'red';
|
||||
}
|
||||
|
||||
accessList[i] = (
|
||||
<div
|
||||
key={'accessHistoryEntryKey' + i}
|
||||
className='access-history__table'
|
||||
>
|
||||
<div className='access__report'>
|
||||
<div className='report__time'>{currentAuditInfo}</div>
|
||||
<div className='report__info'>
|
||||
{moreInfo}
|
||||
</div>
|
||||
{divider}
|
||||
</div>
|
||||
</div>
|
||||
<tr key={audit.id}>
|
||||
<td>{auditInfo.timestamp}</td>
|
||||
{uContent}
|
||||
<td style={descStyle}>{auditInfo.desc}</td>
|
||||
{iContent}
|
||||
{sContent}
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
return <form role='form'>{accessList}</form>;
|
||||
let userIdContent;
|
||||
if (this.props.showUserId) {
|
||||
userIdContent = (
|
||||
<th>
|
||||
<FormattedMessage
|
||||
id='audit_table.userId'
|
||||
defaultMessage='User ID'
|
||||
/>
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
let ipContent;
|
||||
if (this.props.showIp) {
|
||||
ipContent = (
|
||||
<th>
|
||||
<FormattedMessage
|
||||
id='audit_table.ip'
|
||||
defaultMessage='IP Address'
|
||||
/>
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
let sessionContent;
|
||||
if (this.props.showSession) {
|
||||
sessionContent = (
|
||||
<th>
|
||||
<FormattedMessage
|
||||
id='audit_table.session'
|
||||
defaultMessage='Session ID'
|
||||
/>
|
||||
</th>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<table className='table'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<FormattedMessage
|
||||
id='audit_table.timestamp'
|
||||
defaultMessage='Timestamp'
|
||||
/>
|
||||
</th>
|
||||
{userIdContent}
|
||||
<th>
|
||||
<FormattedMessage
|
||||
id='audit_table.action'
|
||||
defaultMessage='Action'
|
||||
/>
|
||||
</th>
|
||||
{ipContent}
|
||||
{sessionContent}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{accessList}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
AuditTable.propTypes = {
|
||||
intl: intlShape.isRequired,
|
||||
audits: React.PropTypes.array.isRequired,
|
||||
oneLine: React.PropTypes.bool,
|
||||
showUserId: React.PropTypes.bool
|
||||
showUserId: React.PropTypes.bool,
|
||||
showIp: React.PropTypes.bool,
|
||||
showSession: React.PropTypes.bool
|
||||
};
|
||||
|
||||
export default injectIntl(AuditTable);
|
||||
|
||||
export function formatAuditInfo(audit, formatMessage) {
|
||||
const actionURL = audit.action.replace(/\/api\/v[1-9]/, '');
|
||||
let auditDesc = '';
|
||||
|
||||
if (actionURL.indexOf('/channels') === 0) {
|
||||
const channelInfo = audit.extra_info.split(' ');
|
||||
const channelNameField = channelInfo[0].split('=');
|
||||
|
||||
let channelURL = '';
|
||||
let channelObj;
|
||||
let channelName = '';
|
||||
if (channelNameField.indexOf('name') >= 0) {
|
||||
channelURL = channelNameField[channelNameField.indexOf('name') + 1];
|
||||
channelObj = ChannelStore.getByName(channelURL);
|
||||
if (channelObj) {
|
||||
channelName = channelObj.display_name;
|
||||
} else {
|
||||
channelName = channelURL;
|
||||
}
|
||||
}
|
||||
|
||||
switch (actionURL) {
|
||||
case '/channels/create':
|
||||
auditDesc = formatMessage(holders.channelCreated, {channelName: channelName});
|
||||
break;
|
||||
case '/channels/create_direct':
|
||||
auditDesc = formatMessage(holders.establishedDM, {username: Utils.getDirectTeammate(channelObj.id).username});
|
||||
break;
|
||||
case '/channels/update':
|
||||
auditDesc = formatMessage(holders.nameUpdated, {channelName: channelName});
|
||||
break;
|
||||
case '/channels/update_desc': // support the old path
|
||||
case '/channels/update_header':
|
||||
auditDesc = formatMessage(holders.headerUpdated, {channelName: channelName});
|
||||
break;
|
||||
default: {
|
||||
let userIdField = [];
|
||||
let userId = '';
|
||||
let username = '';
|
||||
|
||||
if (channelInfo[1]) {
|
||||
userIdField = channelInfo[1].split('=');
|
||||
|
||||
if (userIdField.indexOf('user_id') >= 0) {
|
||||
userId = userIdField[userIdField.indexOf('user_id') + 1];
|
||||
username = UserStore.getProfile(userId).username;
|
||||
}
|
||||
}
|
||||
|
||||
if (/\/channels\/[A-Za-z0-9]+\/delete/.test(actionURL)) {
|
||||
auditDesc = formatMessage(holders.channelDeleted, {url: channelURL});
|
||||
} else if (/\/channels\/[A-Za-z0-9]+\/add/.test(actionURL)) {
|
||||
auditDesc = formatMessage(holders.userAdded, {username: username, channelName: channelName});
|
||||
} else if (/\/channels\/[A-Za-z0-9]+\/remove/.test(actionURL)) {
|
||||
auditDesc = formatMessage(holders.userRemoved, {username: username, channelName: channelName});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (actionURL.indexOf('/oauth') === 0) {
|
||||
const oauthInfo = audit.extra_info.split(' ');
|
||||
|
||||
switch (actionURL) {
|
||||
case '/oauth/register': {
|
||||
const clientIdField = oauthInfo[0].split('=');
|
||||
|
||||
if (clientIdField[0] === 'client_id') {
|
||||
auditDesc = formatMessage(holders.attemptedRegisterApp, {id: clientIdField[1]});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case '/oauth/allow':
|
||||
if (oauthInfo[0] === 'attempt') {
|
||||
auditDesc = formatMessage(holders.attemptedAllowOAuthAccess);
|
||||
} else if (oauthInfo[0] === 'success') {
|
||||
auditDesc = formatMessage(holders.successfullOAuthAccess);
|
||||
} else if (oauthInfo[0] === 'fail - redirect_uri did not match registered callback') {
|
||||
auditDesc = formatMessage(holders.failedOAuthAccess);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/oauth/access_token':
|
||||
if (oauthInfo[0] === 'attempt') {
|
||||
auditDesc = formatMessage(holders.attemptedOAuthToken);
|
||||
} else if (oauthInfo[0] === 'success') {
|
||||
auditDesc = formatMessage(holders.successfullOAuthToken);
|
||||
} else {
|
||||
const oauthTokenFailure = oauthInfo[0].split('-');
|
||||
|
||||
if (oauthTokenFailure[0].trim() === 'fail' && oauthTokenFailure[1]) {
|
||||
auditDesc = formatMessage(oauthTokenFailure, {token: oauthTokenFailure[1].trim()});
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (actionURL.indexOf('/users') === 0) {
|
||||
const userInfo = audit.extra_info.split(' ');
|
||||
|
||||
switch (actionURL) {
|
||||
case '/users/login':
|
||||
if (userInfo[0] === 'attempt') {
|
||||
auditDesc = formatMessage(holders.attemptedLogin);
|
||||
} else if (userInfo[0] === 'success') {
|
||||
auditDesc = formatMessage(holders.successfullLogin);
|
||||
} else if (userInfo[0]) {
|
||||
auditDesc = formatMessage(holders.failedLogin);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/users/revoke_session':
|
||||
auditDesc = formatMessage(holders.sessionRevoked, {sessionId: userInfo[0].split('=')[1]});
|
||||
break;
|
||||
case '/users/newimage':
|
||||
auditDesc = formatMessage(holders.updatePicture);
|
||||
break;
|
||||
case '/users/update':
|
||||
auditDesc = formatMessage(holders.updateGeneral);
|
||||
break;
|
||||
case '/users/newpassword':
|
||||
if (userInfo[0] === 'attempted') {
|
||||
auditDesc = formatMessage(holders.attemptedPassword);
|
||||
} else if (userInfo[0] === 'completed') {
|
||||
auditDesc = formatMessage(holders.successfullPassword);
|
||||
} else if (userInfo[0] === 'failed - tried to update user password who was logged in through oauth') {
|
||||
auditDesc = formatMessage(holders.failedPassword);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/users/update_roles': {
|
||||
const userRoles = userInfo[0].split('=')[1];
|
||||
|
||||
auditDesc = formatMessage(holders.updatedRol);
|
||||
if (userRoles.trim()) {
|
||||
auditDesc += userRoles;
|
||||
} else {
|
||||
auditDesc += formatMessage(holders.member);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case '/users/update_active': {
|
||||
const updateType = userInfo[0].split('=')[0];
|
||||
const updateField = userInfo[0].split('=')[1];
|
||||
|
||||
/* Either describes account activation/deactivation or a revoked session as part of an account deactivation */
|
||||
if (updateType === 'active') {
|
||||
if (updateField === 'true') {
|
||||
auditDesc = formatMessage(holders.accountActive);
|
||||
} else if (updateField === 'false') {
|
||||
auditDesc = formatMessage(holders.accountInactive);
|
||||
}
|
||||
|
||||
const actingUserInfo = userInfo[1].split('=');
|
||||
if (actingUserInfo[0] === 'session_user') {
|
||||
const actingUser = UserStore.getProfile(actingUserInfo[1]);
|
||||
const user = UserStore.getCurrentUser();
|
||||
if (user && actingUser && (Utils.isAdmin(user.roles) || Utils.isSystemAdmin(user.roles))) {
|
||||
auditDesc += formatMessage(holders.by, {username: actingUser.username});
|
||||
} else if (user && actingUser) {
|
||||
auditDesc += formatMessage(holders.byAdmin);
|
||||
}
|
||||
}
|
||||
} else if (updateType === 'session_id') {
|
||||
auditDesc = formatMessage(holders.sessionRevoked, {sessionId: updateField});
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case '/users/send_password_reset':
|
||||
auditDesc = formatMessage(holders.sentEmail, {email: userInfo[0].split('=')[1]});
|
||||
break;
|
||||
case '/users/reset_password':
|
||||
if (userInfo[0] === 'attempt') {
|
||||
auditDesc = formatMessage(holders.attemptedReset);
|
||||
} else if (userInfo[0] === 'success') {
|
||||
auditDesc = formatMessage(holders.successfullReset);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/users/update_notify':
|
||||
auditDesc = formatMessage(holders.updateGlobalNotifications);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (actionURL.indexOf('/hooks') === 0) {
|
||||
const webhookInfo = audit.extra_info.split(' ');
|
||||
|
||||
switch (actionURL) {
|
||||
case '/hooks/incoming/create':
|
||||
if (webhookInfo[0] === 'attempt') {
|
||||
auditDesc = formatMessage(holders.attemptedWebhookCreate);
|
||||
} else if (webhookInfo[0] === 'success') {
|
||||
auditDesc = formatMessage(holders.succcessfullWebhookCreate);
|
||||
} else if (webhookInfo[0] === 'fail - bad channel permissions') {
|
||||
auditDesc = formatMessage(holders.failedWebhookCreate);
|
||||
}
|
||||
|
||||
break;
|
||||
case '/hooks/incoming/delete':
|
||||
if (webhookInfo[0] === 'attempt') {
|
||||
auditDesc = formatMessage(holders.attemptedWebhookDelete);
|
||||
} else if (webhookInfo[0] === 'success') {
|
||||
auditDesc = formatMessage(holders.successfullWebhookDelete);
|
||||
} else if (webhookInfo[0] === 'fail - inappropriate conditions') {
|
||||
auditDesc = formatMessage(holders.failedWebhookDelete);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (actionURL) {
|
||||
case '/logout':
|
||||
auditDesc = formatMessage(holders.logout);
|
||||
break;
|
||||
case '/verify_email':
|
||||
auditDesc = formatMessage(holders.verified);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If all else fails... */
|
||||
if (!auditDesc) {
|
||||
/* Currently not called anywhere */
|
||||
if (audit.extra_info.indexOf('revoked_all=') >= 0) {
|
||||
auditDesc = formatMessage(holders.revokedAll);
|
||||
} else {
|
||||
let actionDesc = '';
|
||||
if (actionURL && actionURL.lastIndexOf('/') !== -1) {
|
||||
actionDesc = actionURL.substring(actionURL.lastIndexOf('/') + 1).replace('_', ' ');
|
||||
actionDesc = Utils.toTitleCase(actionDesc);
|
||||
}
|
||||
|
||||
let extraInfoDesc = '';
|
||||
if (audit.extra_info) {
|
||||
extraInfoDesc = audit.extra_info;
|
||||
|
||||
if (extraInfoDesc.indexOf('=') !== -1) {
|
||||
extraInfoDesc = extraInfoDesc.substring(extraInfoDesc.indexOf('=') + 1);
|
||||
}
|
||||
}
|
||||
auditDesc = actionDesc + ' ' + extraInfoDesc;
|
||||
}
|
||||
}
|
||||
|
||||
const date = new Date(audit.create_at);
|
||||
let auditInfo = {};
|
||||
auditInfo.timestamp = date.toLocaleDateString(global.window.mm_locale, {month: 'short', day: '2-digit', year: 'numeric'}) + ' - ' + date.toLocaleTimeString(global.window.mm_locale, {hour: '2-digit', minute: '2-digit'});
|
||||
auditInfo.userId = audit.user_id;
|
||||
auditInfo.desc = auditDesc;
|
||||
auditInfo.ip = audit.ip_address;
|
||||
auditInfo.sessionId = audit.session_id;
|
||||
|
||||
return auditInfo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user