Moodle

get_admin function doesn't return superuser admin account

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Not a bug
  • Affects Version/s: 1.7
  • Fix Version/s: 1.7
  • Component/s: Administration
  • Labels:
    None
  • Environment:
    linux
  • Database:
    PostgreSQL
  • Affected Branches:
    MOODLE_17_STABLE
  • Fixed Branches:
    MOODLE_17_STABLE

Description

the get_admin function returns the first of the admin users identified by the get_admins() function, which orders based on ra.id. Oddly this ordering seems to be character rather than integer ordering, because user id 16 is coming first instead of user id 3.

This means that any site admin user might be used to, for example, send the account sign-up email to, rather than the super user account - which would be the lowest numerical id. It looks a bit odd this way - I expected get_admin to give me the superuser account.

Issue Links

Activity

Hide
Martin Dougiamas added a comment -

Hmm, this works fine for me (MySQL) as it should. The sort is fairly straightforward.

Can you check on your Postgres database and make sure that the ra.id field is an integer field?

Show
Martin Dougiamas added a comment - Hmm, this works fine for me (MySQL) as it should. The sort is fairly straightforward. Can you check on your Postgres database and make sure that the ra.id field is an integer field?
Hide
Jenny Gray added a comment -

Yes, it is an integer. Here is the create statement from PGAdmin

CREATE TABLE mdl_role_assignments
(
id int4 NOT NULL DEFAULT nextval('mdl_role_assignments_id_seq'::regclass),
roleid int4 NOT NULL DEFAULT 0,
contextid int4 NOT NULL DEFAULT 0,
userid int4 NOT NULL DEFAULT 0,
hidden int4 NOT NULL DEFAULT 0,
timestart int4 NOT NULL DEFAULT 0,
timeend int4 NOT NULL DEFAULT 0,
timemodified int4 NOT NULL DEFAULT 0,
modifierid int4 NOT NULL DEFAULT 0,
enrol varchar(20) NOT NULL DEFAULT ''::character varying,
sortorder int4 NOT NULL DEFAULT 0,
CONSTRAINT mdl_role_assignments_pkey PRIMARY KEY (id)
)

Oddly I've just realised if I run the following query "select * from mdl_role_assignments where roleid=1 order by userid" in the database directly it returns as I would expect with userid=3 first.

Show
Jenny Gray added a comment - Yes, it is an integer. Here is the create statement from PGAdmin CREATE TABLE mdl_role_assignments ( id int4 NOT NULL DEFAULT nextval('mdl_role_assignments_id_seq'::regclass), roleid int4 NOT NULL DEFAULT 0, contextid int4 NOT NULL DEFAULT 0, userid int4 NOT NULL DEFAULT 0, hidden int4 NOT NULL DEFAULT 0, timestart int4 NOT NULL DEFAULT 0, timeend int4 NOT NULL DEFAULT 0, timemodified int4 NOT NULL DEFAULT 0, modifierid int4 NOT NULL DEFAULT 0, enrol varchar(20) NOT NULL DEFAULT ''::character varying, sortorder int4 NOT NULL DEFAULT 0, CONSTRAINT mdl_role_assignments_pkey PRIMARY KEY (id) ) Oddly I've just realised if I run the following query "select * from mdl_role_assignments where roleid=1 order by userid" in the database directly it returns as I would expect with userid=3 first.
Hide
Petr Škoda (skodak) added a comment -

This is most probably not a bug, because now the superadmin is the first admin that was assigned the admin role - ra.id is not user id, but ID in role_assignment table.

If you need to change primary admin:
1/ assign the Administrator role to secondary admin
2/ unassign your own admin role
3/ use the new admin to reassign the admin role to you

you are now secondary admin

I have reviewed the upgrade script too, it should keep the primary admin primary after the roles installation.

Show
Petr Škoda (skodak) added a comment - This is most probably not a bug, because now the superadmin is the first admin that was assigned the admin role - ra.id is not user id, but ID in role_assignment table. If you need to change primary admin: 1/ assign the Administrator role to secondary admin 2/ unassign your own admin role 3/ use the new admin to reassign the admin role to you you are now secondary admin I have reviewed the upgrade script too, it should keep the primary admin primary after the roles installation.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: