Implementation Plan for Roles

DRAFT - 16th November 2004

Overview

This architecture allows for the creation of different roles that will have assignable capabilities. Each role is a list that basically says what that role is allowed to do. Admins can create site-wide roles beyond the existing standard roles, and "teachers" will also be able to create new roles within their own courses (though only roles with less power than they have). People can be assigned to one or more roles at the site level or the course level.

Requirements

Add database tables

1. 'role'

Field name Description Field Type
id unique record id int
name short name of role (no spaces) varchar
fullname full name of role text
description description of role text
timemodified timestamp int
sortorder   int
courseid id from course table int
userid id from user table - last modifier of role int

Notes:

<lang lang="en">dog</lang><lang lang="de">hund</lang><lang lang="ma">kuri</lang>

 

2. role_capabilities

Field name Description Field Type
id unique record id int
module name of the module (no spaces) varchar
capability name of capability (no spaces) varchar

Notes:

These functions will modify the 'role_capabilities' and 'role_allocations' tables

 

3. role_allocations

Field name Description Field Type
id unique record id int
roleid id from role table int
capabilitiesid id from role_capabilities table int

Notes:

 

4. role_users

Field name Description Field Type
id unique record id int
userid id from user table int
courseid id from courses table int
roleid id from role table int
timestart timestamp int
timeend timestamp int
timemodified timestamp int
assignerid id from user table - who assigned the role int

Notes:

 

Amend database tables

new field 'default_role' - this is what is given to people who self enrol.

 

Remove database tables

New Functions

function require_capability ( $module, $capability, $courseid) {
    global $USER;
    return ( isset ($USER->capabilities["{$module}_{$capability}"][$courseid]) or isadmin () );
}

The core function of the new system

If asked for a capability that doesn't exist then return false. This should never happen as the module code maintains both the 'role_capabilities' table and the calls to require_capability.

returns true if a user possesses all the capabilities of the given role, false otherwise

 

Amended Functions

 

Deprecated Functions

 

Other Changes

Capabilities in the $USER variable need to be 'AND'ed between the real user and the pseudo user. This is to avoid the real user attaining any extra capabilities while limiting their experience to the pseudo-users capabilities.

 

Structure

Global User Variable

Capabilities for a user will be initialised with the global $USER variable. The format will be as follows:

$USER->capabilities[ module_capability ][ course_id ]

where 'module_capability' is a concatenation of the respective fields in the 'role_capabilities' table.

 

Reserved role names

The role of teacheredit is for backward compatibility.

The user_admin table will remain and the role of admin will be tested against this table only. When testing a capability, the admin will always return true.

All users on the site will have the 'user' role. This will allow the admin to assign capabilities which apply to everyone on the site. For example, the 'edit own profile' capability in the moodle module. The courseid field will be set to 0 in the 'role' table. The 'timestart' and 'timeend' fields may be used to limit user access to the site.

 

Administration pages

Remove:

Add:

Short Name
Full Name
Description
Sortorder
Applies to
based on
Capabilities
 
Moodle
 
Create Courses
Edit other's profiles
Edit own profile
Edit Courses
Roles
 
Edit roles
Assign roles
Quiz
 
Create quizzes
Edit quizzes
View quiz statistics
Take quizzes
Forum
 
Create forums
Edit forums
View forums
Receive forum posts
Reply to posts
Start new discussions
...

When creating a role, a user can only assign capabilities they already possess. Capabilities they do not possess will be displayed but will be disabled.

The moodle module capabilities will only appear when editing site roles.

 

By Roles
By Users
 
Assign users to role(s)
select course: select role:
Assigned to ...
Not Assigned to ...

 

By Roles
By Users
 
Assign roles to user(s)
select course: select user:
Roles Assigned to ...
Potential Roles.

A user with the 'assign roles' capability can only assign roles to which they possess all capabilities. Other roles will be not be displayed. However a user with the 'assign roles' capability can remove roles for which they do not possess all the capabilities.

The courses available in the select box will be determined by which courses the user has the 'assign roles' capability. Only roles available to this course will be used (and also confined by the restriction above)

 

Other Notes

 

Appendix A: Core Modules and Capabilities