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

dev/drupal#127 - require email for the Useradd task and errors not showing #17915

Merged
merged 1 commit into from
Aug 4, 2020

Conversation

demeritcowboy
Copy link
Contributor

@demeritcowboy demeritcowboy commented Jul 22, 2020

Overview

https://lab.civicrm.org/dev/drupal/-/issues/127

This is more noticeable on drupal 8 because in drupal 7 the CMS prevents it and outputs its own error message, but either way the "Create User Record" action when viewing a contact doesn't properly display or check for errors when creating the CMS user.

  1. Find a contact without an email.
  2. Choose Create User Record from the actions dropdown.
  3. Fill out the form.
  4. When you submit, what happens on drupal 8 is it goes back to contact view with no message a success message but the CMS user is not created.

Before

Missing or incorrect message. Also the actual cause of the error is not recorded or displayed anywhere.

After

Proper message and cause displayed.

Technical Details

Also to be in line with https://lab.civicrm.org/dev/drupal/-/issues/91 I made email required on the form to head off errors from that.

Comments

Has test.

@civibot
Copy link

civibot bot commented Jul 22, 2020

(Standard links)

@civibot civibot bot added the master label Jul 22, 2020
@@ -56,6 +56,9 @@ public function createUser(&$params, $mail) {
// Validate the user object
$violations = $account->validate();
if (count($violations)) {
foreach ($violations as $violation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@demeritcowboy do we need to do this on other CMSes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For drupal 7 no, because of the way it uses drupal's form layer to create a user, so the form errors display.

Let's take a look at what wordpress/joomla do...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok it took a minute to find but it looks like wordpress doesn't override checkPermissionAddUser() so it returns false so you don't even see this feature.

Ok now joomla...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Joomla UF class has pretty extensive checking as a form rule via checkUserNameEmailExists(), and it's beyond my joomla knowledge to know how to get past it to trigger a fail in joomla itself. The only thing I can see it doesn't check for is a blank email, which this PR would cover. But createUser itself doesn't have any kind of error checking, and in fact seems like it would never return FALSE either way, so technically createUser might need some sprucing up, but I'm not a joomla person.

@seamuslee001
Copy link
Contributor

@kcristiano @mattwire Thoughts on this? I think it seems fine to me from a Drupal 7/8 POV

@eileenmcnaughton
Copy link
Contributor

@kcristiano @christianwach @andrewpthompson thoughts?

@demeritcowboy
Copy link
Contributor Author

If it helps here's an updated table about what happens when you use the Create User Record action from the view contact summary for a contact who has no email.

CMS Before patch status After patch status
Drupal 7 Bit of a mixed state after #17914. It will show form errors from drupal, but now civi will at the same time happily show a success message no matter what happened. Correct messages from drupal and civi.
Drupal 8 Says success but it didn't succeed. Correct messages.
Wordpress CRM/Utils/System/Wordpress doesn't override checkPermissionAddUser() so it returns FALSE so the feature doesn't appear as an action. Same as before.
Joomla Don't have one to test on as an admin, but reading the code it would depend on what joomla does when email is blank. In any case civi would always show a success message unless joomla throws a fatal error. Email now required on the form, so should head off any issues there. The form rule validation looks like it will catch most other problems. In terms of other unexpected errors the createUser code never returns FALSE so again it would depend what joomla does.
Backdrop Same as drupal 7 Code seems identical to drupal 7.

@christianwach
Copy link
Member

@eileenmcnaughton WordPress would appear to be unaffected by this PR since the the feature doesn't appear as an action.

This can already be done in WordPress via:

  • CiviCRM WordPress Profile Sync which adds an item to the "Bulk Actions" menu allowing one or more Users to be created from Contacts. Requires the CIVICRM_WP_PROFILE_SYNC_BULK constant to be set for the feature to appear.
  • CiviCRM WordPress Member Sync which creates WordPress Users when a Membership is created and there's an association rule for that Member Type.
  • BP Groups CiviCRM Sync which creates a WordPress User for a Contact when a Group Membership is created and there's an associated BuddyPress Group.

Having said all that, IMO it would be nice to have this in core at some stage.

@eileenmcnaughton
Copy link
Contributor

I've tried to ping a few Joomla! people & also pasted on chat. Unfortunately Joomla! world is a bit quiet - I think at this stage I'm going to merge it - but @agh1 can you try to give some visibility to the fact this may change Joomla! behaviour in the release notes. I think it would be easy to fix if the change is considered regressive

@vingle pinging you as someone else with some Joomla! knowledge

@eileenmcnaughton eileenmcnaughton merged commit 0bdc815 into civicrm:master Aug 4, 2020
@eileenmcnaughton
Copy link
Contributor

Thanks for that analysis @christianwach

@andrewpthompson
Copy link
Contributor

I've only given this a quick test on Joomla, and only for the case of trying to create a CMS user with no email address. The patch works as intended.

For info, before the patch: Joomla user is not created. No error is displayed by Joomla. Civi show a success message.

I'm not particularly familiar with this part of Joomla/Civi interaction but it looks OK to me.

@eileenmcnaughton
Copy link
Contributor

Thanks @andrewpthompson - appreciate your feedback

@demeritcowboy
Copy link
Contributor Author

Thanks everybody.

@demeritcowboy demeritcowboy deleted the useradd-messages branch August 4, 2020 13:31
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.

5 participants