Finished structure for formatting audits and began writing individual formatting for each audit

Этот коммит содержится в:
Reed Garmsen
2015-10-09 16:35:59 -07:00
родитель 536c55dc5f
Коммит 487c47e803

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

@@ -14,6 +14,7 @@ export default class AccessHistoryModal extends React.Component {
this.handleMoreInfo = this.handleMoreInfo.bind(this); this.handleMoreInfo = this.handleMoreInfo.bind(this);
this.onHide = this.onHide.bind(this); this.onHide = this.onHide.bind(this);
this.onShow = this.onShow.bind(this); this.onShow = this.onShow.bind(this);
this.formatAuditInfo = this.formatAuditInfo.bind(this);
const state = this.getStateFromStoresForAudits(); const state = this.getStateFromStoresForAudits();
state.moreInfo = []; state.moreInfo = [];
@@ -52,22 +53,12 @@ export default class AccessHistoryModal extends React.Component {
newMoreInfo[index] = true; newMoreInfo[index] = true;
this.setState({moreInfo: newMoreInfo}); this.setState({moreInfo: newMoreInfo});
} }
render() { formatAuditInfo(currentAudit) {
var accessList = [];
for (var i = 0; i < this.state.audits.length; i++) {
var currentAudit = this.state.audits[i];
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]/, ''); const currentActionURL = currentAudit.action.replace(/\/api\/v[1-9]/, '');
let currentAuditDesc = ' '; let currentAuditDesc = ' ';
/* Handle specific audit type formatting semi-individually 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:
@@ -84,21 +75,51 @@ export default class AccessHistoryModal extends React.Component {
- Allow Attempt/Success/Failure X - Allow Attempt/Success/Failure X
/team /team
- Revoke All Sessions X (NO CORRESPONDING ADDRESS) - Revoke All Sessions X (NO CORRESPONDING ADDRESS/FUNCTION)
- Revoke Session X
- Update (users - ?) X - Update (users - ?) X
- Update Notify (?) X - Update Notify (?) X
- Login Attempt X - Login Attempt X
- Login (success/failure) X - Login (success/failure) X
- Logout (/logout) X - Logout (/logout) X
- Verify Email (/verify_email) X
*/ */
switch (currentActionURL) { switch (currentActionURL) {
/* BREAK UP CHANNEL INTO OWN SWITCH STATEMENT TO REUSE VARIABLES AND BE CLEAN */
case '/channels/create': 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; break;
case '/channels/update': 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; break;
case '/channels/update_desc':
break; /* case '/channels/update_desc':
const updateChannelInfo = currentAudit.extra_info.split('=');
let originalChannelName = '';
if (updateChannelInfo[0] === 'name') {
originalChannelName = updateChannelInfo[1];
}
currentAuditDesc = 'Updated the channel/group name for ' + originalChannelName;
break;*/
case /\/channels\/[A-Za-z0-9]+\/delete/: case /\/channels\/[A-Za-z0-9]+\/delete/:
break; break;
case /\/channels\/[A-Za-z0-9]+\/add/: case /\/channels\/[A-Za-z0-9]+\/add/:
@@ -109,11 +130,44 @@ export default class AccessHistoryModal extends React.Component {
break; break;
case '/oauth/allow': case '/oauth/allow':
break; break;
case '/team/': 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; break;
default: default:
let currentActionDesc = ''; if (currentAudit.extra_info.indexOf('revoked_all=') >= 0) {
// do stuff
} else {
let currentActionDesc = ' ';
if (currentActionURL && currentActionURL.lastIndexOf('/') !== -1) { if (currentActionURL && currentActionURL.lastIndexOf('/') !== -1) {
currentActionDesc = currentActionURL.substring(currentActionURL.lastIndexOf('/') + 1).replace('_', ' '); currentActionDesc = currentActionURL.substring(currentActionURL.lastIndexOf('/') + 1).replace('_', ' ');
currentActionDesc = Utils.toTitleCase(currentActionDesc); currentActionDesc = Utils.toTitleCase(currentActionDesc);
@@ -127,11 +181,23 @@ export default class AccessHistoryModal extends React.Component {
currentExtraInfoDesc = currentExtraInfoDesc.substring(currentExtraInfoDesc.indexOf('=') + 1); currentExtraInfoDesc = currentExtraInfoDesc.substring(currentExtraInfoDesc.indexOf('=') + 1);
} }
} }
currentAuditDesc = currentActionDesc + ' ' + currentExtraInfoDesc; 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 = ( var moreInfo = (
<a <a
href='#' href='#'
@@ -143,8 +209,13 @@ 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) {
currentAudit.session_id = 'N/A (Login attempt)';
}
moreInfo = ( moreInfo = (
<div> <div>
<div>{'IP: ' + currentAudit.ip_address}</div>
<div>{'Session ID: ' + currentAudit.session_id}</div> <div>{'Session ID: ' + currentAudit.session_id}</div>
</div> </div>
); );
@@ -161,7 +232,7 @@ export default class AccessHistoryModal extends React.Component {
className='access-history__table' className='access-history__table'
> >
<div className='access__report'> <div className='access__report'>
<div className='report__time'>{currentDate.toDateString() + ' - ' + currentDate.toLocaleTimeString(navigator.language, {hour: '2-digit', minute: '2-digit'}) + ' | ' + currentAuditDesc + ' from ' + currentAudit.ip_address}</div> <div className='report__time'>{currentAuditInfo}</div>
<div className='report__info'> <div className='report__info'>
{moreInfo} {moreInfo}
</div> </div>