This repository was archived by the owner on Apr 13, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +24
-14
lines changed
Expand file tree Collapse file tree 1 file changed +24
-14
lines changed Original file line number Diff line number Diff line change @@ -474,20 +474,30 @@ GameSchema.methods.hasPermission = function(token, callback) {
474474 * @param {function } callback The callback with result
475475 * @return {Promise } The promise object for async action
476476 */
477- GameSchema . statics . addGroup = function ( ids , groupId , permission , callback ) {
478- if ( ! Array . isArray ( ids ) ) ids = [ ids ] ;
479-
480- var group = {
481- group : groupId ,
482- permission : permission
483- } ;
484-
485- this . update (
486- { _id : { $in : ids } } ,
487- { $push : { groups : group } } ,
488- { multi : true } ,
489- callback
490- ) ;
477+ GameSchema . statics . addGroup = function ( ids , groupId , permission , callback )
478+ {
479+ if ( ! Array . isArray ( ids ) ) ids = [ ids ] ;
480+
481+ var group = {
482+ group : groupId ,
483+ permission : permission
484+ } ;
485+
486+ // logic implements overwrite of existing with incoming
487+ // first remove any old entries associated with the group in question
488+ this . update (
489+ { _id : { $in : ids } } ,
490+ { $pull : { groups : { group : { $in : [ groupId ] } } } }
491+ )
492+ // then add the 'new' permission level
493+ . then ( ( ) => {
494+ this . update (
495+ { _id : { $in : ids } } ,
496+ { $push : { groups : group } } ,
497+ { multi : true } ,
498+ callback
499+ ) ;
500+ } ) ;
491501} ;
492502
493503/**
You can’t perform that action at this time.
0 commit comments