Manage default role assignments.

@since 2.0.?
@access public
167514
public function DefaultRoles() {
      $this->Permission('Garden.Settings.Manage');
      $this->AddSideMenu('');

      $this->Title(T('Default Roles'));

      // Load roles for dropdowns.
      $RoleModel = new RoleModel();
      $this->SetData('RoleData', $RoleModel->Get());

      if ($this->Form->AuthenticatedPostBack() === FALSE) {
         // Get a list of default member roles from the config.
         $DefaultRoles = C('Garden.Registration.DefaultRoles');
         $this->Form->SetValue('DefaultRoles', $DefaultRoles);

         // Get the guest roles.
         $GuestRolesData = $RoleModel->GetByUserID(0);
         $GuestRoles = ConsolidateArrayValuesByKey($GuestRolesData, 'RoleID');
         $this->Form->SetValue('GuestRoles', $GuestRoles);

         // The applicant role.
         $ApplicantRoleID = C('Garden.Registration.ApplicantRoleID', '');
         $this->Form->SetValue('ApplicantRoleID', $ApplicantRoleID);
      } else {
         $DefaultRoles = $this->Form->GetFormValue('DefaultRoles');
         $ApplicantRoleID = $this->Form->GetFormValue('ApplicantRoleID');
         SaveToConfig(array(
            'Garden.Registration.DefaultRoles' => $DefaultRoles,
            'Garden.Registration.ApplicantRoleID' => $ApplicantRoleID));

         $GuestRoles = $this->Form->GetFormValue('GuestRoles');
         $UserModel = new UserModel();
         $UserModel->SaveRoles(0, $GuestRoles, FALSE);

         $this->InformMessage(T("Saved"));
      }

      $this->Render();
   }
1244226
protected function set_choices() {
		$this->choices['controls'] = [];
		if ( is_array( $this->default ) ) {
			foreach ( $this->default as $key => $value ) {
				$this->choices['controls'][ $key ] = true;
			}
		}
	}
1284197
public static function assign_roles($assignments) {
        global $DB;

        // Do basic automatic PARAM checks on incoming data, using params description
        // If any problems are found then exceptions are thrown with helpful error messages
        $params = self::validate_parameters(self::assign_roles_parameters(), array('assignments'=>$assignments));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['assignments'] as $assignment) {
            // Ensure correct context level with a instance id or contextid is passed.
            $context = self::get_context_from_params($assignment);

            // Ensure the current user is allowed to run this function in the enrolment context.
            self::validate_context($context);
            require_capability('moodle/role:assign', $context);

            // throw an exception if user is not able to assign the role in this context
            $roles = get_assignable_roles($context, ROLENAME_SHORT);

            if (!array_key_exists($assignment['roleid'], $roles)) {
                throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']);
            }

            role_assign($assignment['roleid'], $assignment['userid'], $context->id);
        }

        $transaction->allow_commit();
    }
97205
function assignPermissions (done) {
  async.map(defaults.permissions, function (pair, callback) {
    Role.addScopes(pair[0], pair[1], function (err, result) {
      callback(err, result)
    })
  }, function (err, results) {
    done(err, results)
  })
}
386740
protected function setupDefaults()
    {
        $defaults = (isset($this->config['defaults'])) ?
            $this->config['defaults'] :
            [];

        foreach ($defaults as $key => $value) {
            if ($key == 'images') {
                if (empty($this->images)) {
                    $this->images = $value;
                }
            } elseif ($key == 'url' && $value === null) {
                $this->setUrl(app('url')->current());
            } elseif (! empty($value) && ! array_key_exists($key, $this->properties)) {
                $this->addProperty($key, $value);
            }
        }
    }
39922
public function addDefaultRoles(DefaultRole ...$roles)
    {
        foreach ($roles as $role) {
            $this->getDefaultRoles()->add($role);
        }

        return $this;
    }
