vicinityManager/server/services/sharingRules.js
/*
An organisation stops being my partner
I need to remove my devices with friend data access Level
To do so, I remove the group which shares with my friend and the group which
my friend is using to share with me.
*/
An organisation stops being my partner
I need to remove my devices with friend data access Level
To do so, I remove the group which shares with my friend and the group which
my friend is using to share with me.
An organisation stops being my partner I need to remove my devices with friend data access Level To do so I remove the group which shares with my friend and the group which my friend is using to share with me .
function removeFriend(my_id, friend_id, email){
  logger.debug('removing friend');
  var items1, items2, items;
  return new Promise(function(resolve, reject) {
    itemOp.find({'cid.id':my_id, accessLevel: {$lt: 2}, 'hasContracts.contractingParty':friend_id}, {hasContracts:1, oid:1, cid:1, accessLevel:1, typeOfItem:1}).populate('cid.id', 'knows')
    .then(function(response){
      if(response){ items1 = response; }
      return itemOp.find({'cid.id':friend_id, accessLevel: {$lt: 2}, 'hasContracts.contractingParty':my_id}, {hasContracts:1, oid:1, cid:1, accessLevel:1, typeOfItem:1}).populate('cid.id', 'knows');
    })
    .then(function(response){
      if(response){ items2 = response; }
        items = items1.concat(items2);
      if(items.length !== 0){ 
        logger.debug('Start async handler...');
        sync.forEachAll(items,
          function(value, allresult, next, otherParams) {
            ctHelper.removeDevice(value, otherParams, function(value, result) {
                allresult.push({value: value, error: result});
                next();
            });
          },
          function(allresult) {
            if(allresult.length === items.length){
              logger.debug('Completed async handler: ' + JSON.stringify(allresult));
              resolve({"error": false, "message": allresult });
            }
          },
          false,
          {email: email}
        );
      } else {
        logger.debug('Unfriending: No items to delete');
        logger.warn({user:email, action: 'removeContract', message: "Nothing to be removed"});
        resolve({"error": false, "message": "Nothing to be removed..."});
      }
    })
    .catch(function(error){
      logger.debug('Error remove friend: ' + error);
      reject({error: true, message: error});
    });
  });
}
function removeFriend ( my_id , friend_id , email ) { logger . debug ( 'removing friend' ) ; var items1 , items2 , items ; return new Promise ( function ( resolve , reject ) { itemOp . find ( { 'cid.id' : my_id , accessLevel : { $lt : 2 } , 'hasContracts.contractingParty' : friend_id } , { hasContracts : 1 , oid : 1 , cid : 1 , accessLevel : 1 , typeOfItem : 1 } ) . populate ( 'cid.id' , 'knows' ) . then ( function ( response ) { if ( response ) { items1 = response ; } return itemOp . find ( { 'cid.id' : friend_id , accessLevel : { $lt : 2 } , 'hasContracts.contractingParty' : my_id } , { hasContracts : 1 , oid : 1 , cid : 1 , accessLevel : 1 , typeOfItem : 1 } ) . populate ( 'cid.id' , 'knows' ) ; } ) . then ( function ( response ) { if ( response ) { items2 = response ; } items = items1 . concat ( items2 ) ; if ( items . length !== 0 ) { logger . debug ( 'Start async handler...' ) ; sync . forEachAll ( items , function ( value , allresult , next , otherParams ) { ctHelper . removeDevice ( value , otherParams , function ( value , result ) { allresult . push ( { value : value , error : result } ) ; next ( ) ; } ) ; } , function ( allresult ) { if ( allresult . length === items . length ) { logger . debug ( 'Completed async handler: ' + JSON . stringify ( allresult ) ) ; resolve ( { "error" : false , "message" : allresult } ) ; } } , false , { email : email } ) ; } else { logger . debug ( 'Unfriending: No items to delete' ) ; logger . warn ( { user : email , action : 'removeContract' , message : "Nothing to be removed" } ) ; resolve ( { "error" : false , "message" : "Nothing to be removed..." } ) ; } } ) . catch ( function ( error ) { logger . debug ( 'Error remove friend: ' + error ) ; reject ( { error : true , message : error } ) ; } ) ; } ) ; }
An organisation stops being my partner
I need to remove my devices with friend data access Level
To do so, I remove the group which shares with my friend and the group which
my friend is using to share with me.
An organisation stops being my partner I need to remove my devices with friend data access Level To do so I remove the group which shares with my friend and the group which my friend is using to share with me .
// Check if there is any item to modify // Removes invalid contracts from all affected devices