jpahullo / moodle-tool_mergeusers

Merge users script for Moodle
https://moodle.org/plugins/view.php?plugin=tool_mergeusers
22 stars 52 forks source link

After having merge request from #218: allow to just update fields instead of proceed with a full merge #250

Open jpahullo opened 1 year ago

jpahullo commented 1 year ago

It comes from PR #248.


This is something it happens in our production environment, looking for usernames.

Imagine that on this Moodle instance, there exist the user to remove, but not the user to keep. This is a merging action very, very, very, very simple: in this example, assuming that we look for username, and only changes the username, since both users are related to the same person, the merging action is as simple as updating its username. For instance: $removeuserid = 12345, $removeuserfield = 'username', $removeuservalue = '4444444', so that this user exists. Instead, $keepuserfiel = 'username', $keepuservalue = '555555', matches no user. So, updating to username = '555555' for the given user.id = 12345 is all what we need to do.

We should consider this case, at least when the removeuserfield and keepuserfield is 'username'. Other fields like email or idnumber may be conflicting cases, maybe, I am not sure, but it is viable for usernames. We do this updating on our production system with a local hack, corresponding to a local cli merger that the plugin let's process merging operations.

First of all, the userfield should be the same, even though you can set a different removeuserfield from keepuserfield. So, in this case, both userfield should be username. And the value must be not empty. Apart from this, it is the responsability from the client side to ask "meaningfull" merge requests.

Maybe the same case could apply to idnumber too. I do not know about the email field.

When the keepuservalue (like the username of the user to keep) does not exists on Moodle mainly it is because the person under that new keepuservalue has not made any login yet on Moodle, so its user is not created yet. Just this.

In our case, we double check in our cli merger that the user to keep exists on LDAP, but not in Moodle yet. We could add a setting for that on the plugin: allow to check on LDAP if the user to keep exists. This would bring us more security that the simple update can be done directly without the need of a full merging operation.

I could work on the part of the LDAP if necessary. It could be a change to be added by me later on. Just to let us close this part as soon as possible during this week.


The idea is to:

  1. Let simply update the username field, for instance, if the user to remove exists, but the user to keep still does not exists on the system.
  2. Only proceed under certain scenarios, like that both fields are username or both are idnumbers, for instance.
  3. There could be a flag to let the plugin check if the user exists in LDAP, according to the credentials specified under auth/ldap. Only available if the plugin auth/ldap is activated and configured. Otherwise, this option cannot be activated.
  4. If there is some common API against auth plugins to check user existence, we could enable a setting per auth plugin enabled.
jpahullo commented 1 year ago

This can be a single issue or maybe splitted into two, one for updating the field, and another one to let admin add the condition to update it only if the user exists on the auth plugin specified.

nvallinoto commented 1 year ago

4: If there is some common API against auth plugins to check user existence, we could enable a setting per auth plugin enabled.

perhaps we can use Moodle API core_user_get_users_by_field