Added more supported audits to audit log

Этот коммит содержится в:
Reed Garmsen
2015-10-12 17:00:27 -07:00
родитель 487c47e803
Коммит 63b0ca8e4b

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

@@ -2,6 +2,7 @@
// See License.txt for license information. // See License.txt for license information.
var UserStore = require('../stores/user_store.jsx'); var UserStore = require('../stores/user_store.jsx');
var ChannelStore = require('../stores/channel_store.jsx');
var AsyncClient = require('../utils/async_client.jsx'); var AsyncClient = require('../utils/async_client.jsx');
var LoadingScreen = require('./loading_screen.jsx'); var LoadingScreen = require('./loading_screen.jsx');
var Utils = require('../utils/utils.jsx'); var Utils = require('../utils/utils.jsx');
@@ -56,16 +57,17 @@ export default class AccessHistoryModal extends React.Component {
formatAuditInfo(currentAudit) { formatAuditInfo(currentAudit) {
const currentActionURL = currentAudit.action.replace(/\/api\/v[1-9]/, ''); const currentActionURL = currentAudit.action.replace(/\/api\/v[1-9]/, '');
let currentAuditDesc = ' '; let currentAuditDesc = '';
/* Handle audit formatting semi-individually for each type and /* Handle audit formatting semi-individually for each type and
fall back to a best guess case if none exists fall back to a best guess case if none exists
Supported audits: Supported audits:
/channels /channels
- Create Channel X - Create Channel
- Update Channel X - Create Direct Channel
- Update Channel Description X - Update Channel
- Update Channel Description
- Delete Channel X - Delete Channel X
- Add User to Channel X - Add User to Channel X
- Remove User from Channel X - Remove User from Channel X
@@ -85,84 +87,147 @@ export default class AccessHistoryModal extends React.Component {
- Logout (/logout) X - Logout (/logout) X
- Verify Email (/verify_email) X - Verify Email (/verify_email) X
*/ */
switch (currentActionURL) { if (currentActionURL.indexOf('/channels') === 0) {
const channelInfo = currentAudit.extra_info.split(' ');
const channelNameField = channelInfo[0].split('=');
/* BREAK UP CHANNEL INTO OWN SWITCH STATEMENT TO REUSE VARIABLES AND BE CLEAN */ let channelURL = '';
case '/channels/create': let channelObj;
const createChannelInfo = currentAudit.extra_info.split('=');
let channelName = ''; let channelName = '';
if (channelNameField.indexOf('name') >= 0) {
if (createChannelInfo[0] === 'name') { channelURL = channelNameField[channelNameField.indexOf('name') + 1];
channelName = createChannelInfo[1]; channelObj = ChannelStore.getByName(channelURL);
if (channelObj) {
channelName = channelObj.display_name;
} else {
channelName = channelURL;
}
} }
currentAuditDesc = 'Created a new channel/group named ' + channelName; switch (currentActionURL) {
case '/channels/create':
currentAuditDesc = 'Created the ' + channelName + ' channel/group';
break;
case '/channels/create_direct':
currentAuditDesc = 'Established a direct message channel with ' + Utils.getDirectTeammate(channelObj.id).username;
break;
case '/channels/update':
currentAuditDesc = 'Updated the ' + channelName + ' channel/group name';
break;
case '/channels/update_desc':
currentAuditDesc = 'Updated the ' + channelName + ' channel/group description';
break;
default:
let userIdField = [];
let userId = '';
let username = '';
break; if (channelInfo[1]) {
case '/channels/update': userIdField = channelInfo[1].split('=');
const updateChannelInfo = currentAudit.extra_info.split('=');
let originalChannelName = '';
if (updateChannelInfo[0] === 'name') { if (userIdField.indexOf('user_id') >= 0) {
originalChannelName = updateChannelInfo[1]; userId = userIdField[userIdField.indexOf('user_id') + 1];
username = UserStore.getProfile(userId).username;
}
}
if (/\/channels\/[A-Za-z0-9]+\/delete/.test(currentActionURL)) {
currentAuditDesc = 'Deleted the channel/group with the URL ' + channelURL;
} else if (/\/channels\/[A-Za-z0-9]+\/add/.test(currentActionURL)) {
currentAuditDesc = 'Added ' + username + ' to the ' + channelName + ' channel/group';
} else if (/\/channels\/[A-Za-z0-9]+\/remove/.test(currentActionURL)) {
currentAuditDesc = 'Removed ' + username + ' from the ' + channelName + ' channel/group';
}
break;
} }
} else if (currentActionURL.indexOf('/oauth') === 0) {
currentAuditDesc = 'Updated the channel/group name for ' + originalChannelName; switch (currentActionURL) {
break; case '/oauth/register':
break;
/* case '/channels/update_desc': case '/oauth/allow':
const updateChannelInfo = currentAudit.extra_info.split('='); break;
let originalChannelName = ''; case '/oauth/access_token':
break;
if (updateChannelInfo[0] === 'name') { default:
originalChannelName = updateChannelInfo[1]; break;
} }
} else if (currentActionURL.indexOf('/users') === 0) {
const userInfo = currentAudit.extra_info.split(' ');
switch (currentActionURL) {
case '/users/login':
if (userInfo[0] === 'attempt') {
currentAuditDesc = 'Login attempted';
} else if (userInfo[0] === 'success') {
currentAuditDesc = 'Successful login attempt';
} else if (userInfo[0]) {
currentAuditDesc = 'FAILED login attempt';
}
currentAuditDesc = 'Updated the channel/group name for ' + originalChannelName; break;
break;*/ case '/users/revoke_session':
case /\/channels\/[A-Za-z0-9]+\/delete/: const revokedSessionId = userInfo[0].split('=')[1];
break;
case /\/channels\/[A-Za-z0-9]+\/add/: currentAuditDesc = 'Revoked the session with id ' + revokedSessionId;
break; break;
case /\/channels\/[A-Za-z0-9]+\/remove/: case '/users/newimage':
break; currentAuditDesc = 'Updated your profile picture';
case '/oauth/register': break;
break; case '/users/update':
case '/oauth/allow': currentAuditDesc = 'Updated the general settings of your account';
break; break;
case '/users/login': case '/users/newpassword':
break; if (userInfo[0] === 'attempted') {
case '/users/revoke_session': currentAuditDesc = 'Password change attempted';
break; } else if (userInfo[0] === 'completed') {
case '/users/newimage': currentAuditDesc = 'Password change success';
break; }
case '/users/update':
break; break;
case '/users/newpassword': case '/users/update_roles':
break; const userRoles = userInfo[0].split('=')[1];
case '/users/update_roles':
break; currentAuditDesc = 'Updated user role(s) to ';
case '/users/update_active': if (userRoles.trim()) {
break; currentAuditDesc += userRoles;
case '/users/send_password_reset': } else {
break; currentAuditDesc += 'member';
case '/users/reset_password': }
break;
case '/users/update_notify': break;
break; case '/users/update_active':
case '/logout': break;
break; case '/users/send_password_reset':
case '/hooks/incoming/create': break;
break; case '/users/reset_password':
case '/hooks/incoming/delete': break;
break; case '/users/update_notify':
case '/verify_email': break;
break; default:
case '/oauth/access_token': break;
break; }
case '': } else if (currentActionURL.indexOf('/hooks') === 0) {
break; switch (currentActionURL) {
default: case '/hooks/incoming/create':
break;
case '/hooks/incoming/delete':
break;
default:
break;
}
} else {
switch (currentActionURL) {
case '/logout':
break;
case '/verify_email':
break;
default:
break;
}
}
/* If all else fails... */
if (!currentAuditDesc) {
if (currentAudit.extra_info.indexOf('revoked_all=') >= 0) { if (currentAudit.extra_info.indexOf('revoked_all=') >= 0) {
// do stuff // do stuff
@@ -183,8 +248,6 @@ export default class AccessHistoryModal extends React.Component {
} }
currentAuditDesc = currentActionDesc + ' ' + currentExtraInfoDesc; currentAuditDesc = currentActionDesc + ' ' + currentExtraInfoDesc;
} }
break;
} }
const currentDate = new Date(currentAudit.create_at); const currentDate = new Date(currentAudit.create_at);
@@ -210,7 +273,11 @@ export default class AccessHistoryModal extends React.Component {
if (this.state.moreInfo[i]) { if (this.state.moreInfo[i]) {
if (!currentAudit.session_id && currentAudit.action.search('/users/login') !== -1) { if (!currentAudit.session_id && currentAudit.action.search('/users/login') !== -1) {
currentAudit.session_id = 'N/A (Login attempt)'; if (currentAudit.extra_info === 'attempt') {
currentAudit.session_id = 'N/A (Login attempt)';
} else {
currentAudit.session_id = 'N/A (Login failure)';
}
} }
moreInfo = ( moreInfo = (