middleware/mw.caller.js
function getCaller(req) {
        var ipAddress = req.headers['x-forwarded-for'] || req.info.remoteAddress || '';
        var user = req.user;

        if (user) {

            // if user admin and there is an onBehalfOf value then use onBehalfOf
            if (user.role === 'admin' && req.query.onBehalfOfId) {
                return {
                    _id:    req.query.onBehalfOfId,
                    name:   req.query.onBehalfOfName,
                    role:   req.query.onBehalfOfRole,
                    type:   req.query.onBehalfOfType,
                    ipAddress: ipAddress
                };
            }

            // else return user data as caller info
            return {
                _id:    user._id,
                name:   user.username,
                role:   user.role,
                type:   'user',
                user:   user,
                ipAddress: ipAddress
            };

        }
        else if (req.deviceId) {
            return {
                _id:    req.deviceId,
                name:   req.deviceId,
                role:   'device',
                type:   'device',
                ipAddress: ipAddress
            };
        }
        // if no other auth, but GET then defer to fakeblock ACL level security
        //else if (req.method === 'get' || req.method === 'options') {
        else {
            return {
                _id:    'unknown',
                name:   'unknown',
                role:   'visitor',
                type:   'visitor',
                ipAddress: ipAddress
            };
        }
    }
function getCaller(req) {
        var ipAddress = req.headers['x-forwarded-for'] || req.info.remoteAddress || '';
        var user = req.user;

        if (user) {

            // if user admin and there is an onBehalfOf value then use onBehalfOf
            if (user.role === 'admin' && req.query.onBehalfOfId) {
                return {
                    _id:    req.query.onBehalfOfId,
                    name:   req.query.onBehalfOfName,
                    role:   req.query.onBehalfOfRole,
                    type:   req.query.onBehalfOfType,
                    ipAddress: ipAddress
                };
            }

            // else return user data as caller info
            return {
                _id:    user._id,
                name:   user.username,
                role:   user.role,
                type:   'user',
                user:   user,
                ipAddress: ipAddress
            };

        }
        else if (req.deviceId) {
            return {
                _id:    req.deviceId,
                name:   req.deviceId,
                role:   'device',
                type:   'device',
                ipAddress: ipAddress
            };
        }
        // if no other auth, but GET then defer to fakeblock ACL level security
        //else if (req.method === 'get' || req.method === 'options') {
        else {
            return {
                _id:    'unknown',
                name:   'unknown',
                role:   'visitor',
                type:   'visitor',
                ipAddress: ipAddress
            };
        }
    }
function getCaller ( req ) { var ipAddress = req . headers [ 'x-forwarded-for' ] || req . info . remoteAddress || '' ; var user = req . user ; if ( user ) { // if user admin and there is an onBehalfOf value then use onBehalfOf if ( user . role === 'admin' && req . query . onBehalfOfId ) { return { _id : req . query . onBehalfOfId , name : req . query . onBehalfOfName , role : req . query . onBehalfOfRole , type : req . query . onBehalfOfType , ipAddress : ipAddress } ; } // else return user data as caller info return { _id : user . _id , name : user . username , role : user . role , type : 'user' , user : user , ipAddress : ipAddress } ; } else if ( req . deviceId ) { return { _id : req . deviceId , name : req . deviceId , role : 'device' , type : 'device' , ipAddress : ipAddress } ; } // if no other auth, but GET then defer to fakeblock ACL level security //else if (req.method === 'get' || req.method === 'options') { else { return { _id : 'unknown' , name : 'unknown' , role : 'visitor' , type : 'visitor' , ipAddress : ipAddress } ; } }
Get the caller based on the request
@param req
@returns {*}
Get the caller based on the request