Show the form for entering the project role.

@param string                                          $defaultRole
@param \Symfony\Component\Console\Input\InputInterface $input

@return string
335738
private function showProjectRoleForm($defaultRole, InputInterface $input)
    {
        /** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
        $questionHelper = $this->getService('question_helper');

        $this->stdErr->writeln("The user's project role can be " . $this->describeRoles(ProjectAccess::$roles) . '.');
        $this->stdErr->writeln('');
        $question = new Question(
            sprintf('Project role (default: %s) <question>%s</question>: ', $defaultRole, $this->describeRoleInput(ProjectAccess::$roles)),
            $defaultRole
        );
        $question->setValidator(function ($answer) {
            return $this->validateProjectRole($answer);
        });
        $question->setMaxAttempts(5);
        $question->setAutocompleterValues(ProjectAccess::$roles);

        return $questionHelper->ask($input, $this->stdErr, $question);
    }
39922
public function addDefaultRoles(DefaultRole ...$roles)
    {
        foreach ($roles as $role) {
            $this->getDefaultRoles()->add($role);
        }

        return $this;
    }
949461
public function findNotInRole(RoleInterface $role)
    {
        return array_filter(
            $this->findAll(),
            function ($user) use ($role) {
                return $user->not($role->key);
            }
        );
    }
1069359
public function createPlatformRoleModalFormAction()
    {
        $form = $form = $this->formFactory->create(FormFactory::TYPE_ROLE_TRANSLATION);

        return array('form' => $form->createView());
    }
170115
public function findRole($projectId, $roleId)
    {
        return $this->apiClient->callEndpoint(sprintf('%s/%s/role/%s', self::ENDPOINT, $projectId, $roleId));
    }
498921
public static function applyDefaultUserAppRole($user, $defaultRole)
    {
        $apps = App::all();

        if (count($apps) === 0) {
            return false;
        }

        foreach ($apps as $app) {
            if (!UserAppRole::whereUserId($user->id)->whereAppId($app->id)->exists()) {
                $userAppRoleData = [
                    'user_id' => $user->id,
                    'app_id'  => $app->id,
                    'role_id' => $defaultRole
                ];

                UserAppRole::create($userAppRoleData);
            }
        }

        return true;
    }
986661
protected function buildRolesTree(RoleManagerInterface $role_manager)
    {
        $hierarchy = [];
        $roles = $role_manager->getRoles();
        foreach ($roles as $role) {
            if ($role instanceof RoleInterface) {
                if ($role->getParent()) {
                    if (!isset($hierarchy[$role->getParent()->getName()])) {
                        $hierarchy[$role->getParent()->getName()] = [];
                    }
                    $hierarchy[$role->getParent()->getName()][] = $role->getName();
                } else {
                    if (!isset($hierarchy[$role->getName()])) {
                        $hierarchy[$role->getName()] = [];
                    }
                }
            }
        }

        return $hierarchy;
    }
44955
public function input($key = null, $default = null)
    {
        return $this->getParameter($key, $this->getPayloadData($key, $default));
    }
1355562
public function loadRoleDraftByRoleId($roleId)
    {
        try {
            return $this->innerGateway->loadRoleDraftByRoleId($roleId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
82258
public function bootstrapRoleLabelFunction(UserInterface $user = null, array $roleColors = [], array $roleTrans = []) {

        if (null === $user) {
            return "";
        }

        $output = [];

        foreach ($user->getRoles() as $current) {

            $role = true === $current instanceof Role ? $current->getRole() : $current;

            $trans = $role;
            if (true === array_key_exists($role, $roleTrans)) {
                $trans = $this->getTranslator()->trans($roleTrans[$role]);
            }

            $label = $this->getLabelTwigExtension()->bootstrapLabelDefaultFunction(["content" => $trans]);
            if (true === array_key_exists($role, $roleColors)) {
                $label = $this->applyColor($label, $trans, $roleColors[$role]);
            }

            $output[] = $label;
        }

        return implode(" ", $output);
    }
819138
public function create($formType, InputInterface $input, array $options = [])
    {
        $options = $this->addDefaultOptions($options);

        $formBuilder = $this->formFactory->createBuilder(FormUtil::formTypeToString($formType), null, $options);

        foreach ($formBuilder as $name => $childBuilder) {
            /* @var FormBuilderInterface $childBuilder */
            if (!$input->hasOption($name)) {
                continue;
            }

            $providedValue = $input->getOption($name);
            if ($providedValue === null) {
                continue;
            }

            $childBuilder->setData($providedValue);
        }

        return $formBuilder->getForm();
    }
1080800
public function userHasRole($roleName, DeterminableUserInterface $user)
    {
        $userHasRole = false;
        if (true === in_array($roleName, $user->getRoles())) {
            $userHasRole = true;
        }
        return $userHasRole;
    }
