Skip to content
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

Enable adding E-Mail addresses to new user accounts using the CLI #29368

Closed

Conversation

philipreinken
Copy link
Contributor

Hi there 👋 With this PR I'm trying to address issue #25319 .

Quick manual testing & unit tests were successful so far.
It seems like the commands are instantiated without using the DIC, so I fetched the arguments needed from \OC::$server like it's done for some of the other commands, I hope I didn't miss something here.

@philipreinken philipreinken force-pushed the issue-25319/dev branch 2 times, most recently from 3e87c16 to b557ea6 Compare November 1, 2021 07:22
core/Command/User/Add.php Outdated Show resolved Hide resolved
@Pytal Pytal requested review from a team, PVince81, ArtificialOwl and come-nc and removed request for a team November 4, 2021 16:50
@Pytal Pytal added this to the Nextcloud 24 milestone Nov 4, 2021
core/Command/User/Add.php Outdated Show resolved Hide resolved
core/Command/User/Add.php Outdated Show resolved Hide resolved
core/Command/User/Add.php Outdated Show resolved Hide resolved
Signed-off-by: Philip Gatzka <philip.gatzka@mailbox.org>
@@ -118,17 +180,32 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

if (trim($password) === '' && $emailIsSet) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not trim here, I think it will cause weird edge cases when $password is all spaces.
Below you use $password ?: $temporaryPassword, which will evaluate to $password if it is not empty and full of spaces.

);
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$uid = $input->getArgument('uid');
$emailIsSet = \is_string($input->getOption('email')) && \mb_strlen($input->getOption('email')) > 0;
$emailIsValid = $this->emailValidator->isValid($input->getOption('email') ?? '', new RFCValidation());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If an invalid email is passed, it should abort with an error right there, it should not continue and do something else that what the caller asked for.

$user->setSystemEMailAddress($input->getOption('email'));
$output->writeln(sprintf('E-Mail set to "%s"', (string) $user->getSystemEMailAddress()));

if (trim($password) === '' && $this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing with trimming, here you can use isset($temporaryPassword) I think.

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all this feels like duplicating code from UserController. I would feel better if it called the same code.

@CarlSchwan
Copy link
Member

The code should probably be abstracted inside a Service that is called by both the occ command and controller. This will ensure that it stays the same and doesn't diverge, as well as make it easier to unit test.

@philipreinken
Copy link
Contributor Author

That's definitely a more maintainable approach than the one I went with 👍 I'd be happy to try and refactor this accordingly in case there are no plans/PRs to do this already.

@come-nc
Copy link
Contributor

come-nc commented Feb 22, 2022

That's definitely a more maintainable approach than the one I went with +1 I'd be happy to try and refactor this accordingly in case there are no plans/PRs to do this already.

No one is working on it I think, so you can start a PR on this. 👍

@skjnldsv skjnldsv mentioned this pull request Mar 24, 2022
@blizzz blizzz mentioned this pull request Mar 31, 2022
@blizzz blizzz mentioned this pull request Apr 7, 2022
@blizzz blizzz mentioned this pull request Apr 13, 2022
@blizzz blizzz modified the milestones: Nextcloud 24, Nextcloud 25 Apr 21, 2022
This was referenced Aug 12, 2022
@blizzz blizzz mentioned this pull request Aug 24, 2022
@bitbonk
Copy link

bitbonk commented Aug 25, 2022

We ran into the same issue describe here.
Will this PR solve that problem and if so, will this be in version 25?

@philipreinken
Copy link
Contributor Author

I'm sorry it took so long for me to revisit this PR. I don't think I'll be able to finish the work on this in the near future. In case anyone wants to build on the changes done here, please feel free to do so.

@mglaubitz
Copy link

Hi there, I have stumbled upon this conversation and I would really appreciate having the possibility to add user account with occ using an --email option.

Is anybody working on this?

@gonzalo
Copy link

gonzalo commented May 5, 2023

also interested on this feature as in our organization we create users massively from command line

kyteinsky added a commit that referenced this pull request Sep 30, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Sep 30, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Sep 30, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Sep 30, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Sep 30, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Sep 30, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Sep 30, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Oct 2, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Oct 4, 2023
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Feb 23, 2024
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
kyteinsky added a commit that referenced this pull request Feb 23, 2024
Signed-off-by: Anupam Kumar <kyteinsky@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants