From 536c55dc5f9f80ea67e2ccb39c1b4a276fbddc07 Mon Sep 17 00:00:00 2001 From: Reed Garmsen Date: Wed, 7 Oct 2015 16:58:27 -0700 Subject: Initial changes to audit log along with structure for handling different audit types --- web/react/components/access_history_modal.jsx | 91 ++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 16 deletions(-) (limited to 'web/react/components/access_history_modal.jsx') diff --git a/web/react/components/access_history_modal.jsx b/web/react/components/access_history_modal.jsx index 2ad4d5b00..9aeb7f682 100644 --- a/web/react/components/access_history_modal.jsx +++ b/web/react/components/access_history_modal.jsx @@ -15,7 +15,7 @@ export default class AccessHistoryModal extends React.Component { this.onHide = this.onHide.bind(this); this.onShow = this.onShow.bind(this); - let state = this.getStateFromStoresForAudits(); + const state = this.getStateFromStoresForAudits(); state.moreInfo = []; this.state = state; @@ -54,29 +54,91 @@ export default class AccessHistoryModal extends React.Component { } render() { var accessList = []; - var currentHistoryDate = null; for (var i = 0; i < this.state.audits.length; i++) { var currentAudit = this.state.audits[i]; - var newHistoryDate = new Date(currentAudit.create_at); - var newDate = null; - - if (!currentHistoryDate || currentHistoryDate.toLocaleDateString() !== newHistoryDate.toLocaleDateString()) { - currentHistoryDate = newHistoryDate; - newDate = (
{currentHistoryDate.toDateString()}
); - } + var currentDate = new Date(currentAudit.create_at); if (!currentAudit.session_id && currentAudit.action.search('/users/login') !== -1) { currentAudit.session_id = 'N/A (Login attempt)'; } + 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 = ''; + + 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; + break; + } + var moreInfo = ( - More info + {'More info'} ); @@ -84,7 +146,6 @@ export default class AccessHistoryModal extends React.Component { moreInfo = (
{'Session ID: ' + currentAudit.session_id}
-
{'URL: ' + currentAudit.action.replace(/\/api\/v[1-9]/, '')}
); } @@ -99,11 +160,9 @@ export default class AccessHistoryModal extends React.Component { key={'accessHistoryEntryKey' + i} className='access-history__table' > -
{newDate}
-
{newHistoryDate.toLocaleTimeString(navigator.language, {hour: '2-digit', minute: '2-digit'})}
+
{currentDate.toDateString() + ' - ' + currentDate.toLocaleTimeString(navigator.language, {hour: '2-digit', minute: '2-digit'}) + ' | ' + currentAuditDesc + ' from ' + currentAudit.ip_address}
-
{'IP: ' + currentAudit.ip_address}
{moreInfo}
{divider} @@ -138,13 +197,13 @@ export default class AccessHistoryModal extends React.Component { data-dismiss='modal' aria-label='Close' > - +

- Access History + {'Access History'}