588300
def assign_role(backend, user, response, *args, **kwargs):
    '''
    
    '''
    if backend.name is 'passthrough' and settings.DEMO is True and 'role' in kwargs['request'].session[passthrough.SESSION_VAR]:
        role = kwargs['request'].session[passthrough.SESSION_VAR]['role']
        if role == 'tutor':
            make_tutor(user)
        if role == 'admin':
            make_admin(user)
        if role == 'owner':
            make_owner(user)
324391
public function restore_role_assignment($instance, $roleid, $userid, $contextid) {
        if ($this->get_config('unenrolaction') == ENROL_EXT_REMOVED_UNENROL or $this->get_config('unenrolaction') == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
            // Role assignments were already synchronised in restore_instance(), we do not want any leftovers.
            return;
        }
        role_assign($roleid, $userid, $contextid, 'enrol_'.$this->get_name(), $instance->id);
    }
471696
private function setDefaultConfiguration(): void
    {
        $this->parameterBag->set('app.devmode', false);
        $this->parameterBag->set('container.dumper.inline_class_loader', true);

        $this->config->addPass($this->parameterBag);
    }
142940
def default_roles(*role_list):
    """"""
    def selectively_attach(func):
        """Only decorate if nothing specified on command line"""
        # pylint: disable=W0142
        if not env.roles and not env.hosts:
            return roles(*role_list)(func)
        else:
            if env.hosts:
                func = hosts(*env.hosts)(func)
            if env.roles:
                func = roles(*env.roles)(func)
            return func
    return selectively_attach
347254
protected function controlAccessAdmin()
    {
        if ($this->is_backend && !$this->isSuperadmin()) {

            if (empty($this->current_user['role_status']) || !$this->access('admin')) {
                $this->redirect('/', $this->text('No access'), 'warning');
            }

            if (isset($this->current_route['access']) && !$this->access($this->current_route['access'])) {
                $this->setHttpStatus(403);
            }
        }
    }
407444
def sync_role_definitions(self):
        """"""
        from superset import conf
        logging.info('Syncing role definition')

        self.create_custom_permissions()

        # Creating default roles
        self.set_role('Admin', self.is_admin_pvm)
        self.set_role('Alpha', self.is_alpha_pvm)
        self.set_role('Gamma', self.is_gamma_pvm)
        self.set_role('granter', self.is_granter_pvm)
        self.set_role('sql_lab', self.is_sql_lab_pvm)

        if conf.get('PUBLIC_ROLE_LIKE_GAMMA', False):
            self.set_role('Public', self.is_gamma_pvm)

        self.create_missing_perms()

        # commit role and view menu updates
        self.get_session.commit()
        self.clean_perms()
1360894
public function setDefaultRole($defaultRole)
    {
        if (! ($defaultRole instanceof RoleInterface || is_string($defaultRole))) {
            throw InvalidRoleException::invalidRoleInstance($defaultRole);
        }

        $this->defaultRole = $defaultRole;
    }
834308
protected function setRoleConfig() {
    if (strlen($this->getConfig()) == 0) {
      // check added nodes for Role instances
      foreach ($this->getAddedNodes() as $relationName => $nodes) {
        foreach ($nodes as $node) {
          if ($node instanceof Role) {
            $roleName = $node->getName();
            $roleConfigs = self::getRoleConfigs();
            if (isset($roleConfigs[$roleName])) {
              $this->setConfig($roleConfigs[$roleName]);
              break;
            }
          }
        }
      }
    }
  }
1017555
protected function addAssignmentsToSu() : void
    {
        $roleSu = $this->authManager->getRole(Rbac::R_SU);
        $this->addRolesToSU($roleSu);
        $this->addPermissionsToSU($roleSu);
    }
870946
public function assignTasksRoles(array $roles)
    {
        foreach ($roles as $roles => $tasks) {
            $tasks = (array) $tasks;
            $roles = (array) $roles;

            foreach ($tasks as $task) {
                $this->builder->buildTask($task)->addRoles($roles);
            }
        }
    }
508994
protected function registerRoleEloquent(): void
    {
        $this->app->bind('orchestra.role', function () {
            $model = $this->getConfig('models.role', Role::class);

            return new $model();
        });
    }