-
Notifications
You must be signed in to change notification settings - Fork 7
DISPLAY-986: Updated add user command to ask which tenants user belongs to #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DISPLAY-986: Updated add user command to ask which tenants user belongs to #154
Conversation
| ->addArgument('role', InputArgument::OPTIONAL, 'The role of the user [editor|admin]') | ||
| ->addArgument('tenant-keys', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'The keys of the tenants the user should belong to (separate multiple keys with a space)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use options for this (rather than arguments) to make it easier to handle multiple values, e.g.
app:user:add … --role=admin --tenant=hat --tenant=brillerbut that's a matter of opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally my preference as well. This was originally adapted from https://github.com/symfony/demo/blob/main/src/Command/AddUserCommand.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And that example uses an option, --admin, for (implicitly) setting the role. This is not really important, so let's leave it as it is for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed 😄
Changed because
- there might be more than 2 roles at some point,
- none of the people who has had to use the command have figured out the
--adminoption. So tried to make it more obvious how to select role
| $this->io->text(' > <info>Tenant Keys</info>: '.$tenantKeys); | ||
| } else { | ||
| $question = new ChoiceQuestion( | ||
| 'Please select the tenant(s) the user should belong to (to select multiple answer with a list. E.g: "key1, key3")', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what “(to select multiple answer with a list. E.g: "key1, key3")” means. Doesn't the helper help the user picking multiple values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. You have to answer with a list of comma separated values. There is no "UI".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I thought the terminal presented a checkbox like user experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://symfony.com/doc/current/components/console/helpers/questionhelper.html#multiple-choices
use Symfony\Component\Console\Question\ChoiceQuestion;
// ...
public function execute(InputInterface $input, OutputInterface $output): int
{
// ...
$helper = $this->getHelper('question');
$question = new ChoiceQuestion(
'Please select your favorite colors (defaults to red and blue)',
['red', 'blue', 'yellow'],
'0,1'
);
$question->setMultiselect(true);
$colors = $helper->ask($input, $output, $question);
$output->writeln('You have just selected: ' . implode(', ', $colors));
return Command::SUCCESS;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice implode(', ', $colors)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yes, before testing it I also expected a checkbox like feature
src/Utils/CommandInputValidator.php
Outdated
| throw new InvalidArgumentException('The role can not be empty.'); | ||
| } | ||
|
|
||
| $allowedRoles = ['editor', 'admin']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future-proofing you could set these roles in an environment variable. Or at least put the list into a class variable; it's also used in interact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to a class constant.
Originally I tried to get the values through DI and the one of the Security services. Didn't work as I wanted because it's a subset of the defined roles we allow here.
I don't like moving them to env because they would still have to match what is defined in security.yaml. Also I consider env values to be something you can configure. But Symfony's docs encourage you to do stuff like #[IsGranted('ROLE_ADMIN')] in code, so having the roles configurable would clash with that.
Link to ticket
https://jira.itkdev.dk/browse/SUPP0RT-1109
Description
Updated add user command to ask which tenants user belongs to
Screenshot of the result
If your change affects the user interface you should include a screenshot of the result with the pull request.
Checklist
If your code does not pass all the requirements on the checklist you have to add a comment explaining why this change
should be exempt from the list.
Additional comments or questions
If you have any further comments or questions for the reviewer please add them here.