Adds a new user role
320790
protected function addUserRole()
    {
        $this->controlAccess('user_role_add');

        if ($this->role->add($this->getSubmitted())) {
            $this->redirect('admin/user/role', $this->text('Role has been added'), 'success');
        }

        $this->redirect('', $this->text('Role has not been added'), 'warning');
    }
1312991
def make_admin(user):
    '''
    
    '''
    tutor_group, owner_group = _get_user_groups()
    user.is_staff = True
    user.is_superuser = True
    user.save()
    owner_group.user_set.add(user)
    owner_group.save()
    tutor_group.user_set.add(user)
    tutor_group.save()
683735
def create_role(*_, **kwargs):
    
    click.echo(green('\nCreating new role:'))
    click.echo(green('-' * 40))

    with get_app().app_context():
        role = Role(**kwargs)
        result = role_service.save(role)
        if not isinstance(result, Role):
            print_validation_errors(result)

        click.echo(green('Created: ') + str(role) + '\n')
945554
def add_role_to_user(self, role, user):
        
        uri = "users/%s/roles/OS-KSADM/%s" % (utils.get_id(user),
                utils.get_id(role))
        resp, resp_body = self.method_put(uri)
193578
def _role_update(name,
                 user=None,
                 host=None,
                 port=None,
                 maintenance_db=None,
                 password=None,
                 createdb=None,
                 typ_='role',
                 createroles=None,
                 inherit=None,
                 login=None,
                 connlimit=None,
                 encrypted=None,
                 superuser=None,
                 replication=None,
                 rolepassword=None,
                 valid_until=None,
                 groups=None,
                 runas=None):
    '''
    
    '''
    role = role_get(name,
                    user=user,
                    host=host,
                    port=port,
                    maintenance_db=maintenance_db,
                    password=password,
                    runas=runas,
                    return_password=False)

    # check if user exists
    if not bool(role):
        log.info(
            '%s \'%s\' could not be found', typ_.capitalize(), name
        )
        return False

    sub_cmd = 'ALTER ROLE "{0}" WITH'.format(name)
    sub_cmd = '{0} {1}'.format(sub_cmd, _role_cmd_args(
        name,
        encrypted=encrypted,
        login=login,
        connlimit=connlimit,
        inherit=inherit,
        createdb=createdb,
        createroles=createroles,
        superuser=superuser,
        groups=groups,
        replication=replication,
        rolepassword=rolepassword,
        valid_until=valid_until,
        db_role=role
    ))
    ret = _psql_prepare_and_run(['-c', sub_cmd],
                                runas=runas, host=host, user=user, port=port,
                                maintenance_db=maintenance_db,
                                password=password)

    return ret['retcode'] == 0
1189632
def add_role role
      raise ArgumentError, '#add_role takes a single role String or Symbol as the argument' if !role || role.kind_of?(Array)
      add_roles role
    end
811631
public function Add() {
		if(!$this->_Permission())
			return;

      $this->Title(T('Add Role'));

      // Use the edit form with no roleid specified.
      $this->View = 'Edit';
      $this->Edit();
   }
890171
public ServerUpdater addRolesToUser(User user, Collection<Role> roles) {
        delegate.addRolesToUser(user, roles);
        return this;
    }
504555
def _create_user(self, username, password, mail, method, uuid):
        """"""

        try:
            if method == 'Invited':
                config_role = self.config.group_accept_invited
            else:
                config_role = self.config.group_accept_enrolled

            roles = []
            if ',' in config_role:
                for item in config_role.split(','):
                    roles.append(item.lstrip().rstrip())
            else:
                roles = [config_role]

            newuser = objectmodels['user']({
                'name': username,
                'passhash': std_hash(password, self.salt),
                'mail': mail,
                'uuid': std_uuid(),
                'roles': roles,
                'created': std_now()
            })

            if method == 'Invited':
                newuser.needs_password_change = True

            newuser.save()
        except Exception as e:
            self.log("Problem creating new user: ", type(e), e,
                     lvl=error)
            return

        try:
            newprofile = objectmodels['profile']({
                'uuid': std_uuid(),
                'owner': newuser.uuid
            })
            self.log("New profile uuid: ", newprofile.uuid,
                     lvl=verbose)

            newprofile.save()

            packet = {
                'component': 'hfos.enrol.enrolmanager',
                'action': 'enrol',
                'data': [True, mail]
            }
            self.fireEvent(send(uuid, packet))

            # TODO: Notify crew-admins
        except Exception as e:
            self.log("Problem creating new profile: ", type(e),
                     e, lvl=error)
