lib/runners/users.js
function roleOrSelf (role) {
        if (!_.isNumber(role)) {
            role = roles[role.toUpperCase()];
        }

        return function validateRoleOrSelf (kontx, next) {
            var userPrivLevel = roles[kontx.user.role.toUpperCase()],
                passedInUserId = kontx.args[0],
                err = createError(strings.group('codes').forbidden, strings.group('errors').user_privileges_exceeded);

            //If user object passed in instead of a string then parse.
            if (!_.isUndefined(kontx.args[0]._id)) {
                passedInUserId = kontx.args[0]._id;
            }

            //If user has enough priviliges then keep going
            if (userPrivLevel <= parseInt(role, 10) || kontx.user._id.toString() === passedInUserId.toString()) {
                next();
                return;
            }

            next(err);
        };
    }
function roleOrSelf (role) {
        if (!_.isNumber(role)) {
            role = roles[role.toUpperCase()];
        }

        return function validateRoleOrSelf (kontx, next) {
            var userPrivLevel = roles[kontx.user.role.toUpperCase()],
                passedInUserId = kontx.args[0],
                err = createError(strings.group('codes').forbidden, strings.group('errors').user_privileges_exceeded);

            //If user object passed in instead of a string then parse.
            if (!_.isUndefined(kontx.args[0]._id)) {
                passedInUserId = kontx.args[0]._id;
            }

            //If user has enough priviliges then keep going
            if (userPrivLevel <= parseInt(role, 10) || kontx.user._id.toString() === passedInUserId.toString()) {
                next();
                return;
            }

            next(err);
        };
    }
function roleOrSelf ( role ) { if ( ! _ . isNumber ( role ) ) { role = roles [ role . toUpperCase ( ) ] ; } return function validateRoleOrSelf ( kontx , next ) { var userPrivLevel = roles [ kontx . user . role . toUpperCase ( ) ] , passedInUserId = kontx . args [ 0 ] , err = createError ( strings . group ( 'codes' ) . forbidden , strings . group ( 'errors' ) . user_privileges_exceeded ) ; //If user object passed in instead of a string then parse. if ( ! _ . isUndefined ( kontx . args [ 0 ] . _id ) ) { passedInUserId = kontx . args [ 0 ] . _id ; } //If user has enough priviliges then keep going if ( userPrivLevel <= parseInt ( role , 10 ) || kontx . user . _id . toString ( ) === passedInUserId . toString ( ) ) { next ( ) ; return ; } next ( err ) ; } ; }
Middleware the ensures that the user either has a good enough role or is trying to get information
about themselves.
@param role
@returns {Function}
Middleware the ensures that the user either has a good enough role or is trying to get information about themselves .