Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
fix(permissions): filters nulls out in places
Browse files Browse the repository at this point in the history
filters any nulls in canRead and canWrite arrays

part fixes #118
  • Loading branch information
didimitrie committed Dec 4, 2019
1 parent 3f29fc1 commit 779751b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/api/middleware/PermissionCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ module.exports = ( user, operation, resource, mod ) => {
}

// let's get basic
let canRead = resource.canRead.map( x => x.toString( ) )
let canWrite = resource.canWrite.map( x => x.toString( ) )
let canRead = resource.canRead.filter( x => !!x ).map( x => x.toString( ) )
let canWrite = resource.canWrite.filter( x => !!x ).map( x => x.toString( ) )

switch ( operation ) {
case 'write':
Expand Down
6 changes: 5 additions & 1 deletion app/api/projects/ProjectPut.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ module.exports = ( req, res ) => {

Project.findOne( { _id: req.params.projectId } )
.then( resource => PermissionCheck( req.user, 'write', resource ) )
.then( resource => resource.set( req.body ).save( ) )
.then( resource => {
resource.canRead = resource.canRead.filter( x => !!x )
resource.canWrite = resource.canWrite.filter( x => !!x )
return resource.set( req.body ).save( )
} )
.then( ( ) => {
res.send( { success: true, message: `Patched ${Object.keys( req.body )} for ${req.params.projectId}.` } )
} )
Expand Down
4 changes: 4 additions & 0 deletions app/api/streams/StreamPut.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ module.exports = ( req, res ) => {
.then( result => {
stream.set( req.body )
if ( objsToSave.length > 0 ) stream.objects = result.map( obj => obj._id )

stream.canRead = stream.canRead.filter( x => !!x )
stream.canWrite = stream.canWrite.filter( x => !!x )

return stream.save( )
} )
.then( ( ) => {
Expand Down

0 comments on commit 779751b

Please sign in to comment.