Disaster with roles

Disaster with roles

by Edward Gash -
Number of replies: 10

Hi all.  I have inadvertently changed my role from that of an administrator and am locked out of my site.  Please see this post.

Thank you

Average of ratings: -
In reply to Edward Gash

Re: Disaster with roles

by Thomas Robb -
If the system doesn't have a way of preventing the primary admin of a site from accidentally un-assigning that role from him/herself, then it is a programming/design problem that needs to be addressed.

What you can do, however, is to use phpMyAdmin and edit your permissions manually to restore it to what it should be. If you browse mdl_role_assignments, you will probably see userid 2 at the top. That's the primary admin of the site. (Userid 1 is for the "guest".) The roleid and contextid should both be set to "1".
In reply to Thomas Robb

Re: Disaster with roles

by Edward Gash -
Just bluffed my way to doing that.  Thanks for the message.  I agree that the system shouldn't really allow you to be as stupid as I was.  Cheers.
In reply to Edward Gash

Re: Disaster with roles

by Thomas Robb -
Martin D. has justed reported fixing this for version 1.7.1. Why he is working on a Sunday is anybody's guess. smile

See MDL-7462.
In reply to Thomas Robb

Re: Disaster with roles

by sol hanna -
Ouch! I just found this thread. Earlier in the day, the other admin on our moodle locked us both out. Just 30min ago I upgraded to 1.7.1. But I'm still locked out. sad

I followed the advice in this thread by using phpmyadmin to update `mdl_role_assignments` column so that "contextid = 1" and "roleid = 1" "where userid = 2" but mysql complains that there are duplicate rows. It's true that the row I want already exists, but somehow, subsequent entries have overridden the original permissions.

Is it okay to delete all the other rows except the one I want? Or is there another more graceful fix?

thanks; sol
In reply to sol hanna

Re: Disaster with roles

by Oswald Zangerle -
Hi
maybe Petr´s script would be useful for 1.7.1 too?

Oswald

In reply to Oswald Zangerle

Re: Disaster with roles

by sol hanna -
Thanks Oswald,

I did try Petr script. It didn't work, but I think you might be on to something. My admin username isn't 'admin', it's 'sol'. So I one line in Petr's script to:

$user = get_record('user','username','sol');

It didn't work, but when I logged in I got the message, "already user by that name" or something like that. Was my change correct?

cheers; sol
In reply to sol hanna

Re: Disaster with roles

by Oswald Zangerle -
Hi sol,
it´s just a guess that Petr´s script could work in 1.7.1 too. I am the primary admin of my site and admin seems to be a special user anyway. For me it worked fine with the original name "admin" but that´s my username. The script seems to gather information from config.php and therefore I guess it works for primary admins.
I don´t know if there is a difference between these tables in 1.7.1 and 1.8 Beta I am just the try and error learner at this time.
Anyway I would try the repair funcion in phpMyAdmin for your database even if it might not solve your permissions problem.

Some time ago I read (in moodle docs?, how to update? "administrator logged out" search term?) how to use the special guest account/ password? in your database to get back the admin role.
PS: Sorry Administration_FAQ#I_have_forgotten_the_admin_password
it´s about forgotten password...

But there is still hope someone with more insight will be of help!

Good luck!
Oswald

In reply to Oswald Zangerle

Re: Disaster with roles

by sol hanna -
Thanks for your help Oswald. I followed your links, but really they help with finding the password, and that much I know. Petr's script did kind of work. It added a row to mdle_role_assignments, but it just didn't seem to work it's mojo in 1.7.1. I really wish I knew which table/row to update to undo this admin lock. But as this was a test install (though my colleague was starting to use it in the classroom) I may just cut my losses. Will make sure that we use 1.7.1 in production next term.... ;)