authorize(req, action) {
        return new Promise((resolve, reject) => {
            if (!$session.checkPermissions(req)) {
                Logger.warn(errMessages.noPermissions);
                reject(new UnauthorizedError(codes._45));
            }
            let permissions = $session.getPermissions(req);
            let payload = $session.getPayload(req);
            let permID = this.config.authorization.permissions;
            if (_.has(permissions, permID + '.' + action)) {
                if ($session.role === access.roles.super) {
                    Logger.info('Authorized as super admin'); /** @todo Remove */
                    resolve(true);
                }
                else if (permissions[permID][action] === access.all) {
                    Logger.info('All user authorized'); /** @todo Remove */
                    resolve(true)
                } else if (permissions[permID][action] === access.owner && (payload.sub == req.params.id)) {
                    Logger.info('Authorized as owner'); /** @todo Remove */
                    resolve(true);
                }
            } else {
                Logger.warn(errMessages.missingPathPerm);
            }
            reject(new UnauthorizedError(codes._45));
        });
    }
/**
     * Core function to check if a user is authorized to perform a particular action on a particular resource.
     * The user must have an active session with permissions defining what the user has access to
     * @method
     * @param {object} req - Express request object.
     * @param {string} action - The action to be performed.
     * @returns {Promise} 
     */
Core function to check if a user is authorized to perform a particular action on a particular resource.
The user must have an active session with permissions defining what the user has access to
@method
@param {object} req - Express request object.
@param {string} action - The action to be performed.
@returns {Promise}
Core function to check if a user is authorized to perform a particular action on a particular resource . The user must have an active session with permissions defining what the user has access to @method @param { object } req - Express request object . @param { string } action - The action to be performed . @returns { Promise }
authorize(req, action) {
        return new Promise((resolve, reject) => {
            if (!$session.checkPermissions(req)) {
                Logger.warn(errMessages.noPermissions);
                reject(new UnauthorizedError(codes._45));
            }
            let permissions = $session.getPermissions(req);
            let payload = $session.getPayload(req);
            let permID = this.config.authorization.permissions;
            if (_.has(permissions, permID + '.' + action)) {
                if ($session.role === access.roles.super) {
                    Logger.info('Authorized as super admin'); 
                    resolve(true);
                }
                else if (permissions[permID][action] === access.all) {
                    Logger.info('All user authorized'); 
                    resolve(true)
                } else if (permissions[permID][action] === access.owner && (payload.sub == req.params.id)) {
                    Logger.info('Authorized as owner'); 
                    resolve(true);
                }
            } else {
                Logger.warn(errMessages.missingPathPerm);
            }
            reject(new UnauthorizedError(codes._45));
        });
    }
authorize ( req , action ) { return new Promise ( ( resolve , reject ) => { if ( ! $session . checkPermissions ( req ) ) { Logger . warn ( errMessages . noPermissions ) ; reject ( new UnauthorizedError ( codes . _45 ) ) ; } let permissions = $session . getPermissions ( req ) ; let payload = $session . getPayload ( req ) ; let permID = this . config . authorization . permissions ; if ( _ . has ( permissions , permID + '.' + action ) ) { if ( $session . role === access . roles . super ) { Logger . info ( 'Authorized as super admin' ) ; resolve ( true ) ; } else if ( permissions [ permID ] [ action ] === access . all ) { Logger . info ( 'All user authorized' ) ; resolve ( true ) } else if ( permissions [ permID ] [ action ] === access . owner && ( payload . sub == req . params . id ) ) { Logger . info ( 'Authorized as owner' ) ; resolve ( true ) ; } } else { Logger . warn ( errMessages . missingPathPerm ) ; } reject ( new UnauthorizedError ( codes . _45 ) ) ; } ) ; }
Core function to check if a user is authorized to perform a particular action on a particular resource.
Core function to check if a user is authorized to perform a particular action on a particular resource .
/** @todo Remove */ /** @todo Remove */ /** @todo Remove */