cannod / moodle-drupalservices

Moodle plugin to connect to Drupal services
36 stars 25 forks source link

How to match Drupal and Moodle super admins? #45

Open VHlede opened 9 years ago

VHlede commented 9 years ago

Hi, How can I match Drupal and Moodle super admins? Below is the error I'm getting when I try to login to Moodle as Drupal super admin. It works fine with other accounts.

Debug info: Duplicate entry '1-admin' for key 'mdl_user_mneuse_uix'
INSERT INTO mdl_user (auth,mnethostid,lang,firstname,lastname,email,city,country,description,username,idnumber,confirmed,deleted,suspended) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)
[array (
0 => 'drupalservices',
1 => '1',
2 => '',
3 => 'Admin',
4 => 'Admin',
5 => 'Amin',
6 => 'Chicago',
7 => 'Us',
8 => '',
9 => 'admin',
10 => '1',
11 => 1,
12 => 0,
13 => 0,
)]
Error code: dmlwriteexception
-------------------------------------------------------------------------
Stack trace:
line 446 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 1164 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1210 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 209 of /auth/drupalservices/auth.php: call to mysqli_native_moodle_database->insert_record()
line 122 of /auth/drupalservices/auth.php: call to auth_plugin_drupalservices->create_update_user()
line 89 of /login/index.php: call to auth_plugin_drupalservices->loginpage_hook()

Thanks,

Vjeko

Cheesenbizkitz commented 9 years ago

This looks like it's happening because you've already got a user called "Admin" created in Moodle, and the auth plugin is try to recreate that user, but can't so it's giving a database error.

The easiest way to fix this would be to delete the admin user in Moodle, then log in to the Drupal site as the admin user and visit the Moodle site. That will create the user properly for use with the drupalservices auth plugin. I had to do this on my site when I had already created an admin user on Moodle that had the same username and password as the one on Drupal.

Just make sure you've got another account with admin privileges on Moodle so that you can add the "Admin" user back to the site administrators once it's been recreated.

There's probably another "proper" way to do this by syncing the accounts somehow, but the above works fine for me.

VHlede commented 9 years ago

Thanks a lot Cheesenbizkitz, It works fine now. I just change the username of the old admin to super-admin. Then a new user "admin" was created by drupalservices auth plugin. I added the admin role to that user. Works perfectly. The only challenge I have right now is that the new admin - although it can do all admin tasks, does not have access to admin links. "Site administration" links are missing. I tried with another theme, cleared cache... but again the menu is missing. I'm using Moodle 2.8. Any suggestion? Thanks, Vjeko

Cheesenbizkitz commented 9 years ago

Did you add the new admin into the list of site administrators under Site Administration -> Users -> Permissions -> Site administrators?

VHlede commented 9 years ago

Yes, I did it here: http://mymoodle.drupalsite.org/admin/roles/admins.php

With both accounts I can do whatever as admin I want - except as "admin" (account created with drupalservices sso) I can not see "Site administration" links. I even converted that account in the "Main Admin" (blue arrow) - but no changes. The images below illustrates what I can see with booth accounts. Please advise, Thanks! moodle-drupalservices-admin-menu

VHlede commented 9 years ago

Ou... this is a standard Moodle issue. It is described here under: https://docs.moodle.org/28/en/Blocks_FAQ >> My Administration block links don't expand!

I had the same issue in all browsers, but after doing what is described under 2) and 3) it works fine. Sometimes it may take a few seconds for the links to pop up. However, knowingly how many admin links (and permissions) Moodle has... that may be understandable.

Thanks Cheesenbizkitz!

netw3rker commented 9 years ago

I'm going to reopen this issue as a feature request. I think there should be an option upon setup that lets users correlate user:1 in drupal with user:2 in moodle (both are the super admins). Also there should be some kind of username-clash detection to prevent this specific problem.

You guys willing to do some testing on this? :)