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

Commit

Permalink
Merge pull request #174 from speckleworks/hotfix-perm-nulls
Browse files Browse the repository at this point in the history
Hotfix perm nulls
  • Loading branch information
didimitrie authored Dec 4, 2019
2 parents cc1107d + 51ddf13 commit 28aa04f
Show file tree
Hide file tree
Showing 4 changed files with 16 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
5 changes: 5 additions & 0 deletions app/api/projects/ProjectPutAddStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ module.exports = async ( req, res ) => {
project.permissions.canRead.forEach( id => {
stream.canRead.indexOf( id ) === -1 ? stream.canRead.push( id ) : null
} )

stream.canRead.indexOf( project.owner ) === -1 ? stream.canRead.push( project.owner ) : null

project.permissions.canWrite.forEach( id => {
stream.canWrite.indexOf( id ) === -1 ? stream.canWrite.push( id ) : null
} )

stream.canWrite.indexOf( project.owner ) === -1 ? stream.canWrite.push( project.owner ) : null

await Promise.all( [ stream.save( ), project.save( ) ] )
return res.send( { success: true, project: project, stream: stream } )
} catch ( err ) {
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 28aa04f

Please sign in to comment.