Skip to content

Commit

Permalink
feat(edit-logs): removes filter
Browse files Browse the repository at this point in the history
  • Loading branch information
naholyr committed Sep 6, 2017
1 parent 898140b commit 5788cff
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions server/routes/editLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@ function formatKind(kind){
}

function editLogsPathFilter(path){
// blacklisting weird diff generated by edtiLogs middleware or internal fields
// This filtering should be done in mongo direclty to avoid problems with pagination
// Turning those filter in mongo might be possible with $filter
// This doesn't work :
// $filter:{
// input:'$diff',
// as:'d',
// cond:{$not:{$and:[
// {'$$d.path.3':{$exists: true}},
// {'$$d.path.0':'academicMemberships'},
// {'$$d.path.2':'organization'}
// ]}}
// }

const keep = path[0] !== 'latestChangeBy' && // internal field
!(path.length > 2 && path[0] === 'academicMemberships' && path [2] === 'organization') &&
!path.includes('id') // weird diff for foreign keys
return keep
// blacklisting weird diff generated by edtiLogs middleware or internal fields
// This filtering should be done in mongo direclty to avoid problems with pagination
// Turning those filter in mongo might be possible with $filter
// This doesn't work :
// $filter:{
// input:'$diff',
// as:'d',
// cond:{$not:{$and:[
// {'$$d.path.3':{$exists: true}},
// {'$$d.path.0':'academicMemberships'},
// {'$$d.path.2':'organization'}
// ]}}
// }
return path[0] !== 'latestChangeBy'
}


Expand Down Expand Up @@ -267,8 +263,6 @@ function formatEdits(data, model){
if (edit.action === 'update'){
edit.diff = d.diff
.map(flattenDiff)
// blaclisting weird diffs
.filter(dd => editLogsPathFilter(dd.path))
.map(dd => {
// remove index of element in array from path
const diff = {path: dd.path.filter(e => typeof e !== 'number')}
Expand Down

0 comments on commit 5788cff

Please sign in to comment.