813878
protected function updateRoles()
    {
        foreach ($this->roles() as $Role) {
            $this->authManager->add($Role);

            echo sprintf('    > role `%s` added.', $Role->name) . PHP_EOL;
        }
    }
1038169
public Result<Void> addUserRole(AuthzTrans trans,UserRoleDAO.Data urData) {
		Result<Void> rv;
		if(Question.ADMIN.equals(urData.rname)) {
			rv = mayAddAdmin(trans, urData.ns, urData.user);
		} else if(Question.OWNER.equals(urData.rname)) {
			rv = mayAddOwner(trans, urData.ns, urData.user);
		} else {
			rv = checkValidID(trans, new Date(), urData.user);
		}
		if(rv.notOK()) {
			return rv; 
		}
		
		// Check if record exists
		if (q.userRoleDAO.read(trans, urData).isOKhasData()) {
			return Result.err(Status.ERR_ConflictAlreadyExists,
					"User Role exists");
		}
		if (q.roleDAO.read(trans, urData.ns, urData.rname).notOKorIsEmpty()) {
			return Result.err(Status.ERR_RoleNotFound,
					"Role [%s.%s] does not exist", urData.ns, urData.rname);
		}

		urData.expires = trans.org().expiration(null, Expiration.UserInRole, urData.user).getTime();
		
		
		Result<UserRoleDAO.Data> udr = q.userRoleDAO.create(trans, urData);
		switch (udr.status) {
		case OK:
			return Result.ok();
		default:
			return Result.err(udr);
		}
	}
1221443
private static function registerRolesAdmin()
    {
        if (!Gate::allows('roles_read')) {
            return;
        }

        Agencms::registerRoute(
            Route::init('roles', ['Users' => 'Manage Roles'], '/agencms-auth/roles')
                ->icon('supervisor_account')
                ->addGroup(Group::full('Details')->addField(
                    Field::number('id', 'Id')->readonly()->list(),
                    Field::string('name', 'Name')->link('slug')->medium()->required()->list(),
                    Field::string('slug', 'Slug')->slug()->medium()->required()->list(),
                    Field::select('permissions', 'Permissions')->addOptions(
                        Policy::all()
                    )->medium()->multiple()->dropdown()
                ))
        );
    }
247777
def create_db(self):
        
        self.add_role(self.auth_role_admin)
        self.add_role(self.auth_role_public)
        if self.count_users() == 0:
            log.warning(LOGMSG_WAR_SEC_NO_USER)
1200014
def add_role_to_user(self, user, role):
        
        user.add_role(role)
        self.save(user)
        events.user_got_role_event.send(user, role=role)
285362
public function add() {
        $role = $this->Roles->newEntity();
        if ($this->request->is('post')) {
            $role = $this->Roles->patchEntity($role, $this->request->data);
            if ($this->Roles->save($role)) {
                $this->Flash->success(__('The role has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The role could not be saved. Please, try again.'));
            }
        }
        $this->set(compact('role'));
        $this->set('_serialize', ['role']);
        $this->filteredSelectOptions();
    }
400190
public function newRole(Role $request)
    {

        $role = $this->addRole($request->input('title'));

        return redirect()
            ->route('configuration.access.roles.edit', ['id' => $role->id])
            ->with('success', trans('web::seat.role_added'));
    }
297887
def role= role
      raise ArgumentError, '#add_role takes a single role String or Symbol as the argument' if !role || role.kind_of?(Array)
      self.roles = role
    end