For use with javascript user selector that allows for searching for an existing user
 and granting them permission to an object.
 @param [User] user to select
 @param [String] role granting the user permission (e.g. 'Manager' | 'Depositor' | 'Viewer')
765331
def select_user(user, role = 'Depositor')
      first('a.select2-choice').click
      find('.select2-input').set(user.user_key)
      sleep 1
      first('div.select2-result-label').click
      within('div.add-users') do
        select(role)
        find('input.edit-collection-add-sharing-button').click
      end
    end
1244194
def visible_for?(user)
      can_view_page = (
        if dropdown?
          true
        elsif menuable.kind_of?(Effective::Page)
          menuable.roles_permit?(user)
        else
          true
        end
      )

      can_view_menu_item = (
        if roles_mask == nil
          true
        elsif roles_mask == -1 # Am I logged out?
          user.blank?
        elsif roles_mask == 0 # Am I logged in?
          user.present?
        else
          roles_permit?(user)
        end
      )

      can_view_page && can_view_menu_item
    end
1023868
def role(id)
      id = id.resolve_id
      @roles.find { |e| e.id == id }
    end
574027
def evaluate_permission(permission, *args)
      # object; Event, Discount, etc
      o = args[0]
      # default to allow
      result = true
      role = get_role_of(o)


      # evaluate procs
      if (proc = PermissionUtilities.has_procs?(permission))
        result &= proc.call(o, self)
      end

      # Here is where the addition of adding collaborations may reside

      # finally, determine if the user (self) can do the requested action
      result &= allowed_to_perform?(permission, role)

      # so we don't need to do everything again
      cache.set_for_role(
        name: permission,
        value: result,
        role: role
      )

      result
    end
910245
def select_role(self):
        

        roles = [(m.key, m.__unicode__()) for m in RoleModel.objects.filter(
            abstract_role=self.current.role.abstract_role,
            unit=self.current.role.unit) if m != self.current.role]

        if roles:
            _form = forms.JsonForm(title=_(u'Assign to workflow'))
            _form.select_role = fields.Integer(_(u"Chose Role"), choices=roles)
            _form.explain_text = fields.String(_(u"Explain Text"), required=False)
            _form.send_button = fields.Button(_(u"Send"))
            self.form_out(_form)
        else:
            title = _(u"Unsuccessful")
            msg = _(u"Assign role not found")
            self.current.msg_box(title=title, msg=msg)
673119
def grant_admin_role(self):
    
    apiuser = ApiUser(self._get_resource_root(), self.name, roles=['ROLE_ADMIN'])
    return self._put('', ApiUser, data=apiuser)
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
822173
public boolean isUserInRole(String role) {
        if (!isEnabled()) {
            throw new IllegalStateException("security module is disabled");
        }
        checkInit();
        SecurityProvider securityProvider = context.getSecurityProvider();
        boolean contained = role == ALL_ROLE || securityProvider.isUserInRole(role);
        LOGGER.debug("isUserInRole returns {} for role {}", contained, role);
        return contained;
    }
600569
def has_access?(permission, user)
      raise UnknownUserException if user.nil?

      AccessProvider.action_permitted_for_user?(permission, user)
    end
304069
function handlePermissions(options) {
            return models.Role.findOne({name: 'Owner'}).then((ownerRole) => {
                return canThis(options.context).assign.role(ownerRole);
            }).then(() => {
                return options;
            });
        }
1166927
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_add_post(obj, user)
546909
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_vote_in_poll(obj, user)
1190925
public ServerUpdater addRoleToUser(User user, Role role) {
        delegate.addRoleToUser(user, role);
        return this;
    }
926007
def set_user(self, user):
        
        self.session['user_id'] = user.key
        self.session['user_data'] = user.clean_value()
        role = self.get_role()
        # TODO: this should be remembered from previous login
        # self.session['role_data'] = default_role.clean_value()
        self.session['role_id'] = role.key
        self.current.role_id = role.key
        self.current.user_id = user.key
        # self.perm_cache = PermissionCache(role.key)
        self.session['permissions'] = role.get_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);
      });
    };
  }
393212
def remove_role_from_user(self, user, role):
        
        rv = False
        user, role = self._prepare_role_modify_args(user, role)
        if role in user.roles:
            rv = True
            user.roles.remove(role)
            self.put(user)
        return rv
1250478
function User(user, rollout) {
  if (!user || !rollout) {
    throw new Error("The  expected two params.");
  }

  this.user    = user;
  this.rollout = rollout;

  if ('object' === typeof this.rollout) {
    var name = this.rollout.name('rollout:users');
    this.rollout.client.sadd(name, user.id, function(err, result) {});
  }
}