1344788
public function grantRoleAccess(RoleInterface $role, ResourceInterface $resource, string $action)
    {
        $resourcePermissions = $this->getGroupPermissions($resource);
        $matchedPermission = null;

        //
        // 1. Check to see if the role, or its parents already have access.  Don't pollute the database.
        //
        $examinedRole = $role;
        while ($examinedRole) {
            foreach ($resourcePermissions as $permission) {
                if ($role === $permission->getRole()) {
                    $matchedPermission = $permission;
                }

                if ($permission->can($action)) {
                    throw new ExistingAccessException($role, $resource, $action, $permission->getRole()->getName());
                }
            }
            $examinedRole = $examinedRole->getParent();
        }

        //
        // 2. Give access
        //
        if (!$matchedPermission) {
            $newPermission = $this->groupPermissions->create($role, $resource->getClass(), $resource->getId(), [$action]);
            $this->groupPermissions->save($newPermission);
        } else {
            $matchedPermission->addAction($action);
            $this->groupPermissions->update($matchedPermission);

        }
    }
1053375
private function getLinkRoleDescription( $role, $roleType, $roleTitle )
	{
		$href = parse_url( $role['href'] );
		$basename = basename( $href['path'] );
		$roleTypes = $this->getRoleTypes( $role['href'] );
		if ( $roleTypes === false )
		{
			$this->log()->warning( "A role type cannot be found for '$basename'" );
			return false;
		}

		if ( ! isset( $roleTypes[ $roleType ] ) )
		{
			$this->log()->warning( "The role type corresponding to href '$basename' does not include one used on a $roleTitle.'" );
			return false;
		}

		$linkRoleType = $roleTypes[ $roleType ];
		if ( ! isset( $linkRoleType[ $role['roleUri'] ] ) )
		{
			$fragment = isset( $href['fragment'] ) ? $href['fragment'] : "";
			$this->log()->warning( "The $roleTitle of the role type corresponding to href '$basename' does not include an Id with fragment '$fragment'." );
			return false;
		}

		$link = $linkRoleType[ $role['roleUri'] ];
		return isset( $link['definition'] ) ? trim( $link['definition'] ) : $role['roleUri'];
	}
988244
public function getRoleService()
    {
        if (null === $this->roleService) {
            $this->roleService = new RoleService(
                $this->getUserService(),
                $this->client,
                $this->inputDispatcher,
                $this->outputVisitor,
                $this->requestParser
            );
        }

        return $this->roleService;
    }
1149482
protected function getProgressBar(InputInterface $input)
    {
        $progress = parent::getProgressBar($input);
        if (!$progress) {
            return null;
        }

        /** @var Dispatcher $eventDispatcher */
        $eventDispatcher = $this->getService('event_dispatcher');
        $eventDispatcher->addListener(
            'transformer.transformation.post',
            function () use ($progress) {
                $progress->advance();
            }
        );

        return $progress;
    }
737451
public function editRole()
	{
        $this->defaultData();

		$clazz = $this->getCurrentClass();
		$role = $this->getCurrentInstance();

		$formContainer = new tao_actions_form_Role($clazz, $role);
		$myForm = $formContainer->getForm();
		if($myForm->isSubmited()){
			if($myForm->isValid()){

				$formValues = $myForm->getValues();
				$roleService = tao_models_classes_RoleService::singleton();
				$includedRolesProperty = $this->getProperty(GenerisRdf::PROPERTY_ROLE_INCLUDESROLE);

				// We have to make the difference between the old list
				// of included roles and the new ones.
				$oldIncludedRolesUris = $role->getPropertyValues($includedRolesProperty);
				$newIncludedRolesUris = $formValues[GenerisRdf::PROPERTY_ROLE_INCLUDESROLE];
				$removeIncludedRolesUris = array_diff($oldIncludedRolesUris, $newIncludedRolesUris);
				$addIncludedRolesUris = array_diff($newIncludedRolesUris, $oldIncludedRolesUris);

				// Make the changes according to the detected differences.
				foreach ($removeIncludedRolesUris as $rU){
					$r = $this->getResource($rU);
					$roleService->unincludeRole($role, $r);
				}

				foreach ($addIncludedRolesUris as $aU){
					$r = $this->getResource($aU);
					$roleService->includeRole($role, $r);
				}

				// Let's deal with other properties the usual way.
				unset($formValues[$includedRolesProperty->getUri()]);

				$binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($role);
				$role = $binder->bind($myForm->getValues());

				core_kernel_users_Cache::removeIncludedRoles($role); // flush cache for this role.

				$this->setData('selectNode', tao_helpers_Uri::encode($role->getUri()));
				$this->setData('message', __('Role saved'));
				$this->setData('reload', true);
			}
		}

		$this->setData('uri', tao_helpers_Uri::encode($role->getUri()));
		$this->setData('classUri', tao_helpers_Uri::encode($clazz->getUri()));
		$this->setData('formTitle', 'Edit Role');
		$this->setData('myForm', $myForm->render());
		$this->setView('roles/form.tpl');
	}