Skip to content

Commit

Permalink
fix(logs): removes technic fields from 'data' diffs (refs #448)
Browse files Browse the repository at this point in the history
  • Loading branch information
naholyr committed Sep 28, 2017
1 parent 229d9a8 commit c01b3df
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions server/routes/editLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ const editLogsPathFilter = path =>
// {'$$d.path.2':'organization'}
// ]}}
// }
path[0] !== 'latestChangeBy'
!editLogsDataKeysBlacklist.includes(path[0])


// Paths to ignore/remove
const editLogsDataKeysBlacklist = ['_id', 'latestChangeBy']
const editLogsDataKeysFilter = ['updatedAt', 'createdAt'].concat(editLogsDataKeysBlacklist)


const routeParamToModel = param => ({
Expand Down Expand Up @@ -389,27 +391,27 @@ const formatEdits = (data, model, removeConfidential) => {
edit.who = {
id: d.whoID
}
if (d.creator.length){
if (d.creator.length) {
edit.who.name = (d.creator[0].firstName ? d.creator[0].firstName+' ': '')+ d.creator[0].name
edit.who.roles = d.creator[0].isariAuthorizedCenters ?
d.creator[0].isariAuthorizedCenters.map(iac =>({lab:iac.organization,role:iac.isariRole})):
[]
}

edit.date = d.date
edit.item = { id:d.item}
edit.item = { id: d.item }
edit.item.name = formatItemName(d.itemObject[0], model)

edit.action = d.action

if (edit.action === 'update'){
if (edit.action === 'update') {
edit.diff = flattenDiff(d.diff)
.filter(dd => editLogsPathFilter(dd.path))
.map(dd => {
// remove index of element in array from path
const diff = {path: dd.path.filter(e => isNaN(parseInt(e)))}

if (dd.kind === 'A'){
if (dd.kind === 'A') {
//array case...
if (dd.item.lhs)
diff.valueBefore = dd.item.lhs
Expand Down Expand Up @@ -462,7 +464,9 @@ const formatEdits = (data, model, removeConfidential) => {


const dataToDiff = (data, editType) => {
data = cleanupData(data)
data = cleanupData(data) // Handle binary ObjectIds & technic fields (keeps _id, which will be filtered just below)
// Remove fields we don't want in UI
editLogsDataKeysFilter.forEach(f => { delete data[f] })
const field = editType === 'create' ? 'valueAfter' : 'valueBefore'
return Object.keys(data).reduce(appendChange(data, editType, field), [])
}
Expand Down

0 comments on commit c01b3df

Please sign in to comment.