Every complex system offers various usage patterns based on user needs and obligations. Based on such use cases we can identify specific roles. Moodle is no different in this respect. For example, we know for sure that we must have a person dedicated to maintaining the platform, monitoring, and fixing any issues that may arise at a time—that person should have the role of a general manager or in Moodle terminology, an administrator. Another example would be a user that is a course participant. His principal interest is to browse through all available learning materials and participate in any tasks set for him—this would be learner or student. Each and every role has a set of things that are permitted or prohibited. By assigning users to one of the predefined or custom roles we are defining the spectrum of the options and actions available to them at every location within LMS. It is paramount for every administrator to fully understand access rights as they are implemented. Therefore, in this chapter we will focus on access rights to resources and functions within Moodle starting with:
The Moodle access rights system is based around the concepts of contexts, capabilities, permissions, and roles. Let us first define these terms in the context of Moodle.
A capability is a system defined feature or action. For example, view course would be one capability. All capabilities are defined either by Moodle core or by third-party module(s).
Context is an abstraction representing part of Moodle. We have six predefined contexts and they are arranged in a hierarchical fashion with permissions inherited from higher to lower contexts. Here is the list of existing contexts presented in order of importance from higher to lower:
Permission defines whether capability is enabled or not. Each capability can be given permission on a particular context. There are four permissions defined:
A Role answers to a question: what can the user do? and is also a predefined list of permissions applied to all capabilities within the system. With Role we can easily separate what one group of users can and cannot do in the specific part of the platform. It is important to say that any user can and usually will have more than one role applied on the same context. Moodle poses no limits in that area, but we still should be conservative in the way we assign and use roles.
Whenever a user wants to perform a specific action in some context, Moodle checks his permission level for it. This is done by reviewing all permissions from all roles that are assigned to that user at that particular context. The result of that review produces computed permission as a sum of enabled, disabled, or not set values taking into account context precedence.
For example, a user logs into Moodle and wishes to enter into a course. Upon logon, every user is assigned the Authenticated user role (this is the default and recommended setting for most use cases but it can be modified). Whether a user can see a course or not is determined by a state of course_view capability for that user within a role he has in that course context. Moodle gets all roles for that user starting from the system level down to the course level. It can be presented with the following table:
User |
Context |
Role |
Capability |
Permission |
---|---|---|---|---|
Student1 |
System |
Authenticated user |
course_view |
not set |
User | ||||
Course category | ||||
Course 1 |
Student |
course_view |
allowed |
As you can see a user has no role whatsoever for some contexts which is normal in Moodle. We are showing them just for the sake of completeness.
In this simple case we have two instances of the course_view capability. One is not set while the other is set to allowed. The basic formula for calculating resulting permission can be described like this:
Start from the context of the resource we want to access, get user role(s) (if any) for it, and get permission value(s) for specific capability. If a user has more than one role defined in that context, permission values are summed in the resulting value. If any of the permissions has the value "prohibit" it finishes the check and denies access to the user, otherwise save current computed permission value and go to the parent context. If there is a parent context, repeat the process. Otherwise, return the computed permission. If the final permission value is bigger than or equal to 1, then the user is granted access.
18.221.165.115