Prevents access to anyone who is not in the "admin" role.
198256
function adminsOnly(req, res, next) {
  if (req.session && _.contains(req.session.user.roles, 'admin')) {
    next();
  }
  else {
    res.status(401).send('Only administrators can access this resource');
  }
}
226385
def blocked(self):
        
        """
        return [r.user for r in self._relationships.values() if r.type is RelationshipType.blocked]
537458
def deny(ip,
        port=None,
        proto='tcp',
        direction='in',
        port_origin='d',
        ip_origin='d',
        ttl=None,
        comment=''):
    '''
    
    '''
    return _access_rule('deny', ip, port, proto, direction, port_origin, ip_origin, comment)
27985
def is_admin(self, roles):
        """"""
        for r in roles:
            if r in self.admin_roles:
                return True
        return False
233002
def access(self, user):
        """"""
        if self.denyusers:
            if user in self.denyusers:
                return False
        if self.allowusers:
            if not user in self.allowusers:
                return False
        return True
664914
def clear_roles(user):
    """"""
    roles = get_user_roles(user)

    for role in roles:
        role.remove_role_from_user(user)

    return roles
93752
def disable_restricted(self, ):
        
        todisable = [(self.reftrack.duplicate, self.duplicate_tb),
                     (self.reftrack.delete, self.delete_tb),
                     (self.reftrack.reference, self.reference_tb),
                     (self.reftrack.replace, self.replace_tb),]
        for action, btn in todisable:
            res = self.reftrack.is_restricted(action)
            btn.setDisabled(res)
1233309
def is_admin(self):
        
        for ur in self.roleusers:
            if ur.role.code == 'admin':
                return True

        return False
204799
def remove_role(*_, role_handle=None, user_id=None):
    
    click.echo(green('\nRemoving role from user:'))
    click.echo(green('-' * 40))
    with get_app().app_context():
        user = find_user(dict(id=user_id))
        if not user:
            click.echo(red('User not found\n'))
            return

        remove_role = None
        for role in user.roles:
            if role.handle == role_handle:
                remove_role = role

        if not remove_role:
            click.echo(red('User does not have such role\n'))
            return

        user_service.remove_role_from_user(user, remove_role)
        msg = 'Role "{}" removed from user "{}"\n'.format(
            remove_role.handle,
            user.email
        )
        click.echo(green(msg))
        return
692827
def disable(other_user, reason)
      return false unless other_user&.system_admin?
      return false if other_user == self

      update_columns(
          disabled_by: other_user.email,
          disabled_at: Time.now,
          disabled_reason: reason,
          enabled: false
      ) && refresh_comments
    end
595968
def _delLocalOwnerRole(self, username):
        
        parent = self.getParent()
        if parent.portal_type == "Client":
            parent.manage_delLocalRoles([username])
            # reindex object security
            self._recursive_reindex_object_security(parent)
1075470
def permitted(refresh = false)
      @permitted = nil if refresh
      @permitted ||=
          if require_admin?
            'Administrators Only'
          elsif require_anon?
            'Anonymous Only'
          elsif allow_anon?
            'Everyone'
          elsif groups.any?
            names = groups.pluck(:name).map{|v| "\"#{v}\""}
            'Members of ' +
                if names.count == 1
                  names.first
                elsif names.count == 2
                  names.join(' or ')
                else
                  names[0...-1].join(', ') + ', or ' + names.last
                end
          else
            'All Users'
          end +
              if non_standard
                ' (Non-Standard)'
              else
                ''
              end
    end
1330154
def revoke_member(context, request):
    """"""

    mapping = request.json['mapping']
    for entry in mapping:
        user = entry['user']
        roles = entry['roles']
        username = user.get('username', None)
        userid = user.get('userid', None)
        if userid:
            u = context.get_user_by_userid(userid)
        elif username:
            u = context.get_user_by_username(username)
        else:
            u = None
        if u is None:
            raise UnprocessableError(
                'User %s does not exists' % (userid or username))
        for rolename in roles:
            context.revoke_member_role(u.userid, rolename)
    return {'status': 'success'}
606974
def remove_tenant_user_role(request, project=None, user=None, role=None,
                            group=None, domain=None):
    """"""
    manager = keystoneclient(request, admin=True).roles
    if VERSIONS.active < 3:
        return manager.remove_user_role(user, role, project)
    else:
        return manager.revoke(role, user=user, project=project,
                              group=group, domain=domain)
436199
def suspend(instance_id, profile=None, **kwargs):
    '''
    

    '''
    conn = _auth(profile, **kwargs)
    return conn.suspend(instance_id)
63185
public static function deny($roles)
    {
        if (static::isAdministrator()) {
            return true;
        }

        if (Auth::guard('admin')->user()->inRoles($roles)) {
            static::error();
        }
    }
576498
def drop_privileges ():
    """"""
    if os.name != 'posix':
        return
    if os.geteuid() == 0:
        log.warn(LOG_CHECK, _("Running as root user; "
                       "dropping privileges by changing user to nobody."))
        import pwd
        os.seteuid(pwd.getpwnam('nobody')[3])