### Handle Permissions
We need to be an authorised user to perform this action
@param {Object} options
@returns {Object} options
12457
function handlePermissions(options) {
            return canThis(options.context).destroy.user(options.id).then(() => {
                options.status = 'all';
                return options;
            }).catch((err) => {
                return Promise.reject(new common.errors.NoPermissionError({
                    err: err,
                    context: common.i18n.t('errors.api.users.noPermissionToDestroyUser')
                }));
            });
        }
81180
def options(self, *args, **kwargs):
        """"""
        self.enable_cache()
        self.handle_session_cookie()
        self.preflight()

        if self.verify_origin():
            allowed_methods = getattr(self, 'access_methods', 'OPTIONS, POST')
            self.set_header('Access-Control-Allow-Methods', allowed_methods)
            self.set_header('Allow', allowed_methods)

            self.set_status(204)
        else:
            # Set forbidden
            self.set_status(403)

        self.finish()
1313267
function normalizeOptions(options) {
  options = options ? options : {}
  if (!options.headers) {
    options.headers = {}
  }
  if (!options.query) {
    options.query = {}
  }
  if (!options.hasOwnProperty('auth')) {
    options.auth = true
  }
  return options
}
157767
function auth(app, config) {
  /* Ensure authorizer */
  if (is.not.function(config.authorizer)) {
    throw new Error(ERR_AUTHORIZER);
  }

  /* Check debug type */
  if (is.function(config.debug)) {
    debug = config.debug;
  } else if (config.debug) {
    debug = console.log.bind(console);
  }

  /* Set the authorized property in 'req.session' */
  app.use((req, res, next) => {
    req.session.authorized = config.authorizer(req);
    next();
  });

  /* Set authorization rules for each route */
  config.routes.forEach((route) => {
    route = normalize(route);

    var router = app.route(route.path);

    if (is.array(route.method) && route.method.length) {
      route.method.forEach((method) => {
        logAssignment(method, route.path, route.allows);
        router[method](generate(route.allows), authorize);
      });
    } else if (is.string(route.method)) {
      logAssignment(route.method, route.path, route.allows);
      router[route.method](generate(route.allows), authorize);
    } else {
      logAssignment(ALL, route.path, route.allows);
      router.all(generate(route.allows), authorize);
    }
  });
}
926398
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_access_moderation_queue(user)
297252
function can(rbac, action, resource, cb) {
  // check existance of permission
  rbac.getPermission(action, resource, (err, permission) => {
    if (err) {
      return cb(err);
    }

    if (!permission) {
      return cb(null, false);
    }

    // check user additional permissions
    if (indexOf(this.permissions, permission.name) !== -1) {
      return cb(null, true);
    }

    if (!this.role) {
      return cb(null, false);
    }

    // check permission inside user role
    return rbac.can(this.role, action, resource, cb);
  });

  return this;
}
21328
function adminAcl(options) {
  var opts = options || {};

  if (!opts.secret) {
    throw new Error('missing secret');
  }

  var expectedHeader;
  if (opts.prefix) {
    expectedHeader = opts.prefix + ' ' + opts.secret;
  }
  else {
    expectedHeader = module.exports.DEFAULT_PREFIX + opts.secret;
  }

  return function (req, res, next) {
    debug('inside of the middleware headerCheck');

    var msg401 = { success: false, message: 'Unauthorized' };

    if (!req.headers) {
      debug('no headers found - misconfiguration probably');
      return res.status(401).send(msg401);
    }
    
    if (!req.headers.authorization) {
      debug('no authorization header found');
      return res.status(401).send(msg401);
    }

    debug('we have a token it seems');
    var receivedHeader = req.headers.authorization;

    if (secureCompare(receivedHeader, expectedHeader)) {
      next();
    }
    else {
      debug('failed on secret match');
      return res.status(401).send(msg401);
    }
  };
}
1236608
def fetch(options = {})
      super(options).tap do |fetched|
        fetched.role = role
        fetched.permissions = permissions
      end
    end
1259106
def __get_permissions(self, res, **kwargs):
        
        response = res._(**kwargs)
        return response.get('permissions', None)
579842
function doQuery(options) {
            return models.User.changePassword(
                options.data.password[0],
                _.omit(options, ['data'])
            ).then(() => {
                return Promise.resolve({
                    password: [{message: common.i18n.t('notices.api.users.pwdChangedSuccessfully')}]
                });
            });
        }
825929
function Management(options) {
  /* eslint-disable */
  assert.check(
    options,
    { type: 'object', message: 'options parameter is not valid' },
    {
      domain: { type: 'string', message: 'domain option is required' },
      token: { type: 'string', message: 'token option is required' },
      _sendTelemetry: {
        optional: true,
        type: 'boolean',
        message: '_sendTelemetry option is not valid'
      },
      _telemetryInfo: {
        optional: true,
        type: 'object',
        message: '_telemetryInfo option is not valid'
      }
    }
  );
  /* eslint-enable */

  this.baseOptions = options;

  this.baseOptions.headers = { Authorization: 'Bearer ' + this.baseOptions.token };

  this.request = new RequestBuilder(this.baseOptions);
  this.baseOptions.rootUrl = urljoin('https://' + this.baseOptions.domain, 'api', 'v2');
}
637106
function(permissions, callback) { // eslint-disable-line camelcase
      var body = permissions;
      var prefix = '_api/v2/db/'; // use `/_api/v2/<db>/_security` endpoint

      if (permissions['couchdb_auth_only']) {
        // https://console.bluemix.net/docs/services/Cloudant/api/authorization.html#using-the-_users-database-with-cloudant-nosql-db
        prefix = ''; // use `/<db>/_security` endpoint
      } else if (!permissions.cloudant) {
        body = { cloudant: permissions };
      }

      return nano.request({
        path: prefix + encodeURIComponent(db) + '/_security',
        method: 'put',
        body: body
      }, callback);
    }
675435
function(objects, user, action, model, body) {
    if (!_.isArray(objects)) {
      return PermissionService.isAllowedToPerformSingle(user.id, action, model, body)(objects);
    }
    return Promise.all(objects.map(PermissionService.isAllowedToPerformSingle(user.id, action, model, body)))
      .then(function (allowedArray) {
        return allowedArray.every(function (allowed) {
          return allowed === true;
        });
      });
  }
182819
def permitted_to! (privilege, options = {} )
      options = {
        :user =>  Authorization.current_user,
        :object => self
      }.merge(options)
      Authorization::Engine.instance.permit!(privilege,
          {:user => options[:user],
           :object => options[:object]})
    end
588698
function UseAuth(options) {
    return function (constructor) {
        if (options) {
            constructor.prototype.useAuth = options;
        }
        else {
            constructor.prototype.useAuth = { create: true, update: true, read: true, delete: true };
        }
    };
}
124674
function (req) {
	var session = l_getSession(req);
	if (session.hasOwnProperty('_user')) {
		var login = session._user;
		login.admin = (session._user.account === 'admin');
		return login;
	}
	
	LOG.warn('user not yet logined...');
	return {control: {groups: [], permissions: []}};
}
1222047
function(user, action, model, body) {
    return function(obj) {
      return new Promise(function(resolve, reject) {
        Model.findOne({
          identity: model
        }).then(function(model) {
         return Permission.find({
            model: model.id,
            action: action,
            relation: 'user',
            user: user
          }).populate('criteria');
        }).then(function(permission) {
          if (permission.length > 0 && PermissionService.hasPassingCriteria(obj, permission, body)) {
            resolve(true);
          } else {
            resolve(false);
          }
        }).catch(reject);
      });
    };
  }