viewer/apiUsers.js
// removes a view from the shared user and adds it to the user that created the view
removes a view from the shared user and adds it to the user that created the view
removes a view from the shared user and adds it to the user that created the view
function unshareView (req, res, user, sharedUser, endpoint, successMessage, errorMessage) {
    User.setUser('_moloch_shared', sharedUser, (err, info) => {
      if (err) {
        console.log('ERROR - unshareView - setUser (_moloch_shared) -', endpoint, util.inspect(err, false, 50), info);
        return res.serverError(500, errorMessage);
      }
      if (user.views[req.body.name]) { 
        return res.serverError(403, 'A view already exists with this name.');
      }
      user.views[req.body.name] = {
        expression: req.body.expression,
        user: req.body.user, 
        shared: false,
        sessionsColConfig: req.body.sessionsColConfig
      };
      User.setUser(user.userId, user, (err, subInfo) => {
        if (err) {
          console.log(`ERROR - saveSharedView - setUser (${user.userId}) -`, endpoint, util.inspect(err, false, 50), subInfo);
          return res.serverError(500, errorMessage);
        }
        return res.send(JSON.stringify({
          success: true,
          text: successMessage
        }));
      });
    });
  }
function unshareView ( req , res , user , sharedUser , endpoint , successMessage , errorMessage ) { User . setUser ( '_moloch_shared' , sharedUser , ( err , info ) => { if ( err ) { console . log ( 'ERROR - unshareView - setUser (_moloch_shared) -' , endpoint , util . inspect ( err , false , 50 ) , info ) ; return res . serverError ( 500 , errorMessage ) ; } if ( user . views [ req . body . name ] ) { return res . serverError ( 403 , 'A view already exists with this name.' ) ; } user . views [ req . body . name ] = { expression : req . body . expression , user : req . body . user , shared : false , sessionsColConfig : req . body . sessionsColConfig } ; User . setUser ( user . userId , user , ( err , subInfo ) => { if ( err ) { console . log ( ` ${ user . userId } ` , endpoint , util . inspect ( err , false , 50 ) , subInfo ) ; return res . serverError ( 500 , errorMessage ) ; } return res . send ( JSON . stringify ( { success : true , text : successMessage } ) ) ; } ) ; } ) ; }
removes a view from the shared user and adds it to the user that created the view
removes a view from the shared user and adds it to the user that created the view
// the user already has a view with this name // keep the user so we know who created it