From 487c47e8039b2004010403aec8b37c1bebbc9513 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Fri, 9 Oct 2015 16:35:59 -0700 Subject: Finished structure for formatting audits and began writing individual formatting for each audit --- web/react/components/access_history_modal.jsx | 193 ++++++++++++++++++-------- 1 file changed, 132 insertions(+), 61 deletions(-) (limited to 'web/react/components') diff --git a/web/react/components/access_history_modal.jsx b/web/react/components/access_history_modal.jsx index 9aeb7f682..41a865df4 100644 --- a/web/react/components/access_history_modal.jsx +++ b/web/react/components/access_history_modal.jsx @@ -14,6 +14,7 @@ export default class AccessHistoryModal extends React.Component { this.handleMoreInfo = this.handleMoreInfo.bind(this); this.onHide = this.onHide.bind(this); this.onShow = this.onShow.bind(this); + this.formatAuditInfo = this.formatAuditInfo.bind(this); const state = this.getStateFromStoresForAudits(); state.moreInfo = []; @@ -52,74 +53,127 @@ export default class AccessHistoryModal extends React.Component { newMoreInfo[index] = true; this.setState({moreInfo: newMoreInfo}); } - render() { - var accessList = []; + formatAuditInfo(currentAudit) { + const currentActionURL = currentAudit.action.replace(/\/api\/v[1-9]/, ''); - for (var i = 0; i < this.state.audits.length; i++) { - var currentAudit = this.state.audits[i]; - var currentDate = new Date(currentAudit.create_at); + let currentAuditDesc = ' '; + + /* Handle audit formatting semi-individually for each type and + fall back to a best guess case if none exists + + Supported audits: + /channels + - Create Channel X + - Update Channel X + - Update Channel Description X + - Delete Channel X + - Add User to Channel X + - Remove User from Channel X + + /oauth + - Register X + - Allow Attempt/Success/Failure X + + /team + - Revoke All Sessions X (NO CORRESPONDING ADDRESS/FUNCTION) + + - Revoke Session X + - Update (users - ?) X + - Update Notify (?) X + - Login Attempt X + - Login (success/failure) X + - Logout (/logout) X + - Verify Email (/verify_email) X + */ + switch (currentActionURL) { + + /* BREAK UP CHANNEL INTO OWN SWITCH STATEMENT TO REUSE VARIABLES AND BE CLEAN */ + case '/channels/create': + const createChannelInfo = currentAudit.extra_info.split('='); + let channelName = ''; + + if (createChannelInfo[0] === 'name') { + channelName = createChannelInfo[1]; + } + + currentAuditDesc = 'Created a new channel/group named ' + channelName; + + break; + case '/channels/update': + const updateChannelInfo = currentAudit.extra_info.split('='); + let originalChannelName = ''; + + if (updateChannelInfo[0] === 'name') { + originalChannelName = updateChannelInfo[1]; + } + + currentAuditDesc = 'Updated the channel/group name for ' + originalChannelName; + break; - if (!currentAudit.session_id && currentAudit.action.search('/users/login') !== -1) { - currentAudit.session_id = 'N/A (Login attempt)'; + /* case '/channels/update_desc': + const updateChannelInfo = currentAudit.extra_info.split('='); + let originalChannelName = ''; + + if (updateChannelInfo[0] === 'name') { + originalChannelName = updateChannelInfo[1]; } - const currentActionURL = currentAudit.action.replace(/\/api\/v[1-9]/, ''); - - let currentAuditDesc = ''; - - /* Handle specific audit type formatting semi-individually and - fall back to a best guess case if none exists - - Supported audits: - /channels - - Create Channel X - - Update Channel X - - Update Channel Description X - - Delete Channel X - - Add User to Channel X - - Remove User from Channel X - - /oauth - - Register X - - Allow Attempt/Success/Failure X - - /team - - Revoke All Sessions X (NO CORRESPONDING ADDRESS) - - - Update (users - ?) X - - Update Notify (?) X - - Login Attempt X - - Login (success/failure) X - - Logout (/logout) X - */ - switch (currentActionURL) { - case '/channels/create': - break; - case '/channels/update': - break; - case '/channels/update_desc': - break; - case /\/channels\/[A-Za-z0-9]+\/delete/: - break; - case /\/channels\/[A-Za-z0-9]+\/add/: - break; - case /\/channels\/[A-Za-z0-9]+\/remove/: - break; - case '/oauth/register': - break; - case '/oauth/allow': - break; - case '/team/': - break; - default: - let currentActionDesc = ''; + currentAuditDesc = 'Updated the channel/group name for ' + originalChannelName; + break;*/ + case /\/channels\/[A-Za-z0-9]+\/delete/: + break; + case /\/channels\/[A-Za-z0-9]+\/add/: + break; + case /\/channels\/[A-Za-z0-9]+\/remove/: + break; + case '/oauth/register': + break; + case '/oauth/allow': + break; + case '/users/login': + break; + case '/users/revoke_session': + break; + case '/users/newimage': + break; + case '/users/update': + break; + case '/users/newpassword': + break; + case '/users/update_roles': + break; + case '/users/update_active': + break; + case '/users/send_password_reset': + break; + case '/users/reset_password': + break; + case '/users/update_notify': + break; + case '/logout': + break; + case '/hooks/incoming/create': + break; + case '/hooks/incoming/delete': + break; + case '/verify_email': + break; + case '/oauth/access_token': + break; + case '': + break; + default: + if (currentAudit.extra_info.indexOf('revoked_all=') >= 0) { + // do stuff + } else { + let currentActionDesc = ' '; if (currentActionURL && currentActionURL.lastIndexOf('/') !== -1) { currentActionDesc = currentActionURL.substring(currentActionURL.lastIndexOf('/') + 1).replace('_', ' '); currentActionDesc = Utils.toTitleCase(currentActionDesc); } - let currentExtraInfoDesc = ''; + let currentExtraInfoDesc = ' '; if (currentAudit.extra_info) { currentExtraInfoDesc = currentAudit.extra_info; @@ -127,11 +181,23 @@ export default class AccessHistoryModal extends React.Component { currentExtraInfoDesc = currentExtraInfoDesc.substring(currentExtraInfoDesc.indexOf('=') + 1); } } - currentAuditDesc = currentActionDesc + ' ' + currentExtraInfoDesc; - break; } + break; + } + + const currentDate = new Date(currentAudit.create_at); + const currentAuditInfo = currentDate.toDateString() + ' - ' + currentDate.toLocaleTimeString(navigator.language, {hour: '2-digit', minute: '2-digit'}) + ' | ' + currentAuditDesc; + return currentAuditInfo; + } + render() { + var accessList = []; + + for (var i = 0; i < this.state.audits.length; i++) { + const currentAudit = this.state.audits[i]; + const currentAuditInfo = this.formatAuditInfo(currentAudit); + var moreInfo = ( +
{'IP: ' + currentAudit.ip_address}
{'Session ID: ' + currentAudit.session_id}
); @@ -161,7 +232,7 @@ export default class AccessHistoryModal extends React.Component { className='access-history__table' >
-
{currentDate.toDateString() + ' - ' + currentDate.toLocaleTimeString(navigator.language, {hour: '2-digit', minute: '2-digit'}) + ' | ' + currentAuditDesc + ' from ' + currentAudit.ip_address}
+
{currentAuditInfo}
{moreInfo}
-- cgit v1.2.3-1-g7c22