When creating a user, it would be convenient to be able to send one of the standard system messages defined at /admin/user/settings.

I've attached a patch that does just that.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greg.1.anderson’s picture

Status: Needs review » Needs work

Good concept. I think that the main flag should be --notify to enable sending email. The --message flag should allow the specific message to be selected, but should default to register_admin_created, which is almost always what you are going to want.

Follow the convention return drush_set_error(....

It is odd to see the convention where if ($message_valid) { is TRUE when $message is FALSE. The logic reads better if you just abort out with a return drush_set_error(... on invalid messages as suggested above so that you do not need to predicate user_save on $message_valid.

greg.1.anderson’s picture

Oh, another thought: optional, but it might be nifty to have an option to allow the user to select which message to send via a drush_choice menu.

ergonlogic’s picture

Thanks for the feedback and suggestions. I agree the logic is awkward. Adding `--notify` might help.

As for `drush_choice`, this would be like how `drush cc` works?

This patch was motivated mainly due to laziness in an Aegir extension I'm writing (https://github.com/ergonlogic/hosting_saas). Any chance it gets backported to Drush 4?

jonhattan’s picture

user-login may also have a --notify-user option.

ergonlogic’s picture

Status: Needs work » Needs review
FileSize
3.55 KB

@jonhattan: not that I could see...

I implemented the changes above, including the drush_choice menu.

moshe weitzman’s picture

Status: Needs review » Needs work

remove various trailing whitespaces.

it looks odd to me to have both --notify and --message. it should be just one of those. if user provides no value, then we use a default. we can distinguish that from the option not being there at all (don't send any email).

the values of --message should use dashes instead of underscores. convert the supplied value to underscores in the code. this is the cli convention.

ergonlogic’s picture

Title: add --message option to user-create » add --notify option to user-create
Status: Needs work » Needs review
FileSize
3.26 KB

Hi moshe, thanks for taking a look. I've made the fixes & changes you suggested.

In so doing, I moved the 'drush_choice' menu into the message validation. This way, it's only presented if '--notify="some-invalid-message"'. My only concern here is that " [0] : Cancel" should really read more like " [0] : None", and "Cancelled" should be "No notification message will be sent". Not really a big deal, I guess, but I'll poke around a little in 'drush_choice to see if/how I can fix these.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

looks ok to me. anyone care to review?

greg.1.anderson’s picture

Status: Reviewed & tested by the community » Needs work

Code looks good to me, although I did not test.

Regarding drush_get_option, I think that cancel should always be an option when presented a choice, and it should actually cancel the operation if selected. If your option is screwed up and you get the choice prompt, you should have the option to say "that's not what I meant at all." (Hm, current patch does not cancel -- setting to 'needs work' for that minor addition.)

If you actually want to have "no message" as an option to the call to drush_choice, just add it to the end of the drush_choice options (or maybe add it to the beginning if you want it to always have the same number). I don't think that's necessary, but it would probably be a useful enhancement.

ergonlogic’s picture

Okay, implemented the changes and re-rolled the patch.

ergonlogic’s picture

Status: Needs work » Needs review

oops

crimsondryad’s picture

This would be really useful for us to automate creating a standard set of users across corporate sites without having to send them a second email. :)

moshe weitzman’s picture

Could someone please test this?

moshe weitzman’s picture

Status: Needs review » Needs work

Does not apply anymore.

joestewart’s picture

rerolled.

I applied the patch, ran the testUser test and it passed.

I then made this change to testUser.php:

-    $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => "example@example.com"));
+    $this->drush('user-create', array($name), $options + array('password' => 'password', 'mail' => "example@example.com", 'notify' => "register-pending-approval"));

And the test passed.

It might be my test environment, but I get an email sent to example@example.com with the status-activated email when the testUser test is run.

After applying this patch I also get another email that contains whatever the notify option is set.

Leaving at needs review.

joestewart’s picture

Status: Needs work » Needs review
moshe weitzman’s picture

Status: Needs review » Needs work

I would rather that tests not actually generate emails. Can we add a --simulate and check the logs that the email went out. Not perfect, but better than leaving cruft in a spool somewhere.

greg.1.anderson’s picture

#15 described a temporary measure done by hand to test the feature; there is no unit test code in the patch. #17 is probably the best way to create a test for this.

greg.1.anderson’s picture

Version: » 8.x-6.x-dev
Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.