<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/test/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jisner</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/test/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jisner"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/Special:Contributions/Jisner"/>
	<updated>2026-08-10T17:58:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40277</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40277"/>
		<updated>2008-07-23T03:57:30Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Do roles have an inheritance relationsip? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Capability&lt;br /&gt;
:A configurable aspect of behavior.  As of version 1.9 Moodle has over 200 capabilities.   Each capability has a computer friendly name like [[Capabilities/mod/forum:rate|mod/forum:rate]] and a human-friendly name like &amp;quot;Rate posts.&amp;quot;&lt;br /&gt;
;Permission&lt;br /&gt;
:A capability and its value considered as a pair.  There are four possible values: &#039;&#039;Not set&#039;&#039; (known as &#039;&#039;Inherit&#039;&#039; in 1.7), &#039;&#039;Allow&#039;&#039;, &#039;&#039;Prevent&#039;&#039;, and &#039;&#039;Prohibit&#039;&#039;&lt;br /&gt;
;Role&lt;br /&gt;
:A named set of permissions, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Context&lt;br /&gt;
:A functional area of Moodle, such as a course, module or block&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, manual role assignments and overrides take effect immediately. However automatic role assignments that result from changes to certain user policies (for example, Default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the System context, so giving such permissions in the course context will have no effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; in all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Do roles have an inheritance relationship?==&lt;br /&gt;
&lt;br /&gt;
No. Roles are completely independent.&lt;br /&gt;
&lt;br /&gt;
* When you create a new role by copying an existing role, it is just like copying a file: the original and the copy are identical at the outset, but the copy has no ongoing relationship with the original.  Changes to the original do not affect the copy and &#039;&#039;vice versa&#039;&#039;.&lt;br /&gt;
* When you create a new role and select a value such as LEGACY:Student from the Legacy role type dropdown, you are not &amp;quot;inheriting&amp;quot; from the Student role.  You are simply indicating that you want your role to have the same defaults as Student.&lt;br /&gt;
* Course creator does not &amp;quot;inherit&amp;quot; from Teacher (a common misconception).  As with all roles, the two roles are completely independent.  Course creator is actually a very simple role that can basically only create courses and not much else.  However a user who creates a course is automatically assigned the role of Teacher in the newly-created course.  This is how a course creator gets her teaching abilities within a course.&lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40255</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40255"/>
		<updated>2008-07-22T16:48:54Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Do roles have an inheritance relationsip? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Capability&lt;br /&gt;
:A configurable aspect of behavior.  As of version 1.9 Moodle has over 200 capabilities.   Each capability has a computer friendly name like [[Capabilities/mod/forum:rate|mod/forum:rate]] and a human-friendly name like &amp;quot;Rate posts.&amp;quot;&lt;br /&gt;
;Permission&lt;br /&gt;
:A capability and its value considered as a pair.  There are four possible values: &#039;&#039;Not set&#039;&#039; (known as &#039;&#039;Inherit&#039;&#039; in 1.7), &#039;&#039;Allow&#039;&#039;, &#039;&#039;Prevent&#039;&#039;, and &#039;&#039;Prohibit&#039;&#039;&lt;br /&gt;
;Role&lt;br /&gt;
:A named set of permissions, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Context&lt;br /&gt;
:A functional area of Moodle, such as a course, module or block&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, manual role assignments and overrides take effect immediately. However automatic role assignments that result from changes to certain user policies (for example, Default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the System context, so giving such permissions in the course context will have no effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; in all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Do roles have an inheritance relationsip?==&lt;br /&gt;
&lt;br /&gt;
No. Roles are completely independent.&lt;br /&gt;
&lt;br /&gt;
* When you create a new role by copying an existing role, it is just like copying a file: the original and the copy are identical at the outset, but the copy has no ongoing relationship with the original.  Changes to the original do not affect the copy and &#039;&#039;vice versa&#039;&#039;.&lt;br /&gt;
* When you create a new role and select a value such as LEGACY:Student from the Legacy role type dropdown, you are not &amp;quot;inheriting&amp;quot; from the Student role.  You are simply indicating that you want your role to have the same defaults as Student.&lt;br /&gt;
* Course creator does not &amp;quot;inherit&amp;quot; from Teacher (a common misconception).  As with all roles, the two roles are completely independent.  Course creator is actually a very simple role that can basically only create courses and not much else.  However a user who creates a course is automatically assigned the role of Teacher in the newly-created course.  This is how a course creator gets her teaching abilities within a course.&lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40247</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40247"/>
		<updated>2008-07-22T16:43:41Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Capability&lt;br /&gt;
:A configurable aspect of behavior.  As of version 1.9 Moodle has over 200 capabilities.   Each capability has a computer friendly name like [[Capabilities/mod/forum:rate|mod/forum:rate]] and a human-friendly name like &amp;quot;Rate posts.&amp;quot;&lt;br /&gt;
;Permission&lt;br /&gt;
:A capability and its value considered as a pair.  There are four possible values: &#039;&#039;Not set&#039;&#039; (known as &#039;&#039;Inherit&#039;&#039; in 1.7), &#039;&#039;Allow&#039;&#039;, &#039;&#039;Prevent&#039;&#039;, and &#039;&#039;Prohibit&#039;&#039;&lt;br /&gt;
;Role&lt;br /&gt;
:A named set of permissions, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Context&lt;br /&gt;
:A functional area of Moodle, such as a course, module or block&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, manual role assignments and overrides take effect immediately. However automatic role assignments that result from changes to certain user policies (for example, Default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the System context, so giving such permissions in the course context will have no effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; in all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Do roles have an inheritance relationsip?==&lt;br /&gt;
&lt;br /&gt;
No. Roles are completely independent.&lt;br /&gt;
&lt;br /&gt;
* When you create a new role by copying an existing role, it is just like copying a file: the original and the copy are identical at the outset, but the copy has no ongoing relationship with the original.  Changes to the original do not affect the copy and &#039;&#039;vice versa&#039;&#039;.&lt;br /&gt;
* When you create a new role and select a value other such as LEGACY:Student from the Legacy role type dropdown, you are not &amp;quot;inheriting&amp;quot; from the Student role.  You are simply indicating that you want your role to have the same defaults as Student.&lt;br /&gt;
* Course creator does not &amp;quot;inherit&amp;quot; from Teacher (a common misconception).  As with all roles, the two roles are completely independent.  Course creator is actually a very simple role that can basically only create courses and not much else.  However a user who creates a course is automatically assigned the role of Teacher in the newly-created course.  This is how a course creator gets her teaching abilities within a course.&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40246</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40246"/>
		<updated>2008-07-22T16:22:51Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Why isn&amp;#039;t my role change taking effect? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Capability&lt;br /&gt;
:A configurable aspect of behavior.  As of version 1.9 Moodle has over 200 capabilities.   Each capability has a computer friendly name like [[Capabilities/mod/forum:rate|mod/forum:rate]] and a human-friendly name like &amp;quot;Rate posts.&amp;quot;&lt;br /&gt;
;Permission&lt;br /&gt;
:A capability and its value considered as a pair.  There are four possible values: &#039;&#039;Not set&#039;&#039; (known as &#039;&#039;Inherit&#039;&#039; in 1.7), &#039;&#039;Allow&#039;&#039;, &#039;&#039;Prevent&#039;&#039;, and &#039;&#039;Prohibit&#039;&#039;&lt;br /&gt;
;Role&lt;br /&gt;
:A named set of permissions, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Context&lt;br /&gt;
:A functional area of Moodle, such as a course, module or block&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, manual role assignments and overrides take effect immediately. However automatic role assignments that result from changes to certain user policies (for example, Default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the System context, so giving such permissions in the course context will have no effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; in all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40245</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40245"/>
		<updated>2008-07-22T16:19:29Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* What is the definition of a... */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Capability&lt;br /&gt;
:A configurable aspect of behavior.  As of version 1.9 Moodle has over 200 capabilities.   Each capability has a computer friendly name like [[Capabilities/mod/forum:rate|mod/forum:rate]] and a human-friendly name like &amp;quot;Rate posts.&amp;quot;&lt;br /&gt;
;Permission&lt;br /&gt;
:A capability and its value considered as a pair.  There are four possible values: &#039;&#039;Not set&#039;&#039; (known as &#039;&#039;Inherit&#039;&#039; in 1.7), &#039;&#039;Allow&#039;&#039;, &#039;&#039;Prevent&#039;&#039;, and &#039;&#039;Prohibit&#039;&#039;&lt;br /&gt;
;Role&lt;br /&gt;
:A named set of permissions, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Context&lt;br /&gt;
:A functional area of Moodle, such as a course, module or block&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; in all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40244</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40244"/>
		<updated>2008-07-22T16:16:00Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* What is the definition of a... */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Capability&lt;br /&gt;
:A configurable aspect of behavior, for example [[Capabilities/mod/forum:rate|mod/forum:rate]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A capability and its value considered as a pair.  There are four possible values: &#039;&#039;Not set&#039;&#039; (known as &#039;&#039;Inherit&#039;&#039; in 1.7), &#039;&#039;Allow&#039;&#039;, &#039;&#039;Prevent&#039;&#039;, and &#039;&#039;Prohibit&#039;&#039;&lt;br /&gt;
;Role&lt;br /&gt;
:A named set of permissions, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Context&lt;br /&gt;
:A functional area of Moodle, such as a course, module or block&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; in all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40193</id>
		<title>Enrolment FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40193"/>
		<updated>2008-07-22T01:11:37Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* How do I prevent users from enrolling themselves on courses? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
==How do I prevent students from enrolling themselves in a course?==&lt;br /&gt;
&lt;br /&gt;
Student-initiated enrollment (also known as [[Internal enrolment]]) is one of the standard enrollment methods supported by Moodle.  In fact, it is the only method that cannot be disabled sitewide by the administrator.  Fortunately, there are a few methods you can use to effectively prevent students from enrolling themselves in your course.&lt;br /&gt;
*Set &#039;&#039;Course enrollable&#039;&#039; to &#039;&#039;No&#039;&#039; in the course settings. This disables internal enrollment for your course. &lt;br /&gt;
*Set an [[Enrolment key|enrolment key]] in the course settings.  Students will only be able to enroll if they know the key.  Naturally, you will keep the key secret. &lt;br /&gt;
&lt;br /&gt;
Note that neither method prevents teachers from [[Enrolment#Manual enrolment|manually enrolling]] students (Course administration -&amp;gt; Assign roles).&lt;br /&gt;
&lt;br /&gt;
== Why are users being unenrolled for no apparent reason? ==&lt;br /&gt;
&lt;br /&gt;
Please check the following:&lt;br /&gt;
*The &#039;&#039;longtimenosee&#039;&#039; variable in &#039;&#039;Site Administration &amp;gt; Server &amp;gt; Cleanup&#039;&#039; (or Administration &amp;gt; Configuration &amp;gt; Variables in Moodle 1.6) which specifies the time limit for which, if students haven&#039;t logged in, they are unenrolled from courses.&lt;br /&gt;
*The &#039;&#039;Enrolment duration&#039;&#039; in the [[course/edit|Course settings]] which unenrols students after the specified time has elapsed.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for a full list of what controls unenrolment.)&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
If the default role for all users in &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to student rather than authenticated user (the default setting), this will result in all students being enrolled in all courses.&lt;br /&gt;
&lt;br /&gt;
Another possibility is that users are assigned the system role of student. Check &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and unassign users as necessary, then reassign them the role of student in the course context.&lt;br /&gt;
&lt;br /&gt;
==Why can&#039;t I select &amp;quot;External Database&amp;quot; from the enrolment plugins drop-down menu in the course settings?==&lt;br /&gt;
&lt;br /&gt;
Only &#039;&#039;interactive&#039;&#039; enrolment methods may be chosen in the course settings. Non-interactive enrolment plugins are set for the entire site in &#039;&#039;Site Administration&#039;&#039; &amp;gt; &#039;&#039;Enrolment&#039;&#039;. Please refer to the interactive enrolment section of [[Enrolment plugins]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable students to unenrol themselves from courses?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the student role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from not set to allow.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for instructions on how to enable students to unenrol themselves from a particular course.)&lt;br /&gt;
&lt;br /&gt;
==How do I prevent teachers from unenrolling themselves from their course by mistake?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the teacher role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from allow to not set.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
==How do I change the spelling of &amp;quot;enrol&amp;quot; to &amp;quot;enroll&amp;quot;?==&lt;br /&gt;
&lt;br /&gt;
Simply install the American English language pack (en_us) then choose it as the default language for the site. Or [[Language editing|edit your language]] settings.&lt;br /&gt;
&lt;br /&gt;
==Is there a way for teachers to be notified when students enrol in a course?==&lt;br /&gt;
&lt;br /&gt;
No notifications will be sent when students are allowed to enrol by the [[Internal enrolment]] process.  It can be done by changing the open source code, but not by through the interface. Other enrolment methods (for example [[Flat file]]) can allow emails when enrolment is complete but these are not student initiated.&lt;br /&gt;
&lt;br /&gt;
==When a student enrols using an enrolment key, they get a welcome e-mail message.  Can a teacher customise this at the course level?==&lt;br /&gt;
&lt;br /&gt;
Entering text for the message is described [[Email_processing#Email_confirmation_or_registration_words.2C_and_how_to_edit_them| Documentation here]].  But at the course level, not possible without a hack.&lt;br /&gt;
&lt;br /&gt;
==Where in the database is the relationship between user and course?==&lt;br /&gt;
&lt;br /&gt;
Prior to Moodle 1.7, enrollments were represented by two simple tables:  mdl_user_students and mdl_user_teachers.  Under the new Roles and Capabilities System introduced in Moodle 1.7, the concept of enrollment has been generalized.  The word &amp;quot;Enroll&amp;quot; should literally be read as &amp;quot;Assign a role to.&amp;quot;  To accomodate this flexibility, the database model has changed.  There is now a mdl_role_assignments table that holds the equivalent information.  For more information, see [[Development:Roles|the roles development documentation]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Enrolment]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40192</id>
		<title>Enrolment FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40192"/>
		<updated>2008-07-22T00:54:20Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
==How do I prevent users from enrolling themselves on courses?==&lt;br /&gt;
&lt;br /&gt;
There are several methods to prevent or restrict [[Internal enrolment]] by a student. &lt;br /&gt;
*Set an [[Enrolment key|enrolment key]] in the course settings, so whilst the student can automatically enrol, they will need the key to complete the process. &lt;br /&gt;
*Set &#039;&#039;Course enrollable&#039;&#039; to &#039;&#039;No&#039;&#039; in the course settings. This stops the internal enrolment (student initiated enrolment) process.&lt;br /&gt;
&lt;br /&gt;
Note that neither method will prevent [[Enrolment#Manual enrolment|manual enrolments]] or [[Enrolment plugins]] from working.&lt;br /&gt;
&lt;br /&gt;
== Why are users being unenrolled for no apparent reason? ==&lt;br /&gt;
&lt;br /&gt;
Please check the following:&lt;br /&gt;
*The &#039;&#039;longtimenosee&#039;&#039; variable in &#039;&#039;Site Administration &amp;gt; Server &amp;gt; Cleanup&#039;&#039; (or Administration &amp;gt; Configuration &amp;gt; Variables in Moodle 1.6) which specifies the time limit for which, if students haven&#039;t logged in, they are unenrolled from courses.&lt;br /&gt;
*The &#039;&#039;Enrolment duration&#039;&#039; in the [[course/edit|Course settings]] which unenrols students after the specified time has elapsed.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for a full list of what controls unenrolment.)&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
If the default role for all users in &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to student rather than authenticated user (the default setting), this will result in all students being enrolled in all courses.&lt;br /&gt;
&lt;br /&gt;
Another possibility is that users are assigned the system role of student. Check &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and unassign users as necessary, then reassign them the role of student in the course context.&lt;br /&gt;
&lt;br /&gt;
==Why can&#039;t I select &amp;quot;External Database&amp;quot; from the enrolment plugins drop-down menu in the course settings?==&lt;br /&gt;
&lt;br /&gt;
Only &#039;&#039;interactive&#039;&#039; enrolment methods may be chosen in the course settings. Non-interactive enrolment plugins are set for the entire site in &#039;&#039;Site Administration&#039;&#039; &amp;gt; &#039;&#039;Enrolment&#039;&#039;. Please refer to the interactive enrolment section of [[Enrolment plugins]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable students to unenrol themselves from courses?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the student role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from not set to allow.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for instructions on how to enable students to unenrol themselves from a particular course.)&lt;br /&gt;
&lt;br /&gt;
==How do I prevent teachers from unenrolling themselves from their course by mistake?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the teacher role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from allow to not set.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
==How do I change the spelling of &amp;quot;enrol&amp;quot; to &amp;quot;enroll&amp;quot;?==&lt;br /&gt;
&lt;br /&gt;
Simply install the American English language pack (en_us) then choose it as the default language for the site. Or [[Language editing|edit your language]] settings.&lt;br /&gt;
&lt;br /&gt;
==Is there a way for teachers to be notified when students enrol in a course?==&lt;br /&gt;
&lt;br /&gt;
No notifications will be sent when students are allowed to enrol by the [[Internal enrolment]] process.  It can be done by changing the open source code, but not by through the interface. Other enrolment methods (for example [[Flat file]]) can allow emails when enrolment is complete but these are not student initiated.&lt;br /&gt;
&lt;br /&gt;
==When a student enrols using an enrolment key, they get a welcome e-mail message.  Can a teacher customise this at the course level?==&lt;br /&gt;
&lt;br /&gt;
Entering text for the message is described [[Email_processing#Email_confirmation_or_registration_words.2C_and_how_to_edit_them| Documentation here]].  But at the course level, not possible without a hack.&lt;br /&gt;
&lt;br /&gt;
==Where in the database is the relationship between user and course?==&lt;br /&gt;
&lt;br /&gt;
Prior to Moodle 1.7, enrollments were represented by two simple tables:  mdl_user_students and mdl_user_teachers.  Under the new Roles and Capabilities System introduced in Moodle 1.7, the concept of enrollment has been generalized.  The word &amp;quot;Enroll&amp;quot; should literally be read as &amp;quot;Assign a role to.&amp;quot;  To accomodate this flexibility, the database model has changed.  There is now a mdl_role_assignments table that holds the equivalent information.  For more information, see [[Development:Roles|the roles development documentation]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Enrolment]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40191</id>
		<title>Enrolment FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40191"/>
		<updated>2008-07-22T00:53:30Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Where in the database is the relationship between user and course? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
==How do I prevent users from enrolling themselves on courses?==&lt;br /&gt;
&lt;br /&gt;
There are several methods to prevent or restrict [[Internal enrolment]] by a student. &lt;br /&gt;
*Set an [[Enrolment key|enrolment key]] in the course settings, so whilst the student can automatically enrol, they will need the key to complete the process. &lt;br /&gt;
*Set &#039;&#039;Course enrollable&#039;&#039; to &#039;&#039;No&#039;&#039; in the course settings. This stops the internal enrolment (student initiated enrolment) process.&lt;br /&gt;
&lt;br /&gt;
Note that neither method will prevent [[Enrolment#Manual enrolment|manual enrolments]] or [[Enrolment plugins]] from working.&lt;br /&gt;
&lt;br /&gt;
== Why are users being unenrolled for no apparent reason? ==&lt;br /&gt;
&lt;br /&gt;
Please check the following:&lt;br /&gt;
*The &#039;&#039;longtimenosee&#039;&#039; variable in &#039;&#039;Site Administration &amp;gt; Server &amp;gt; Cleanup&#039;&#039; (or Administration &amp;gt; Configuration &amp;gt; Variables in Moodle 1.6) which specifies the time limit for which, if students haven&#039;t logged in, they are unenrolled from courses.&lt;br /&gt;
*The &#039;&#039;Enrolment duration&#039;&#039; in the [[course/edit|Course settings]] which unenrols students after the specified time has elapsed.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for a full list of what controls unenrolment.)&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
If the default role for all users in &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to student rather than authenticated user (the default setting), this will result in all students being enrolled in all courses.&lt;br /&gt;
&lt;br /&gt;
Another possibility is that users are assigned the system role of student. Check &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and unassign users as necessary, then reassign them the role of student in the course context.&lt;br /&gt;
&lt;br /&gt;
==Why can&#039;t I select &amp;quot;External Database&amp;quot; from the enrolment plugins drop-down menu in the course settings?==&lt;br /&gt;
&lt;br /&gt;
Only &#039;&#039;interactive&#039;&#039; enrolment methods may be chosen in the course settings. Non-interactive enrolment plugins are set for the entire site in &#039;&#039;Site Administration&#039;&#039; &amp;gt; &#039;&#039;Enrolment&#039;&#039;. Please refer to the interactive enrolment section of [[Enrolment plugins]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable students to unenrol themselves from courses?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the student role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from not set to allow.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for instructions on how to enable students to unenrol themselves from a particular course.)&lt;br /&gt;
&lt;br /&gt;
==How do I prevent teachers from unenrolling themselves from their course by mistake?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the teacher role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from allow to not set.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
==How do I change the spelling of &amp;quot;enrol&amp;quot; to &amp;quot;enroll&amp;quot;?==&lt;br /&gt;
&lt;br /&gt;
Simply install the American English language pack (en_us) then choose it as the default language for the site. Or [[Language editing|edit your language]] settings.&lt;br /&gt;
&lt;br /&gt;
==Is there a way for lecturers to be notified when students enrol in a course?==&lt;br /&gt;
&lt;br /&gt;
No notifications will be sent when students are allowed to enrol by the [[Internal enrolment]] process.  It can be done by changing the open source code, but not by through the interface. Other enrolment methods (for example [[Flat file]]) can allow emails when enrolment is complete but these are not student initiated.&lt;br /&gt;
&lt;br /&gt;
==When a student enrols using an enrolment key, they get a welcome e-mail message.  Can a lecturer customise this at the course level?==&lt;br /&gt;
&lt;br /&gt;
Entering text for the message is described [[Email_processing#Email_confirmation_or_registration_words.2C_and_how_to_edit_them| Documentation here]].  But at the course level, not possible without a hack.&lt;br /&gt;
&lt;br /&gt;
==Where in the database is the relationship between user and course?==&lt;br /&gt;
&lt;br /&gt;
Prior to Moodle 1.7, enrollments were represented by two simple tables:  mdl_user_students and mdl_user_teachers.  Under the new Roles and Capabilities System introduced in Moodle 1.7, the concept of enrollment has been generalized.  The word &amp;quot;Enroll&amp;quot; should literally be read as &amp;quot;Assign a role to.&amp;quot;  To accomodate this flexibility, the database model has changed.  There is now a mdl_role_assignments table that holds the equivalent information.  For more information, see [[Development:Roles|the roles development documentation]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Enrolment]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40190</id>
		<title>Enrolment FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Enrolment_FAQ&amp;diff=40190"/>
		<updated>2008-07-22T00:50:27Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{FAQ}}&lt;br /&gt;
==How do I prevent users from enrolling themselves on courses?==&lt;br /&gt;
&lt;br /&gt;
There are several methods to prevent or restrict [[Internal enrolment]] by a student. &lt;br /&gt;
*Set an [[Enrolment key|enrolment key]] in the course settings, so whilst the student can automatically enrol, they will need the key to complete the process. &lt;br /&gt;
*Set &#039;&#039;Course enrollable&#039;&#039; to &#039;&#039;No&#039;&#039; in the course settings. This stops the internal enrolment (student initiated enrolment) process.&lt;br /&gt;
&lt;br /&gt;
Note that neither method will prevent [[Enrolment#Manual enrolment|manual enrolments]] or [[Enrolment plugins]] from working.&lt;br /&gt;
&lt;br /&gt;
== Why are users being unenrolled for no apparent reason? ==&lt;br /&gt;
&lt;br /&gt;
Please check the following:&lt;br /&gt;
*The &#039;&#039;longtimenosee&#039;&#039; variable in &#039;&#039;Site Administration &amp;gt; Server &amp;gt; Cleanup&#039;&#039; (or Administration &amp;gt; Configuration &amp;gt; Variables in Moodle 1.6) which specifies the time limit for which, if students haven&#039;t logged in, they are unenrolled from courses.&lt;br /&gt;
*The &#039;&#039;Enrolment duration&#039;&#039; in the [[course/edit|Course settings]] which unenrols students after the specified time has elapsed.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for a full list of what controls unenrolment.)&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
If the default role for all users in &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to student rather than authenticated user (the default setting), this will result in all students being enrolled in all courses.&lt;br /&gt;
&lt;br /&gt;
Another possibility is that users are assigned the system role of student. Check &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and unassign users as necessary, then reassign them the role of student in the course context.&lt;br /&gt;
&lt;br /&gt;
==Why can&#039;t I select &amp;quot;External Database&amp;quot; from the enrolment plugins drop-down menu in the course settings?==&lt;br /&gt;
&lt;br /&gt;
Only &#039;&#039;interactive&#039;&#039; enrolment methods may be chosen in the course settings. Non-interactive enrolment plugins are set for the entire site in &#039;&#039;Site Administration&#039;&#039; &amp;gt; &#039;&#039;Enrolment&#039;&#039;. Please refer to the interactive enrolment section of [[Enrolment plugins]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable students to unenrol themselves from courses?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the student role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from not set to allow.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
(See [[Unenrolment]] for instructions on how to enable students to unenrol themselves from a particular course.)&lt;br /&gt;
&lt;br /&gt;
==How do I prevent teachers from unenrolling themselves from their course by mistake?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Click the edit icon opposite the teacher role.&lt;br /&gt;
#Change the [[Capabilities/moodle/role:unassignself|moodle/role:unassignself]] capability from allow to not set.&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page.&lt;br /&gt;
&lt;br /&gt;
==How do I change the spelling of &amp;quot;enrol&amp;quot; to &amp;quot;enroll&amp;quot;?==&lt;br /&gt;
&lt;br /&gt;
Simply install the American English language pack (en_us) then choose it as the default language for the site. Or [[Language editing|edit your language]] settings.&lt;br /&gt;
&lt;br /&gt;
==Is there a way for lecturers to be notified when students enrol in a course?==&lt;br /&gt;
&lt;br /&gt;
No notifications will be sent when students are allowed to enrol by the [[Internal enrolment]] process.  It can be done by changing the open source code, but not by through the interface. Other enrolment methods (for example [[Flat file]]) can allow emails when enrolment is complete but these are not student initiated.&lt;br /&gt;
&lt;br /&gt;
==When a student enrols using an enrolment key, they get a welcome e-mail message.  Can a lecturer customise this at the course level?==&lt;br /&gt;
&lt;br /&gt;
Entering text for the message is described [[Email_processing#Email_confirmation_or_registration_words.2C_and_how_to_edit_them| Documentation here]].  But at the course level, not possible without a hack.&lt;br /&gt;
&lt;br /&gt;
==Where in the database is the relationship between user and course?==&lt;br /&gt;
&lt;br /&gt;
Prior to Moodle 1.7, enrollments were represented by two simple tables:  mdl_user_students and mdl_user_teachers.  Under the new Roles and Capabilities System introduced in Moodle 1.7, the concept of enrollment has been generalized.  The word &amp;quot;Enroll&amp;quot; should litterally be read as &amp;quot;Assign a role to.&amp;quot;  The data base model has become considerably more complicated.  There is now a mdl_role_assignments table that holds the equivalent information.  For more information, see [[Development:Roles|the roles development documentation]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Enrolment]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40188</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40188"/>
		<updated>2008-07-21T20:07:54Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; to all my courses? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Role&lt;br /&gt;
:An identifier of the user&#039;s status in some context, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Capability&lt;br /&gt;
:A description of a particular Moodle feature, for example [[Capabilities/moodle/blog:create|moodle/blog:create]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A setting for a capability - inherit, allow, prevent or prohibit&lt;br /&gt;
;Context&lt;br /&gt;
:A &amp;quot;space&amp;quot; in Moodle, such as courses, activity modules or blocks&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; in all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40187</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40187"/>
		<updated>2008-07-21T20:06:01Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Why are participants being added automatically when a new course is created? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Role&lt;br /&gt;
:An identifier of the user&#039;s status in some context, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Capability&lt;br /&gt;
:A description of a particular Moodle feature, for example [[Capabilities/moodle/blog:create|moodle/blog:create]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A setting for a capability - inherit, allow, prevent or prohibit&lt;br /&gt;
;Context&lt;br /&gt;
:A &amp;quot;space&amp;quot; in Moodle, such as courses, activity modules or blocks&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are all my teacher accounts automatically added as &amp;quot;Teachers&amp;quot; to all my courses?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40186</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40186"/>
		<updated>2008-07-21T20:01:08Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Why are participants being added automatically when a new course is created? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Role&lt;br /&gt;
:An identifier of the user&#039;s status in some context, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Capability&lt;br /&gt;
:A description of a particular Moodle feature, for example [[Capabilities/moodle/blog:create|moodle/blog:create]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A setting for a capability - inherit, allow, prevent or prohibit&lt;br /&gt;
;Context&lt;br /&gt;
:A &amp;quot;space&amp;quot; in Moodle, such as courses, activity modules or blocks&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are participants being added automatically when a new course is created?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a role in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles) or in a Course category context, then the user will have this role in ALL courses within the context. For example, a user who is assigned the Teacher role in the System context will appear as a Teacher in all courses on the site, including the Front page course.&lt;br /&gt;
&lt;br /&gt;
Except in very special cases, teachers and students should be assigned their respective roles in a Course context.  When these roles are assigned in a System context, it is almost always an error on the part of the administrator.&lt;br /&gt;
&lt;br /&gt;
If you have accidentally assigned a System role, go to &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; unassign users using the right-facing arrow button.  Then re-assign the roles in the appropriate Course context.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40185</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40185"/>
		<updated>2008-07-21T19:53:19Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Role&lt;br /&gt;
:An identifier of the user&#039;s status in some context, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Capability&lt;br /&gt;
:A description of a particular Moodle feature, for example [[Capabilities/moodle/blog:create|moodle/blog:create]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A setting for a capability - inherit, allow, prevent or prohibit&lt;br /&gt;
;Context&lt;br /&gt;
:A &amp;quot;space&amp;quot; in Moodle, such as courses, activity modules or blocks&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are participants being added automatically when a new course is created?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a system role or a role in the course category context then the user has this role in ALL courses in that context. Thus users who are students or teachers at the category level appear as course participants in all courses in that category.&lt;br /&gt;
&lt;br /&gt;
Please check &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and also the Assign roles link in course categories page and unassign users as necessary.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==What is the difference between Prevent and Not set?==&lt;br /&gt;
&lt;br /&gt;
If a role has capability &#039;&#039;X = Not set&#039;&#039;, then the role is saying &amp;quot;I don&#039;t care about X.&amp;quot;  If a role has &#039;&#039;X = Prevent,&#039;&#039; then the role is saying &amp;quot;I don&#039;t want you be able to do X.&amp;quot;  Now you typically have multiple roles in a given context, and those roles may have different opinions about &#039;&#039;X&#039;&#039;. If ALL of your roles have &#039;&#039;X = Not set&#039;&#039; then you will be effectively prevented from doing &#039;&#039;X&#039;&#039; because you need positive permission to do something.  It&#039;s just like an election.  If you are a candidate but no one votes, you don&#039;t win the election.  If all of your roles except for one has &#039;&#039;X = Not set&#039;&#039; and the remaining role has &#039;&#039;X = Allow&#039;&#039;, then you will be allowed to do X.  Again, it&#039;s like an election where only one person votes, and they vote for you!  For more complicated cases (e.g., roles assigned and overridden in different contexts) you need to understand [[How permissions are calculated]], but the principle is the same: By not voting, a role can allow other roles to determine the outcome of the election.  Roles with lots of permissions Not set tend to mix well with other roles. &lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40180</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40180"/>
		<updated>2008-07-21T19:16:58Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Role&lt;br /&gt;
:An identifier of the user&#039;s status in some context, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Capability&lt;br /&gt;
:A description of a particular Moodle feature, for example [[Capabilities/moodle/blog:create|moodle/blog:create]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A setting for a capability - inherit, allow, prevent or prohibit&lt;br /&gt;
;Context&lt;br /&gt;
:A &amp;quot;space&amp;quot; in Moodle, such as courses, activity modules or blocks&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are participants being added automatically when a new course is created?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a system role or a role in the course category context then the user has this role in ALL courses in that context. Thus users who are students or teachers at the category level appear as course participants in all courses in that category.&lt;br /&gt;
&lt;br /&gt;
Please check &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and also the Assign roles link in course categories page and unassign users as necessary.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==Where are permissions inherited from?==&lt;br /&gt;
&lt;br /&gt;
Permissions are inherited from a role assigned in a higher-level context which has permissions set to allow for particular capabilities. If permission is &amp;quot;Not set&amp;quot; in any context and not allowed in any higher context (in particular, if you are creating or editing a role at the site level), then a user will have no permission for that capability.&lt;br /&gt;
&lt;br /&gt;
For example, the Student role has permission not set for the change site configuration capability. The permission is never allowed in any context so users assigned the role of Student cannot change the site configuration.&lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See [[Roles_FAQ#How can I prevent a user from changing their own password? | How can I prevent a user from changing their own password?]]  The answer to this question is the same if you substitute &#039;&#039;edit their own profile&#039;&#039; for &#039;&#039;change their own password&#039;&#039; and &#039;&#039;moodle/user:editownprofile&#039;&#039; for &#039;&#039;moodle/user:changeownpassword.&#039;&#039; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40179</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=40179"/>
		<updated>2008-07-21T19:11:23Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Role&lt;br /&gt;
:An identifier of the user&#039;s status in some context, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Capability&lt;br /&gt;
:A description of a particular Moodle feature, for example [[Capabilities/moodle/blog:create|moodle/blog:create]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A setting for a capability - inherit, allow, prevent or prohibit&lt;br /&gt;
;Context&lt;br /&gt;
:A &amp;quot;space&amp;quot; in Moodle, such as courses, activity modules or blocks&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are participants being added automatically when a new course is created?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a system role or a role in the course category context then the user has this role in ALL courses in that context. Thus users who are students or teachers at the category level appear as course participants in all courses in that category.&lt;br /&gt;
&lt;br /&gt;
Please check &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and also the Assign roles link in course categories page and unassign users as necessary.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==Where are permissions inherited from?==&lt;br /&gt;
&lt;br /&gt;
Permissions are inherited from a role assigned in a higher-level context which has permissions set to allow for particular capabilities. If permission is &amp;quot;Not set&amp;quot; in any context and not allowed in any higher context (in particular, if you are creating or editing a role at the site level), then a user will have no permission for that capability.&lt;br /&gt;
&lt;br /&gt;
For example, the Student role has permission not set for the change site configuration capability. The permission is never allowed in any context so users assigned the role of Student cannot change the site configuration.&lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from changing their own password?==&lt;br /&gt;
&lt;br /&gt;
To prevent a user from changing their own password, you must make sure they do not have moodle/user:changeownpassword (&amp;quot;Change own password&amp;quot;) = Allow in the System context. The Authenticated user role (which is assigned to users in the System context) has moodle/user:changeownpassword = Allow by default, so you have two choices: &lt;br /&gt;
# edit Authenticated user, setting moodle/user:changeownpassword = Not set &lt;br /&gt;
# create a new role CannotChangeOwnPassword with moodle/user:changeownpassword = Prevent and all other permissions Not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles). &lt;br /&gt;
&lt;br /&gt;
Choice (1) will prevent &#039;&#039;all&#039;&#039; users from changing their passwords (except for the administrator, who can do anything).  To selectively allow selected users (say teachers) to change their passwords, you could create a new role CanChangeOwnPassword with moodle/user:changeownpassword = Allow and all other permissions not set and assign the role to selected users in the System context (Site administration -&amp;gt; Users -&amp;gt; Permissions -&amp;gt; Assign system roles).&lt;br /&gt;
&lt;br /&gt;
Choice (2) allows you to be selective, but if you have a lot of users that you want to prevent (say, all students), you will have to make a lot of role assignments in the System context.  There is currently no convenient way to do this, so you might consider choice (1).&lt;br /&gt;
&lt;br /&gt;
Note that you MUST deal with this permission in the System context.&lt;br /&gt;
&lt;br /&gt;
==How can I prevent a user from editing their own profile?==&lt;br /&gt;
&lt;br /&gt;
See &amp;quot;How can I prevent a user from chaning their own password?&amp;quot;  The answer to this question is the same if you substitute &amp;quot;edit their own profile&amp;quot; for &amp;quot;change their own password&amp;quot; and &amp;quot;moodle/user:editownprofile&amp;quot; for &amp;quot;moodle/user:changeownpassword.&amp;quot; &lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role|Forum moderator]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role|Blogger]] - for limiting blogging to specific users only&lt;br /&gt;
*[[Quiz user with unlimited time role|Quiz user with unlimited time]] - for allowing a user unlimited time to attempt a quiz which has a time limit set&lt;br /&gt;
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override permissions&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
==How do I copy a custom role from one Moodle site to another==&lt;br /&gt;
&lt;br /&gt;
There is no import and export facility for roles, but it can be achieved nearly as easily using backup and restore.&lt;br /&gt;
&lt;br /&gt;
# Create an empty course with all the default settings&lt;br /&gt;
# Assign anybody to your custom role (or roles) within the course&lt;br /&gt;
# Backup the course (all defaults are fine)&lt;br /&gt;
# Download the backup file&lt;br /&gt;
# Upload the backup file to the site files of the target Moodle&lt;br /&gt;
# Restore the course (all defaults are fine)&lt;br /&gt;
# Delete the course.&lt;br /&gt;
&lt;br /&gt;
You will find that the custom roles have been recreated in the target site.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[de:Rollen FAQ]]&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40137</id>
		<title>Keyholder role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40137"/>
		<updated>2008-07-21T13:55:36Z</updated>

		<summary type="html">&lt;p&gt;Jisner: Undo revision 39978 by Jisner (Talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The role of &#039;&#039;&#039;Keyholder&#039;&#039;&#039; may be used to set the person named as holding a course [[Enrolment key|enrolment key]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that from Moodle 1.8.3 you can specify the role of the keyholder in the [[Internal enrolment]] settings, making this tip effectively redundant (although it will still work as described if the keyholder is not set).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Keyholder, short name and description&lt;br /&gt;
#Change the capability [[Capabilities/moodle/course:update|moodle/course:update]] to allow&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Use the up arrows in the edit column to move the Keyholder role above the Teacher role in the list&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
# Access the Assign roles page in a particular course via the Assign roles link in course administration block&lt;br /&gt;
# Choose the Keyholder role to assign&lt;br /&gt;
# Select the user holding the course enrolment key in the potential users list, and use the left-facing arrow button to add it to the existing users list&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Rôle gardien de clé]]&lt;br /&gt;
[[ja:キー保持者ロール]]&lt;br /&gt;
[[de:Kursschlüsselverwalter-Rolle]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40136</id>
		<title>Keyholder role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40136"/>
		<updated>2008-07-21T13:55:20Z</updated>

		<summary type="html">&lt;p&gt;Jisner: Undo revision 39979 by Jisner (Talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The role of &#039;&#039;&#039;Keyholder&#039;&#039;&#039; may be used to set the person named as holding a course [[Enrolment key|enrolment key]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that from Moodle 1.8.3 you can specify the role of the keyholder in the [[Internal enrolment]] settings, making this tip effectively redundant (although it will still work as described if the keyholder is not set).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Keyholder, short name and description&lt;br /&gt;
#Change the capability [[Capabilities/moodle/course:update|moodle/course:update]] to allow&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Use the up arrows in the edit column to move the Keyholder role above the Teacher role in the list&lt;br /&gt;
#Go to &#039;&#039;Site administration &amp;gt; Courses &amp;gt; Enrolments&#039;&#039; and click the Edit link next to Internal Enrolments.  Choose &amp;quot;Keyholder&amp;quot; from the enrol_manual_keyholder dropdown list. Save changes.&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
# Access the Assign roles page in a particular course via the Assign roles link in course administration block&lt;br /&gt;
# Choose the Keyholder role to assign&lt;br /&gt;
# Select the user holding the course enrolment key in the potential users list, and use the left-facing arrow button to add it to the existing users list&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Rôle gardien de clé]]&lt;br /&gt;
[[ja:キー保持者ロール]]&lt;br /&gt;
[[de:Kursschlüsselverwalter-Rolle]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40135</id>
		<title>Keyholder role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40135"/>
		<updated>2008-07-21T13:54:06Z</updated>

		<summary type="html">&lt;p&gt;Jisner: Undo revision 40134 by Jisner (Talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The role of &#039;&#039;&#039;Keyholder&#039;&#039;&#039; may be used to set the person named as holding a course [[Enrolment key|enrolment key]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that from Moodle 1.8.3 you can specify the role of the keyholder in the [[Internal enrolment]] settings, making this tip effectively redundant (although it will still work as described if the keyholder is not set).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Keyholder, short name and description&lt;br /&gt;
#Change the capability [[Capabilities/moodle/course:update|moodle/course:update]] to allow&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Use the up arrows in the edit column to move the Keyholder role above the Teacher role in the list&lt;br /&gt;
#Go to &#039;&#039;Site administration &amp;gt; Courses &amp;gt; Enrolments&#039;&#039; and click the Edit link next to Internal Enrolments.  Choose &amp;quot;Keyholder&amp;quot; from the enrol_manual_keyholder dropdown list. Save changes.&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
# Access the Assign roles page in a particular course via the Assign roles link in course administration block&lt;br /&gt;
# Choose the Keyholder role to assign&lt;br /&gt;
# Select the user holding the course enrolment key in the potential users list, and use the left-facing arrow button to add it to the existing users list&lt;br /&gt;
&lt;br /&gt;
Note: Currently, you &#039;&#039;must&#039;&#039; assign the role in a Course context.  If you assign it in a higher context (Category or System) the mechanism does not work.  See MDL-14566.&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Rôle gardien de clé]]&lt;br /&gt;
[[ja:キー保持者ロール]]&lt;br /&gt;
[[de:Kursschlüsselverwalter-Rolle]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40134</id>
		<title>Keyholder role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=40134"/>
		<updated>2008-07-21T13:53:32Z</updated>

		<summary type="html">&lt;p&gt;Jisner: Undo revision 39979 by Jisner (Talk)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The role of &#039;&#039;&#039;Keyholder&#039;&#039;&#039; may be used to set the person named as holding a course [[Enrolment key|enrolment key]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that from Moodle 1.8.3 you can specify the role of the keyholder in the [[Internal enrolment]] settings, making this tip effectively redundant (although it will still work as described if the keyholder is not set).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Keyholder, short name and description&lt;br /&gt;
#Change the capability [[Capabilities/moodle/course:update|moodle/course:update]] to allow&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Use the up arrows in the edit column to move the Keyholder role above the Teacher role in the list&lt;br /&gt;
#Go to &#039;&#039;Site administration &amp;gt; Courses &amp;gt; Enrolments&#039;&#039; and click the Edit link next to Internal Enrolments.  Choose &amp;quot;Keyholder&amp;quot; from the enrol_manual_keyholder dropdown list. Save changes.&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
# Access the Assign roles page in a particular course via the Assign roles link in course administration block&lt;br /&gt;
# Choose the Keyholder role to assign&lt;br /&gt;
# Select the user holding the course enrolment key in the potential users list, and use the left-facing arrow button to add it to the existing users list&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Rôle gardien de clé]]&lt;br /&gt;
[[ja:キー保持者ロール]]&lt;br /&gt;
[[de:Kursschlüsselverwalter-Rolle]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=39979</id>
		<title>Keyholder role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=39979"/>
		<updated>2008-07-18T15:03:12Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Role assignment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The role of &#039;&#039;&#039;Keyholder&#039;&#039;&#039; may be used to set the person named as holding a course [[Enrolment key|enrolment key]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that from Moodle 1.8.3 you can specify the role of the keyholder in the [[Internal enrolment]] settings, making this tip effectively redundant (although it will still work as described if the keyholder is not set).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Keyholder, short name and description&lt;br /&gt;
#Change the capability [[Capabilities/moodle/course:update|moodle/course:update]] to allow&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Use the up arrows in the edit column to move the Keyholder role above the Teacher role in the list&lt;br /&gt;
#Go to &#039;&#039;Site administration &amp;gt; Courses &amp;gt; Enrolments&#039;&#039; and click the Edit link next to Internal Enrolments.  Choose &amp;quot;Keyholder&amp;quot; from the enrol_manual_keyholder dropdown list. Save changes.&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
# Access the Assign roles page in a particular course via the Assign roles link in course administration block&lt;br /&gt;
# Choose the Keyholder role to assign&lt;br /&gt;
# Select the user holding the course enrolment key in the potential users list, and use the left-facing arrow button to add it to the existing users list&lt;br /&gt;
&lt;br /&gt;
Note: Currently, you &#039;&#039;must&#039;&#039; assign the role in a Course context.  If you assign it in a higher context (Category or System) the mechanism does not work.  See MDL-14566.&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Rôle gardien de clé]]&lt;br /&gt;
[[ja:キー保持者ロール]]&lt;br /&gt;
[[de:Kursschlüsselverwalter-Rolle]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=39978</id>
		<title>Keyholder role</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Keyholder_role&amp;diff=39978"/>
		<updated>2008-07-18T15:00:24Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Role set-up */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The role of &#039;&#039;&#039;Keyholder&#039;&#039;&#039; may be used to set the person named as holding a course [[Enrolment key|enrolment key]].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note that from Moodle 1.8.3 you can specify the role of the keyholder in the [[Internal enrolment]] settings, making this tip effectively redundant (although it will still work as described if the keyholder is not set).&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Role set-up==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Give the role a name e.g. Keyholder, short name and description&lt;br /&gt;
#Change the capability [[Capabilities/moodle/course:update|moodle/course:update]] to allow&lt;br /&gt;
#Click the button &amp;quot;Add a new role&amp;quot;&lt;br /&gt;
#Use the up arrows in the edit column to move the Keyholder role above the Teacher role in the list&lt;br /&gt;
#Go to &#039;&#039;Site administration &amp;gt; Courses &amp;gt; Enrolments&#039;&#039; and click the Edit link next to Internal Enrolments.  Choose &amp;quot;Keyholder&amp;quot; from the enrol_manual_keyholder dropdown list. Save changes.&lt;br /&gt;
&lt;br /&gt;
==Role assignment==&lt;br /&gt;
&lt;br /&gt;
# Access the Assign roles page in a particular course via the Assign roles link in course administration block&lt;br /&gt;
# Choose the Keyholder role to assign&lt;br /&gt;
# Select the user holding the course enrolment key in the potential users list, and use the left-facing arrow button to add it to the existing users list&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Rôle gardien de clé]]&lt;br /&gt;
[[ja:キー保持者ロール]]&lt;br /&gt;
[[de:Kursschlüsselverwalter-Rolle]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Forum_ratings&amp;diff=39931</id>
		<title>Forum ratings</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Forum_ratings&amp;diff=39931"/>
		<updated>2008-07-17T19:57:41Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* How to use */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Forums}}&lt;br /&gt;
Forum ratings allow users to evaluate posts in a forum.&lt;br /&gt;
&lt;br /&gt;
==How to use==&lt;br /&gt;
If a user has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Allow in a forum context, the user will be able to rate posts in that forum (see below). Note that the predefined Teacher role has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Allow, while the predefined Student role has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Not set.  As a result, only teachers are allowed to rate forum posts by default.  To allow students to rate posts, see [[Forum_permissions#Enabling_students_to_rate_posts | enabling students to rate posts]].&lt;br /&gt;
&lt;br /&gt;
A user who is allowed to rate posts will see, at the end of each post (except, of course, for his own posts) a label &amp;quot;Rate this post&amp;quot; with a pulldown menu.  The menu displays a [[Scales|scale]] that the forum creator selected in the [[Adding/editing_a_forum#Grade|Forum grade settings]].  The rating can become part of the [[Grades|Gradebook]].  &lt;br /&gt;
&lt;br /&gt;
[[Image:Forum rating example1 mu.png|thumb|center|Teacher view of a previously rated student post]]&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
*Not all your students are seeing stars?  It is all about their browser settings, language and installed fonts.  &lt;br /&gt;
**If this is a problem, stick with the basics in you scale.  Perhaps create a scale that uses Numbers and words. &lt;br /&gt;
&lt;br /&gt;
==See also==  &lt;br /&gt;
*[[Course level ratings]]&lt;br /&gt;
*[[Scales]]&lt;br /&gt;
*[[Grades]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Forum_ratings&amp;diff=39930</id>
		<title>Forum ratings</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Forum_ratings&amp;diff=39930"/>
		<updated>2008-07-17T19:54:38Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Forums}}&lt;br /&gt;
Forum ratings allow users to evaluate posts in a forum.&lt;br /&gt;
&lt;br /&gt;
==How to use==&lt;br /&gt;
If a user has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Allow in a forum context, the user will be able to rate posts in that forum (see below). Note that the predefined Teacher role has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Allow, while the predefined Student role has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Not set.  As a result, only teachers are allowed to rate forum posts by default.&lt;br /&gt;
&lt;br /&gt;
A user who is allowed to rate posts will see, at the end of each post (except, of course, for his own posts) a label &amp;quot;Rate this post&amp;quot; with a pulldown menu.  The menu displays a [[Scales|scale]] that the forum creator selected in the [[Adding/editing_a_forum#Grade|Forum grade settings]].  The rating can become part of the [[Grades|Gradebook]].  &lt;br /&gt;
&lt;br /&gt;
[[Image:Forum rating example1 mu.png|thumb|center|Teacher view of a previously rated student post]]&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
*Not all your students are seeing stars?  It is all about their browser settings, language and installed fonts.  &lt;br /&gt;
**If this is a problem, stick with the basics in you scale.  Perhaps create a scale that uses Numbers and words. &lt;br /&gt;
&lt;br /&gt;
==See also==  &lt;br /&gt;
*[[Course level ratings]]&lt;br /&gt;
*[[Scales]]&lt;br /&gt;
*[[Grades]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Forum_ratings&amp;diff=39929</id>
		<title>Forum ratings</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Forum_ratings&amp;diff=39929"/>
		<updated>2008-07-17T19:51:24Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* How to use */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Forums}}&lt;br /&gt;
Forum ratings allow either the teacher and/or students to evaluate posts in a forum.&lt;br /&gt;
&lt;br /&gt;
==How to use==&lt;br /&gt;
If a user has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Allow in a forum context, the user will see a label &amp;quot;Rate this post&amp;quot; with a pulldown menu at the bottom of each post (except, of course, for his own posts).  The menu displays a [[Scales|scale]] that the forum creator selected in the [[Adding/editing_a_forum#Grade|Forum grade settings]].  The rating can become part of the [[Grades|Gradebook]].  Note that the predefined Teacher role has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Allow, while the predefined Student role has mod/forum:rate (&amp;quot;Rate posts&amp;quot;) = Not set.  As a result, only teachers are allowed to rate forum posts by default.&lt;br /&gt;
&lt;br /&gt;
[[Image:Forum rating example1 mu.png|thumb|center|Teacher view of a previously rated student post]]&lt;br /&gt;
&lt;br /&gt;
==Tips and Tricks==&lt;br /&gt;
*Not all your students are seeing stars?  It is all about their browser settings, language and installed fonts.  &lt;br /&gt;
**If this is a problem, stick with the basics in you scale.  Perhaps create a scale that uses Numbers and words. &lt;br /&gt;
&lt;br /&gt;
==See also==  &lt;br /&gt;
*[[Course level ratings]]&lt;br /&gt;
*[[Scales]]&lt;br /&gt;
*[[Grades]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=39170</id>
		<title>How permissions are calculated</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=39170"/>
		<updated>2008-07-04T03:58:44Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Representing the data in tabular form */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
One of the most frequently asked question is: &#039;&#039;What are my permissions in this context?&#039;&#039; This article will document the function that Moodle uses to answer this question.  The article is written for non-programmers as well as programmers, since it describes &#039;&#039;what&#039;&#039; the function does, not &#039;&#039;how&#039;&#039;. The &#039;&#039;how&#039;&#039; is complicated. The &#039;&#039;what&#039;&#039; turns out to be relatively simple!  If you are a programmer and you insist on reading the code, look for &#039;&#039;has_capability()&#039;&#039; in &#039;&#039;lib/accesslib.php&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Given a user, a capability, and a context, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039; if the user is allowed to perform the action controlled by the capability in the given context, and &#039;&#039;false&#039;&#039; otherwise.  In calculating the permission, the function considers all of the relevant permission data, which include role definitions, assignments, and overrides.&lt;br /&gt;
&lt;br /&gt;
Moodle never calculates a user&#039;s complete set of permissions.  To do so would be very costly and also wasteful, since most permissions are never tested. Instead, Moodle calculates permissions only as needed. It does not store the permissions that it calculates, but recalculates them every time it needs to test them. This is why role assignments and overrides no longer have delayed effects, as they did in Moodle 1.7 and 1.8.&lt;br /&gt;
&lt;br /&gt;
Incidentally, you can generate permission tables like the ones in this article using [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
==The calculation==&lt;br /&gt;
&lt;br /&gt;
When a user attempts an action that is controlled by a capability, Moodle calls has_capability to see if the action should be permitted.  The function is called as follows:&lt;br /&gt;
&lt;br /&gt;
    has_capability(CAP,CONTEXT,USER);&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
*CAP is the capability that controls the action (e.g., mod/quiz:attempt)&lt;br /&gt;
*CONTEXT is the context in which the capability is being tested&lt;br /&gt;
*USER is the user attempting the action&lt;br /&gt;
&lt;br /&gt;
The function returns a true/false result&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;true&#039;&#039;  means the user should be allowed to perform the action&lt;br /&gt;
* &#039;&#039;false&#039;&#039; means the user should be prevented from perfoming the action&lt;br /&gt;
&lt;br /&gt;
===Data used by the function===&lt;br /&gt;
&lt;br /&gt;
Suppose USER is about to attempt a quiz (&#039;&#039;CAP = mod/quiz:attempt&#039;&#039;) in a Module context nested four levels deep within System.  &lt;br /&gt;
&lt;br /&gt;
      System&lt;br /&gt;
         |&lt;br /&gt;
     Category A&lt;br /&gt;
         |					      &lt;br /&gt;
    Subcategory B&lt;br /&gt;
         |&lt;br /&gt;
       Course&lt;br /&gt;
         |&lt;br /&gt;
       Quiz  &amp;lt;--- the user is here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The quiz module will call &#039;&#039;has_capability()&#039;&#039; to see if the user should be allowed to perform this action.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; considers the following permission data:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Role definitions&#039;&#039; (these are in the System context) &lt;br /&gt;
* &#039;&#039;Role assignments&#039;&#039; which may occur in any of the five contexts &lt;br /&gt;
* &#039;&#039;Role overrides&#039;&#039; which may occur in any of the contexts except System (there is no concept of override in System).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; ignores capabilities other than CAP.  This simplification lets us view each role or override as if it contains a &#039;&#039;single permission&#039;&#039; having one of the following values&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
We use the following notation: for a role &#039;&#039;R1&#039;&#039; with permission &#039;&#039;P&#039;&#039;, we write &#039;&#039;R1(P)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===An example===&lt;br /&gt;
&lt;br /&gt;
In the quiz example, suppose that the user has four roles (&#039;&#039;R1&#039;&#039;, &#039;&#039;R2&#039;&#039;, &#039;&#039;R3&#039;&#039;, and &#039;&#039;R4&#039;&#039;) and each of the roles has been assigned and overridden as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define R1(A), R2(N), R3(N), R4(P)&lt;br /&gt;
            |               assign R1&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A    &amp;lt;-------------- overide R1(N) and R4(N)&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign R2 and R3&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;-------------- override R2(X) and R3(A)&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4     Quiz        &amp;lt;---- assign R4 and R1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;R1&#039;&#039; has been assigned in two different contexts. This is an unusual practice (it is probably someone&#039;s error), but since it is legal, we have to consider the possibility that it can happen.  In fact this entire example has been contrived to explore the edge cases of the algorithm.  In practice, the calculation of permissions is trivial and the function calculates the result you would expect based on common sense and simple mental analysis (for further discussion of this, see [[#A note about the algorithm|A note about the algorithm]] near the end of this article.&lt;br /&gt;
&lt;br /&gt;
===Representing the data in tabular form===&lt;br /&gt;
&lt;br /&gt;
We will set up a table to hold the permission data.  The table has&lt;br /&gt;
*a column for each context, ordered from highest level (System) to lowest (the context where we want to calculate the permission).&lt;br /&gt;
*a row for each context, also listed from highest to lowest.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-3A.png|Empty table]]&lt;br /&gt;
&lt;br /&gt;
The role definitions go in the first row.  Put each definition in the column(s) coresponding to the context(s) in which the role is assigned: &lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-5A.png|Table with assignments added]]&lt;br /&gt;
&lt;br /&gt;
The overrides go in the remaining rows.  Each override goes&lt;br /&gt;
*in the same column as the role being overridden&lt;br /&gt;
*in the row corresponding the context in which the override is made.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s add just one of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-6A.png|Table with just one override]]&lt;br /&gt;
&lt;br /&gt;
R2(X) represents the override to role R2 made in the course context.  Let&#039;s add the rest of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-7A.png|Table with remaining overrides shown]]&lt;br /&gt;
&lt;br /&gt;
The table is now fully populated, and we are ready to calculate the permission.&lt;br /&gt;
&lt;br /&gt;
===The algorithm===&lt;br /&gt;
&lt;br /&gt;
The algorithm follows a path through the table indicated by nodes and arrows in the diagram below and stops as soon as it has a conclusive result.&lt;br /&gt;
&lt;br /&gt;
[[Image:Algorithm_path_through_permission_table_A.png|Algorithm path through permissions data]]&lt;br /&gt;
&lt;br /&gt;
# If there is an X anywhere in the table, STOP.  The calculated permission is &#039;&#039;X&#039;&#039;&lt;br /&gt;
# Go to the START node&lt;br /&gt;
# If there is no next node, STOP.  The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
# Otherwise, follow the arrow to the next node&lt;br /&gt;
#Add the permissions in the node using the numerical equivalents: N = 0, A = +1, P = -1&lt;br /&gt;
#* If the sum is positive, STOP. The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
#* If the sum is negative, STOP. The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
#* If the sum is zero, GO TO step 3 &lt;br /&gt;
&lt;br /&gt;
Notice that the algorithm stops when either (1) a conclusive result is obtained, or (2) the algorithm reaches the last node without a conclusive result.&lt;br /&gt;
&lt;br /&gt;
===Applying the algorithm to our example===&lt;br /&gt;
&lt;br /&gt;
If we execute the algorithm with the quiz data, we stop at step 1 with a calculated permission of X.  That&#039;s not very interesting, so let&#039;s change the X to a P and see what happens:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-8A.png|Change X to P in permission table]]&lt;br /&gt;
&lt;br /&gt;
Run the algorithm:&lt;br /&gt;
&lt;br /&gt;
*There is No X in the table&lt;br /&gt;
*Go to the START node&lt;br /&gt;
*Go to the next node&lt;br /&gt;
*N + N = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*P + A = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*N = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A = +1&lt;br /&gt;
*the sum is positive; STOP.  The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If the calculated permission is &#039;&#039;A&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039;, and the user is allowed to perform the action.&lt;br /&gt;
&lt;br /&gt;
Had the calculated permission been &#039;&#039;P&#039;&#039; or &#039;&#039;X&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; would not immediately return &#039;&#039;false&#039;&#039;. Rather, it would test if the user has &#039;&#039;moodle/site:doanything = Allow&#039;&#039; (since this permission trumps all others). The function does this by calling itself: &lt;br /&gt;
&lt;br /&gt;
    final result = has_capability(moodle/site:doanything,CONTEXT, USER);&lt;br /&gt;
&lt;br /&gt;
==A note about the algorithm==&lt;br /&gt;
&lt;br /&gt;
Earlier, we said that the algorithm &amp;quot;calculates the result you would expect.&amp;quot; But what do we expect?  Intuition tells us that permissions closer to the user should carry more weight than more distant permissions.  That&#039;s why we set up the table the way we did and why the algorithm walks the table in the order that it does.  The last column of the table represents the role assignment(s) closest to the user.  The second-to-last column represents the role assignent(s) that are next in terms of distance from the user, and so-on.  That&#039;s why the algorithm considers the columns from right-to-left.  Within a column, the algorithm searches upward in order to give higher weight to overrides that are closer to the user.  Once again, this matches our intuition about overrides.  If there are no overrides in a column (or the overrides are all Not set), the permission in the role definition is used.&lt;br /&gt;
&lt;br /&gt;
==Getting the result you expect==&lt;br /&gt;
&lt;br /&gt;
The calculation is more likely to give &amp;quot;the result you would expect&amp;quot; if you keep your permissions as simple as possible.  Therefore, we recommend the following &#039;rules&#039; for defining and overriding roles. If you understand the description of the calculation above, you should understand why they make sense.&lt;br /&gt;
&lt;br /&gt;
===When defining roles===&lt;br /&gt;
&lt;br /&gt;
... use Allow (A) for things you want the role to be able to do, and use Not set (N) for things you don&#039;t care about (which should include most things).&lt;br /&gt;
&lt;br /&gt;
===When overriding permissions===&lt;br /&gt;
&lt;br /&gt;
... leave the permission for every capability as Inherit (N) apart from the few you want to change. For those, use Allow (A) for things you want to allow, and Prevent (P) for things you want to prevent.&lt;br /&gt;
&lt;br /&gt;
===Only use prohibit in special roles===&lt;br /&gt;
&lt;br /&gt;
Prohibit exists to cover extreme scenarios such as the following: Suppose you have a naughty student who is posting inappropriate content in your Moodle site. You need to be able to remove their ability to contribute to public discussions until they have promised not to do it again, but during that time, you cannot completely block them from the resources, quizzes, etc. because they must keep up with their studying. Therefore, you need a way to block their access to specific capabilities e.g.  mod/forum:replypost in a way that cannot be overridden. You can do this by creating a special &#039;Naughty student&#039; role defined with the required permission(s) set to prohibit. Then when you are having problems with a user, you can temporarily assign them this role, either at site level or at course level.&lt;br /&gt;
&lt;br /&gt;
==A practical example==&lt;br /&gt;
&lt;br /&gt;
Suppose that a user, who is assigned the role of Course creator in category B, creates a course (becoming Teacher in the course) and then creates a Lesson within the course.  The user is about to edit the lesson (editing lessons is controlled by capability &#039;&#039;mod/lesson:edit&#039;&#039;).  Here is the permission data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define Auth user(N), Creator(N), Teacher(A)&lt;br /&gt;
            |               assign Auth user&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign Creator&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;---- assign Teacher&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4    Lesson       &amp;lt;---- user attempts to edit lesson&lt;br /&gt;
&lt;br /&gt;
We set up the table and populate it with permission data.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-10A.png|A practical example]]&lt;br /&gt;
&lt;br /&gt;
Since there are no overrides, the table only has data in the first row.  The algorithm quickly calculates a permission of &#039;&#039;A&#039;&#039; and returns true.  The user is allowed to edit the Lesson!&lt;br /&gt;
&lt;br /&gt;
Now suppose Teacher is overridden in the Lesson context with &#039;&#039;mod/lesson:edit = P&#039;&#039;.  Then the table changes&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-11A.png|A practical example with first override]]&lt;br /&gt;
&lt;br /&gt;
and clearly the user is no longer allowed to edit the Lesson.&lt;br /&gt;
&lt;br /&gt;
But suppose the administrator (or whoever is making the overrides) decided instead to override the &#039;&#039;Creator role&#039;&#039;, setting &#039;&#039;mod/lesson:edit = Prevent&#039;&#039; in the Categoy B context:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-12A.png|A practical example with second override]]             &lt;br /&gt;
&lt;br /&gt;
Much to everyone&#039;s surprise, the user is still allowed to edit the Lesson!  If you understood this article, you shouldn&#039;t be surprised, and you should be able to explain what happened.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=90140 Logged in: what role am I?] and [http://moodle.org/mod/forum/discuss.php?d=66782 What happens if a user has multiple roles in a course?] forum discussions.  &lt;br /&gt;
&lt;br /&gt;
There is a script that you can use to create tables like the ones in this article.  It is very useful for debugging roles-related problems.  See [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Comment les permissions sont calculées ?]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Grade_import&amp;diff=36779</id>
		<title>Grade import</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Grade_import&amp;diff=36779"/>
		<updated>2008-05-26T13:57:37Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Importing grades */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Grades}}Grades may be imported as a CSV or XML file.&lt;br /&gt;
&lt;br /&gt;
The import file format is the same as the corresponding export format. &lt;br /&gt;
&lt;br /&gt;
Note: Grade import is equivalent to manual grading in the [[Grader report|grader report]]. Thus, if grades for a particular  Moodle activity such as an assignment are imported, they can no longer be edited via the assignment submission page.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Importing grades==&lt;br /&gt;
[[Image:Csv grade import.png|thumb|CSV grade import]]&lt;br /&gt;
To import grades into the gradebook:&lt;br /&gt;
&lt;br /&gt;
# Decide on an import format - CSV or XML file (see below) - then [[Grade export|export some grades]] using the corresponding export format.&lt;br /&gt;
# Edit the export file as appropriate and save it.&lt;br /&gt;
# Select your chosen import format from the gradebook dropdown menu.&lt;br /&gt;
# Browse and upload your previously saved file.&lt;br /&gt;
# Set options as required.&lt;br /&gt;
# Click the &amp;quot;Upload grades&amp;quot; button.&lt;br /&gt;
# CSV import only: Preview the grade import and choose the column mapping then click the &amp;quot;Upload grades&amp;quot; button to complete the grade import.&lt;br /&gt;
&lt;br /&gt;
You need two permissions to import grades: (1) general permission to import grades and (2) permission to import grades in a particular format. For example, to import CSV grades you need&lt;br /&gt;
&lt;br /&gt;
    moodle/grade:import (&amp;quot;Import grades&amp;quot;) = Allow&lt;br /&gt;
    gradeimport/csv:view (&amp;quot;Import grades from CSV&amp;quot;) = Allow&lt;br /&gt;
&lt;br /&gt;
==XML import==&lt;br /&gt;
&lt;br /&gt;
XML import requires the numerical grade, activity idnumber and user idnumber.&lt;br /&gt;
&lt;br /&gt;
===Remote file URL===&lt;br /&gt;
&lt;br /&gt;
The remote file URL field is for fetching data from a remote server, such as a student information system.&lt;br /&gt;
&lt;br /&gt;
==CSV import==&lt;br /&gt;
&lt;br /&gt;
CSV import is more flexible than XML import, as you may choose the column mapping.&lt;br /&gt;
&lt;br /&gt;
===Encoding===&lt;br /&gt;
&lt;br /&gt;
If you are unsure of the encoding of your CSV file, try selecting the second option in the encoding dropdown menu. If you&#039;ve used Excel to produce the CSV file the second option WINDOWS-xxx encoding is probably the correct one. The grade import preview will tell you if you guessed the encoding correctly.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
Using Moodle forum discussions:&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=85944 Gradebook confusion]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=92081 Can external software insert data into the gradebook?]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36089</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36089"/>
		<updated>2008-05-13T15:19:50Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Essential roles and capabilities concepts */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a solid understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required that they do so.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert views the output and immediately diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires a solid understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I should be able do this, but Moodle won&#039;t let me!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are three possibilities:&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified (Moodle calculates some permissions explicitly in System or User contexts).&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission.  For example, Guest has been edited, allowing it to post to Forums,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission. If you ask a developer why, they will tell you &amp;quot;because guests can never post.&amp;quot;&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When such a disagreement occurs, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation.  For example, when a permission is calculated in a different context, the documentation usually says so.  Other times you will just need to read the code. &lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36088</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36088"/>
		<updated>2008-05-13T15:19:02Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* The use case for rolesdebug.php */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a solid understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required that they do so.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert views the output and immediately diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I should be able do this, but Moodle won&#039;t let me!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are three possibilities:&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified (Moodle calculates some permissions explicitly in System or User contexts).&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission.  For example, Guest has been edited, allowing it to post to Forums,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission. If you ask a developer why, they will tell you &amp;quot;because guests can never post.&amp;quot;&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When such a disagreement occurs, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation.  For example, when a permission is calculated in a different context, the documentation usually says so.  Other times you will just need to read the code. &lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36087</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36087"/>
		<updated>2008-05-13T15:17:55Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* The use case for rolesdebug.php */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a solid understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required that they do so.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I should be able do this, but Moodle won&#039;t let me!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are three possibilities:&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified (Moodle calculates some permissions explicitly in System or User contexts).&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission.  For example, Guest has been edited, allowing it to post to Forums,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission. If you ask a developer why, they will tell you &amp;quot;because guests can never post.&amp;quot;&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When such a disagreement occurs, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation.  For example, when a permission is calculated in a different context, the documentation usually says so.  Other times you will just need to read the code. &lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36085</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=36085"/>
		<updated>2008-05-13T15:16:47Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* The use case for rolesdebug.php */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a solid understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I should be able do this, but Moodle won&#039;t let me!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are three possibilities:&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified (Moodle calculates some permissions explicitly in System or User contexts).&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission.  For example, Guest has been edited, allowing it to post to Forums,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission. If you ask a developer why, they will tell you &amp;quot;because guests can never post.&amp;quot;&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When such a disagreement occurs, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation.  For example, when a permission is calculated in a different context, the documentation usually says so.  Other times you will just need to read the code. &lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=36016</id>
		<title>Roles FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=Roles_FAQ&amp;diff=36016"/>
		<updated>2008-05-12T13:09:20Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* What is my role here? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
&lt;br /&gt;
==What is the definition of a...==&lt;br /&gt;
&lt;br /&gt;
;Role&lt;br /&gt;
:An identifier of the user&#039;s status in some context, for example Teacher, Student and Forum moderator&lt;br /&gt;
;Capability&lt;br /&gt;
:A description of a particular Moodle feature, for example [[Capabilities/moodle/blog:create|moodle/blog:create]]&lt;br /&gt;
;Permission&lt;br /&gt;
:A setting for a capability - inherit, allow, prevent or prohibit&lt;br /&gt;
;Context&lt;br /&gt;
:A &amp;quot;space&amp;quot; in Moodle, such as courses, activity modules or blocks&lt;br /&gt;
&lt;br /&gt;
==Why isn&#039;t my role change taking effect?==&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.7.x and 1.8.x, role assignments and overrides do not take effect immediately.  They are delayed until the next time the user logs in.  Starting with Moodle 1.9, explicit role assignments and overrides take effect immediately. However role assignments resulting from changes to certain user policies (for example, changing the default front page role) may be delayed until the next login.&lt;br /&gt;
&lt;br /&gt;
If you are testing a new role, [[Manage_roles#Testing_a_new_role | here are some suggestions]].&lt;br /&gt;
&lt;br /&gt;
Also, please check the context in which the role is assigned. Certain capabilities e.g. [[Capabilities/moodle/user:update|moodle/user:update]] may only be applied in the system context, so assigning a role in the course context will result in the role change not taking effect.&lt;br /&gt;
&lt;br /&gt;
==Why are participants being added automatically when a new course is created?==&lt;br /&gt;
&lt;br /&gt;
If a user is assigned a system role or a role in the course category context then the user has this role in ALL courses in that context. Thus users who are students or teachers at the category level appear as course participants in all courses in that category.&lt;br /&gt;
&lt;br /&gt;
Please check &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Assign system roles&#039;&#039; and also the Assign roles link in course categories page and unassign users as necessary.&lt;br /&gt;
&lt;br /&gt;
==Why are all students enrolled in all courses?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
*Users are assigned the role of student in the site/system context rather than the course context (see FAQ above)&lt;br /&gt;
Or&lt;br /&gt;
*The default role for all users in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; User policies&#039;&#039; is set to Student rather than Authenticated user (Moodle 1.8 onwards).&lt;br /&gt;
&lt;br /&gt;
==Why are there differences in the users listed as course participants and users assigned roles in a course?==&lt;br /&gt;
&lt;br /&gt;
Users assigned roles in a higher context, for example users assigned the role of teacher in a course category context, may appear as course participants. The discussion [http://moodle.org/mod/forum/discuss.php?d=59900 Discrepancies between Assign Roles lists and Participants list] contains a longer explanation. &lt;br /&gt;
&lt;br /&gt;
==How can I prevent administrators being listed as course participants?==&lt;br /&gt;
&lt;br /&gt;
Ensure that administrators are not assigned another role in addition to their admin role.&lt;br /&gt;
&lt;br /&gt;
==Why are hidden assignments still visible?==&lt;br /&gt;
&lt;br /&gt;
Hidden assignments are not hidden from admins or teachers i.e. users with the [[Capabilities/moodle/role:viewhiddenassigns|viewhiddenassigns capability]].&lt;br /&gt;
&lt;br /&gt;
==Where are permissions inherited from?==&lt;br /&gt;
&lt;br /&gt;
Permissions are inherited from a role assigned in a higher-level context which has permissions set to allow for particular capabilities. If permission is &amp;quot;Not set&amp;quot; in any context and not allowed in any higher context (in particular, if you are creating or editing a role at the site level), then a user will have no permission for that capability.&lt;br /&gt;
&lt;br /&gt;
For example, the Student role has permission not set for the change site configuration capability. The permission is never allowed in any context so users assigned the role of Student cannot change the site configuration.&lt;br /&gt;
&lt;br /&gt;
==What is my role here?==&lt;br /&gt;
&lt;br /&gt;
This is a frequently asked question, but an improper one.  The correct question is &amp;quot;What are my &#039;&#039;permissions&#039;&#039; here?&amp;quot;  In any given context, you often have two or more roles.  In addition, one or more role overrides may be in effect.  Your permissions in a given context are a result of &amp;quot;adding&amp;quot; the individual permissions from these roles and overrides according to certain rules.  As Tim Hunt writes in [http://moodle.org/mod/forum/discuss.php?d=90140 this discussion], the rules &amp;quot;normally do what you expect.&amp;quot;  However when permissions conflict, the results can be surprising, and it pays to understand [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How do I debug a roles-related problem?==&lt;br /&gt;
&lt;br /&gt;
If you&#039;re having a problem that you suspect is related to roles, consider using [[The rolesdebug.php roles debugging script | the rolesdebug.php roles debugging script]].  You can download it from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and plugins database].  The script gives you a spatial view of your role assignments and overrides in a given context, and analyzes your permissions there.  To interpret the output requires a basic understanding of roles and capabilities.  If you are a complete roles novice, run the script and post the output to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities Forum].&lt;br /&gt;
&lt;br /&gt;
==Are there any differences in Roles in Moodle 1.7 and 1.8?==&lt;br /&gt;
&lt;br /&gt;
In addition to many Roles fixes and refinements (see the list of [http://tracker.moodle.org/secure/IssueNavigator.jspa?mode=hide&amp;amp;requestId=10221 Roles improvements] in the Tracker), in Moodle 1.8 the &#039;&#039;system&#039;&#039; context is separated from the &#039;&#039;front page&#039;&#039; context. Roles may be assigned in the front page context via &#039;&#039;Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;quot;Duplicate role&amp;quot; button has been added in Moodle 1.8, which makes creating new roles based on predefined roles much quicker.&lt;br /&gt;
&lt;br /&gt;
==How do I change the name for &amp;quot;teacher&amp;quot; in the course description?==&lt;br /&gt;
&lt;br /&gt;
Either&lt;br /&gt;
* Edit the role of Teacher via &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; and rename it. The new name will apply site-wide.&lt;br /&gt;
Or&lt;br /&gt;
* Create a duplicate teacher role with an alternative name and assign users the duplicate teacher role as appropriate in the course context. In &#039;&#039;Administration &amp;gt; Appearance &amp;gt; Course manager&#039;&#039; select the alternative name for teacher that you wish to be displayed in the course description.&lt;br /&gt;
Or&lt;br /&gt;
* One more way to do it in 1.8 is to create new &amp;quot;dummy&amp;quot; roles (no capabilities) with those names and assign them to teachers along with the real roles. In the course manager settings you can choose which roles display on the front page under each course. (The feature request [http://tracker.moodle.org/browse/MDL-9182 Ability to assign or display custom title for role of person in course] contains this further method.)&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}From Moodle 1.9 onwards, names for different roles in a course may be changed in the [[Course settings|course settings]].&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to set role overrides?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;.&lt;br /&gt;
#Edit the teacher role and change the capability [[Capabilities/moodle/role:override|moodle/role:override]] to allow.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
#Click the tab &amp;quot;Allow role overrides&amp;quot; (in &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039;).&lt;br /&gt;
#Check the appropriate box to allow a teacher to override the student role.&lt;br /&gt;
#Click the button &amp;quot;Save changes&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==How do I enable teachers to assign other teachers in a course?==&lt;br /&gt;
&lt;br /&gt;
This is disabled by default but it can be switched on by modifying the teacher&#039;s role. In &#039;&#039;Administration &amp;gt; Users &amp;gt; Permissions &amp;gt; Define roles&#039;&#039; select the &amp;quot;Allow role assignments&amp;quot; tab and tick the checkbox where Teacher and Teacher intersect.&lt;br /&gt;
&lt;br /&gt;
==Why doesn&#039;t &amp;quot;Switch role to..&amp;quot; within a course seem to work properly for a course creator?==&lt;br /&gt;
&lt;br /&gt;
This feature is intended for teachers so that they can see how their course appears for students. It doesn&#039;t work reliably outside the course.&lt;br /&gt;
&lt;br /&gt;
Further information about this feature can be found in [[Switch roles]] and the paragraph on testing a new role in [[Manage roles]].&lt;br /&gt;
&lt;br /&gt;
==Are there any example roles?==&lt;br /&gt;
&lt;br /&gt;
Yes, as follows:&lt;br /&gt;
&lt;br /&gt;
*[[Inspector role|Inspector]] - for providing external inspectors with permission to view all courses (without being required to enrol)&lt;br /&gt;
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees&lt;br /&gt;
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can&#039;t be changed&lt;br /&gt;
*[[Forum moderator role]] - for providing a user with permission in a particular forum to edit or delete forum posts, split discussions and move discussions to other forums&lt;br /&gt;
*[[Keyholder role]] - for setting the person named as holding a course [[Enrolment key|enrolment key]]&lt;br /&gt;
*[[Calendar editor role|Calendar editor]] - for providing a user with permission to add site events to the calendar&lt;br /&gt;
*[[Blogger role]] - for limiting blogging to specific users only&lt;br /&gt;
&lt;br /&gt;
==Logged-in users can&#039;t read the site news. What can I do?==&lt;br /&gt;
&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Scroll down to &#039;&#039;&#039;Forum&#039;&#039;&#039;&lt;br /&gt;
#Change the capability [[Capabilities/mod/forum:viewdiscussion|mod/forum:viewdiscussion]] to &#039;&#039;allow&#039;&#039;&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
==How do I enable logged-in users to participate in front page activities?==&lt;br /&gt;
&lt;br /&gt;
Either:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Follow the &amp;quot;Override roles&amp;quot; link&lt;br /&gt;
#Click on &amp;quot;Authenticated User&amp;quot;&lt;br /&gt;
#Change capabilities to &#039;&#039;allow&#039;&#039; for all required activities e.g. record a choice, reply to posts&lt;br /&gt;
#Click the &amp;quot;Save changes&amp;quot; button at the bottom of the page&lt;br /&gt;
&lt;br /&gt;
Note that for this to work, you need to make the default role for all users &amp;quot;authenticated user&amp;quot;. This is the default for new versions of Moodle. In older versions, the default setting is guest, so if you have recently upgraded, you may have to change this setting. You can change the setting via &#039;&#039;Site Administration &amp;gt; Permissions &amp;gt; User Policies&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Or:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page roles&#039;&#039;&lt;br /&gt;
#Click on Student&lt;br /&gt;
#Select all users in the potential users list, and use the left-facing arrow button to add them to the existing users list&lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}Or, in Moodle 1.9 onwards:&lt;br /&gt;
#Access &#039;&#039;Site Administration &amp;gt; Front Page &amp;gt; Front Page settings&#039;&#039;&lt;br /&gt;
#Set the default front page role to student.&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[es:FAQ_roles]]&lt;br /&gt;
[[fr:FAQ des rôles]]&lt;br /&gt;
[[ja:ロールFAQ]]&lt;br /&gt;
[[ru:FAQ по ролям]]&lt;br /&gt;
[[de:Rollen FAQ]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35933</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35933"/>
		<updated>2008-05-10T22:14:48Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Rolesdebug says I should be able do this, but Moodle won&amp;#039;t let me! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I should be able do this, but Moodle won&#039;t let me!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are three possibilities:&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified (Moodle calculates some permissions explicitly in System or User contexts).&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission.  For example, Guest has been edited, allowing it to post to Forums,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission. If you ask a developer why, they will tell you &amp;quot;because guests can never post.&amp;quot;&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When such a disagreement occurs, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation.  For example, when a permission is calculated in a different context, the documentation usually says so.  Other times you will just need to read the code. &lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35932</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35932"/>
		<updated>2008-05-10T22:11:56Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Rolesdebug says I can do this, but Moodle says I can&amp;#039;t! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I should be able do this, but Moodle won&#039;t let me!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are several possibilities to consider.&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified (Moodle calculates some permissions explicitly in System or User contexts).&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission.  For example, if you allow Guest it to post to a Forum,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission. If you ask a developer why, they will tell you &amp;quot;because guests can never post.&amp;quot;&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When such a disagreement occurs, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation (e.g., when a permission is calculated in a different context, the documentation usually says so), and other times you will need to read the code. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35931</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35931"/>
		<updated>2008-05-10T22:11:29Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* Rolesdebug says I can do this, but Moodle says I can&amp;#039;t! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I can do this, but Moodle says I can&#039;t!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are several possibilities to consider.&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified (Moodle calculates some permissions explicitly in System or User contexts).&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission.  For example, if you allow Guest it to post to a Forum,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission. If you ask a developer why, they will tell you &amp;quot;because guests can never post.&amp;quot;&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When such a disagreement occurs, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation (e.g., when a permission is calculated in a different context, the documentation usually says so), and other times you will need to read the code. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35930</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35930"/>
		<updated>2008-05-10T22:07:55Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php will only give you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions (unless you can login as them).  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php outputs a table giving a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
==Rolesdebug says I can do this, but Moodle says I can&#039;t!==&lt;br /&gt;
When this happens it is because Moodle is calculating your permission differently from the way you think it is.  Here are several possibilities to consider.&lt;br /&gt;
* Moodle may be calculating the permission in a &#039;&#039;different context&#039;&#039; than the one you specified.  Moodle tests some Systems explicitly in System or User contexts.&lt;br /&gt;
* If you are assigned any legacy roles (particularly Guest), Moodle may be ignoring the calculated permission in favor of preserving legacy behavior.  For example, if you allow Guest it to post to a Forum,  Rolesdebug will report that you can post, but Moodle will simply ignore the permission.&lt;br /&gt;
* The action you are attempting requires two or more permissions.&lt;br /&gt;
&lt;br /&gt;
When there is a disagreement, further research will be needed to debug the problem.  Sometimes you can find the answer in documentation (e.g., when a permission is calculated in a different context, the documentation usually says so), and other times you will need to read the code. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35929</id>
		<title>How permissions are calculated</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35929"/>
		<updated>2008-05-10T21:48:10Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* The calculation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
One of the most frequently asked question is: &#039;&#039;What are my permissions in this context?&#039;&#039; This article will document the function that Moodle uses to answer this question.  The article is written for non-programmers as well as programmers, since it describes &#039;&#039;what&#039;&#039; the function does, not &#039;&#039;how&#039;&#039;. The &#039;&#039;how&#039;&#039; is complicated. The &#039;&#039;what&#039;&#039; turns out to be relatively simple!  If you are a programmer and you insist on reading the code, look for &#039;&#039;has_capability()&#039;&#039; in &#039;&#039;lib/accesslib.php&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Given a user, a capability, and a context, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039; if the user is allowed to perform the action controlled by the capability in the given context, and &#039;&#039;false&#039;&#039; otherwise.  In calculating the permission, the function considers all of the relevant permission data, which include role definitions, assignments, and overrides.&lt;br /&gt;
&lt;br /&gt;
Moodle never calculates a user&#039;s complete set of permissions.  To do so would be very costly and also wasteful, since most permissions are never tested. Instead, Moodle calculates permissions only as needed. It does not store the permissions that it calculates, but recalculates them every time it needs to test them. This is why role assignments and overrides no longer have delayed effects, as they did in Moodle 1.7 and 1.8.&lt;br /&gt;
&lt;br /&gt;
Incidentally, you can generate permission tables like the ones in this article using [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
==The calculation==&lt;br /&gt;
&lt;br /&gt;
When a user attempts an action that is controlled by a capability, Moodle calls has_capability to see if the action should be permitted.  The function is called as follows:&lt;br /&gt;
&lt;br /&gt;
    has_capability(CAP,CONTEXT,USER);&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
*CAP is the capability that controls the action (e.g., mod/quiz:attempt)&lt;br /&gt;
*CONTEXT is the context in which the capability is being tested&lt;br /&gt;
*USER is the user attempting the action&lt;br /&gt;
&lt;br /&gt;
The function returns a true/false result&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;true&#039;&#039;  means the user should be allowed to perform the action&lt;br /&gt;
* &#039;&#039;false&#039;&#039; means the user should be prevented from perfoming the action&lt;br /&gt;
&lt;br /&gt;
===Data used by the function===&lt;br /&gt;
&lt;br /&gt;
Suppose USER is about to attempt a quiz (&#039;&#039;CAP = mod/quiz:attempt&#039;&#039;) in a Module context nested four levels deep within System.  &lt;br /&gt;
&lt;br /&gt;
      System&lt;br /&gt;
         |&lt;br /&gt;
     Category A&lt;br /&gt;
         |					      &lt;br /&gt;
    Subcategory B&lt;br /&gt;
         |&lt;br /&gt;
       Course&lt;br /&gt;
         |&lt;br /&gt;
       Quiz  &amp;lt;--- the user is here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The quiz module will call &#039;&#039;has_capability()&#039;&#039; to see if the user should be allowed to perform this action.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; considers the following permission data:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Role definitions&#039;&#039; (these are in the System context) &lt;br /&gt;
* &#039;&#039;Role assignments&#039;&#039; which may occur in any of the five contexts &lt;br /&gt;
* &#039;&#039;Role overrides&#039;&#039; which may occur in any of the contexts except System (there is no concept of override in System).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; ignores capabilities other than CAP.  This simplification lets us view each role or override as if it contains a &#039;&#039;single permission&#039;&#039; having one of the following values&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
We use the following notation: for a role &#039;&#039;R1&#039;&#039; with permission &#039;&#039;P&#039;&#039;, we write &#039;&#039;R1(P)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===An example===&lt;br /&gt;
&lt;br /&gt;
In the quiz example, suppose that the user has four roles (&#039;&#039;R1&#039;&#039;, &#039;&#039;R2&#039;&#039;, &#039;&#039;R3&#039;&#039;, and &#039;&#039;R4&#039;&#039;) and each of the roles has been assigned and overridden as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define R1(A), R2(N), R3(N), R4(P)&lt;br /&gt;
            |               assign R1&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A    &amp;lt;-------------- overide R1(N) and R4(N)&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign R2 and R3&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;-------------- override R2(X) and R3(A)&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4     Quiz        &amp;lt;---- assign R4 and R1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;R1&#039;&#039; has been assigned in two different contexts. This is an unusual practice (it is probably someone&#039;s error), but since it is legal, we have to consider the possibility that it can happen.  In fact this entire example has been contrived to explore the edge cases of the algorithm.  In practice, the calculation of permissions is trivial and the function calculates the result you would expect based on common sense and simple mental analysis (for further discussion of this, see [[#A note about the algorithm|A note about the algorithm]] near the end of this article.&lt;br /&gt;
&lt;br /&gt;
===Representing the data in tabular form===&lt;br /&gt;
&lt;br /&gt;
We will set up a table to hold the permission data.  The table has&lt;br /&gt;
*a column for each context, ordered from highest level (System) to lowest (the context where we want to compute the permission).&lt;br /&gt;
*a row for each context, also listed from highest to lowest.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-3A.png|Empty table]]&lt;br /&gt;
&lt;br /&gt;
The role definitions go in the first row.  Put each definition in the column(s) coresponding to the context(s) in which the role is assigned: &lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-5A.png|Table with assignments added]]&lt;br /&gt;
&lt;br /&gt;
The overrides go in the remaining rows.  Each override goes&lt;br /&gt;
*in the same column as the role being overridden&lt;br /&gt;
*in the row corresponding the context in which the override is made.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s add just one of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-6A.png|Table with just one override]]&lt;br /&gt;
&lt;br /&gt;
R2(X) represents the override to role R2 made in the course context.  Let&#039;s add the rest of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-7A.png|Table with remaining overrides shown]]&lt;br /&gt;
&lt;br /&gt;
The table is now fully populated, and we are ready to calculate the permission.&lt;br /&gt;
&lt;br /&gt;
===The algorithm===&lt;br /&gt;
&lt;br /&gt;
The algorithm follows a path through the table indicated by nodes and arrows in the diagram below and stops as soon as it has a conclusive result.&lt;br /&gt;
&lt;br /&gt;
[[Image:Algorithm_path_through_permission_table_A.png|Algorithm path through permissions data]]&lt;br /&gt;
&lt;br /&gt;
# If there is an X anywhere in the table, STOP.  The calculated permission is &#039;&#039;X&#039;&#039;&lt;br /&gt;
# Go to the START node&lt;br /&gt;
# If there is no next node, STOP.  The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
# Otherwise, follow the arrow to the next node&lt;br /&gt;
#Add the permissions in the node using the numerical equivalents: N = 0, A = +1, P = -1&lt;br /&gt;
#* If the sum is positive, STOP. The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
#* If the sum is negative, STOP. The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
#* If the sum is zero, GO TO step 3 &lt;br /&gt;
&lt;br /&gt;
Notice that the algorithm stops when either (1) a conclusive result is obtained, or (2) the algorithm reaches the last node without a conclusive result.&lt;br /&gt;
&lt;br /&gt;
===Applying the algorithm to our example===&lt;br /&gt;
&lt;br /&gt;
If we execute the algorithm with the quiz data, we stop at step 1 with a calculated permission of X.  That&#039;s not very interesting, so let&#039;s change the X to a P and see what happens:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-8A.png|Change X to P in permission table]]&lt;br /&gt;
&lt;br /&gt;
Run the algorithm:&lt;br /&gt;
&lt;br /&gt;
*There is No X in the table&lt;br /&gt;
*Go to the START node&lt;br /&gt;
*Go to the next node&lt;br /&gt;
*N + N = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*P + A = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*N = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A = +1&lt;br /&gt;
*the sum is positive; STOP.  The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If the calculated permission is &#039;&#039;A&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039;, and the user is allowed to perform the action.&lt;br /&gt;
&lt;br /&gt;
Had the calculated permission been &#039;&#039;P&#039;&#039; or &#039;&#039;X&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; would not immediately return &#039;&#039;false&#039;&#039;. Rather, it would test if the user has &#039;&#039;moodle/site:doanything = Allow&#039;&#039; (since this permission trumps all others). The function does this by calling itself: &lt;br /&gt;
&lt;br /&gt;
    final result = has_capability(moodle/site:doanything,CONTEXT, USER);&lt;br /&gt;
&lt;br /&gt;
==A note about the algorithm==&lt;br /&gt;
&lt;br /&gt;
Earlier, we said that the algorithm &amp;quot;calculates the result you would expect.&amp;quot; But what do we expect?  Intuition tells us that permissions closer to the user should carry more weight than more distant permissions.  That&#039;s why we set up the table the way we did and why the algorithm walks the table in the order that it does.  The last column of the table represents the role assignment(s) closest to the user.  The second-to-last column represents the role assignent(s) that are next in terms of distance from the user, and so-on.  That&#039;s why the algorithm considers the columns from right-to-left.  Within a column, the algorithm searches upward in order to give higher weight to overrides that are closer to the user.  Once again, this matches our intuition about overrides.  If there are no overrides in a column (or the overrides are all Not set), the permission in the role definition is used.&lt;br /&gt;
&lt;br /&gt;
==Getting the result you expect==&lt;br /&gt;
&lt;br /&gt;
The calculation is more likely to give &amp;quot;the result you would expect&amp;quot; if you keep your permissions as simple as possible.  Therefore, we recommend the following &#039;rules&#039; for defining and overriding roles. If you understand the description of the calculation above, you should understand why they make sense.&lt;br /&gt;
&lt;br /&gt;
===When defining roles===&lt;br /&gt;
&lt;br /&gt;
... use Allow (A) for things you want the role to be able to do, and use Not set (N) for things you don&#039;t care about (which should include most things).&lt;br /&gt;
&lt;br /&gt;
===When overriding permissions===&lt;br /&gt;
&lt;br /&gt;
... leave the permission for every capability as Inherit (N) apart from the few you want to change. For those, use Allow (A) for things you want to allow, and Prevent (P) for things you want to prevent.&lt;br /&gt;
&lt;br /&gt;
===Only use prohibit in special roles===&lt;br /&gt;
&lt;br /&gt;
Prohibit exists to cover extreme scenarios such as the following: Suppose you have a naughty student who is posting inappropriate content in your Moodle site. You need to be able to remove their ability to contribute to public discussions until they have promised not to do it again, but during that time, you cannot completely block them from the resources, quizzes, etc. because they must keep up with their studying. Therefore, you need a way to block their access to specific capabilities e.g.  mod/forum:replypost in a way that cannot be overridden. You can do this by creating a special &#039;Naughty student&#039; role defined with the required permission(s) set to prohibit. Then when you are having problems with a user, you can temporarily assign them this role, either at site level or at course level.&lt;br /&gt;
&lt;br /&gt;
==A practical example==&lt;br /&gt;
&lt;br /&gt;
Suppose that a user, who is assigned the role of Course creator in category B, creates a course (becoming Teacher in the course) and then creates a Lesson within the course.  The user is about to edit the lesson (editing lessons is controlled by capability &#039;&#039;mod/lesson:edit&#039;&#039;).  Here is the permission data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define Auth user(N), Creator(N), Teacher(A)&lt;br /&gt;
            |               assign Auth user&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign Creator&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;---- assign Teacher&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4    Lesson       &amp;lt;---- user attempts to edit lesson&lt;br /&gt;
&lt;br /&gt;
We set up the table and populate it with permission data.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-10A.png|A practical example]]&lt;br /&gt;
&lt;br /&gt;
Since there are no overrides, the table only has data in the first row.  The algorithm quickly calculates a permission of &#039;&#039;A&#039;&#039; and returns true.  The user is allowed to edit the Lesson!&lt;br /&gt;
&lt;br /&gt;
Now suppose Teacher is overridden in the Lesson context with &#039;&#039;mod/lesson:edit = P&#039;&#039;.  Then the table changes&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-11A.png|A practical example with first override]]&lt;br /&gt;
&lt;br /&gt;
and clearly the user is no longer allowed to edit the Lesson.&lt;br /&gt;
&lt;br /&gt;
But suppose the administrator (or whoever is making the overrides) decided instead to override the &#039;&#039;Creator role&#039;&#039;, setting &#039;&#039;mod/lesson:edit = Prevent&#039;&#039; in the Categoy B context:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-12A.png|A practical example with second override]]             &lt;br /&gt;
&lt;br /&gt;
Much to everyone&#039;s surprise, the user is still allowed to edit the Lesson!  If you understood this article, you shouldn&#039;t be surprised, and you should be able to explain what happened.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=90140 Logged in: what role am I?] and [http://moodle.org/mod/forum/discuss.php?d=66782 What happens if a user has multiple roles in a course?] forum discussions.  &lt;br /&gt;
&lt;br /&gt;
There is a script that you can use to create tables like the ones in this article.  It is very useful for debugging roles-related problems.  See [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Comment les permissions sont calculées ?]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35928</id>
		<title>How permissions are calculated</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35928"/>
		<updated>2008-05-10T21:46:45Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* The calculation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
One of the most frequently asked question is: &#039;&#039;What are my permissions in this context?&#039;&#039; This article will document the function that Moodle uses to answer this question.  The article is written for non-programmers as well as programmers, since it describes &#039;&#039;what&#039;&#039; the function does, not &#039;&#039;how&#039;&#039;. The &#039;&#039;how&#039;&#039; is complicated. The &#039;&#039;what&#039;&#039; turns out to be relatively simple!  If you are a programmer and you insist on reading the code, look for &#039;&#039;has_capability()&#039;&#039; in &#039;&#039;lib/accesslib.php&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Given a user, a capability, and a context, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039; if the user is allowed to perform the action controlled by the capability in the given context, and &#039;&#039;false&#039;&#039; otherwise.  In calculating the permission, the function considers all of the relevant permission data, which include role definitions, assignments, and overrides.&lt;br /&gt;
&lt;br /&gt;
Moodle never calculates a user&#039;s complete set of permissions.  To do so would be very costly and also wasteful, since most permissions are never tested. Instead, Moodle calculates permissions only as needed. It does not store the permissions that it calculates, but recalculates them every time it needs to test them. This is why role assignments and overrides no longer have delayed effects, as they did in Moodle 1.7 and 1.8.&lt;br /&gt;
&lt;br /&gt;
Incidentally, you can generate permission tables like the ones in this article using [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
==The calculation==&lt;br /&gt;
&lt;br /&gt;
When a user attempts an action that is controlled by a capability, Moodle calls has_capability to see if you have permission.  The function is called as follows:&lt;br /&gt;
&lt;br /&gt;
    has_capability(CAP,CONTEXT,USER);&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
*CAP is the capability that controls the action (e.g., mod/quiz:attempt)&lt;br /&gt;
*CONTEXT is the context in which the capability is being tested&lt;br /&gt;
*USER is the user attempting the action&lt;br /&gt;
&lt;br /&gt;
The function returns a true/false result&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;true&#039;&#039;  means the user should be allowed to perform the action&lt;br /&gt;
* &#039;&#039;false&#039;&#039; means the user should be prevented from perfoming the action&lt;br /&gt;
&lt;br /&gt;
===Data used by the function===&lt;br /&gt;
&lt;br /&gt;
Suppose USER is about to attempt a quiz (&#039;&#039;CAP = mod/quiz:attempt&#039;&#039;) in a Module context nested four levels deep within System.  &lt;br /&gt;
&lt;br /&gt;
      System&lt;br /&gt;
         |&lt;br /&gt;
     Category A&lt;br /&gt;
         |					      &lt;br /&gt;
    Subcategory B&lt;br /&gt;
         |&lt;br /&gt;
       Course&lt;br /&gt;
         |&lt;br /&gt;
       Quiz  &amp;lt;--- the user is here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The quiz module will call &#039;&#039;has_capability()&#039;&#039; to see if the user should be allowed to perform this action.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; considers the following permission data:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Role definitions&#039;&#039; (these are in the System context) &lt;br /&gt;
* &#039;&#039;Role assignments&#039;&#039; which may occur in any of the five contexts &lt;br /&gt;
* &#039;&#039;Role overrides&#039;&#039; which may occur in any of the contexts except System (there is no concept of override in System).  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; ignores capabilities other than CAP.  This simplification lets us view each role or override as if it contains a &#039;&#039;single permission&#039;&#039; having one of the following values&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
We use the following notation: for a role &#039;&#039;R1&#039;&#039; with permission &#039;&#039;P&#039;&#039;, we write &#039;&#039;R1(P)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===An example===&lt;br /&gt;
&lt;br /&gt;
In the quiz example, suppose that the user has four roles (&#039;&#039;R1&#039;&#039;, &#039;&#039;R2&#039;&#039;, &#039;&#039;R3&#039;&#039;, and &#039;&#039;R4&#039;&#039;) and each of the roles has been assigned and overridden as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define R1(A), R2(N), R3(N), R4(P)&lt;br /&gt;
            |               assign R1&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A    &amp;lt;-------------- overide R1(N) and R4(N)&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign R2 and R3&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;-------------- override R2(X) and R3(A)&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4     Quiz        &amp;lt;---- assign R4 and R1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;R1&#039;&#039; has been assigned in two different contexts. This is an unusual practice (it is probably someone&#039;s error), but since it is legal, we have to consider the possibility that it can happen.  In fact this entire example has been contrived to explore the edge cases of the algorithm.  In practice, the calculation of permissions is trivial and the function calculates the result you would expect based on common sense and simple mental analysis (for further discussion of this, see [[#A note about the algorithm|A note about the algorithm]] near the end of this article.&lt;br /&gt;
&lt;br /&gt;
===Representing the data in tabular form===&lt;br /&gt;
&lt;br /&gt;
We will set up a table to hold the permission data.  The table has&lt;br /&gt;
*a column for each context, ordered from highest level (System) to lowest (the context where we want to compute the permission).&lt;br /&gt;
*a row for each context, also listed from highest to lowest.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-3A.png|Empty table]]&lt;br /&gt;
&lt;br /&gt;
The role definitions go in the first row.  Put each definition in the column(s) coresponding to the context(s) in which the role is assigned: &lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-5A.png|Table with assignments added]]&lt;br /&gt;
&lt;br /&gt;
The overrides go in the remaining rows.  Each override goes&lt;br /&gt;
*in the same column as the role being overridden&lt;br /&gt;
*in the row corresponding the context in which the override is made.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s add just one of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-6A.png|Table with just one override]]&lt;br /&gt;
&lt;br /&gt;
R2(X) represents the override to role R2 made in the course context.  Let&#039;s add the rest of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-7A.png|Table with remaining overrides shown]]&lt;br /&gt;
&lt;br /&gt;
The table is now fully populated, and we are ready to calculate the permission.&lt;br /&gt;
&lt;br /&gt;
===The algorithm===&lt;br /&gt;
&lt;br /&gt;
The algorithm follows a path through the table indicated by nodes and arrows in the diagram below and stops as soon as it has a conclusive result.&lt;br /&gt;
&lt;br /&gt;
[[Image:Algorithm_path_through_permission_table_A.png|Algorithm path through permissions data]]&lt;br /&gt;
&lt;br /&gt;
# If there is an X anywhere in the table, STOP.  The calculated permission is &#039;&#039;X&#039;&#039;&lt;br /&gt;
# Go to the START node&lt;br /&gt;
# If there is no next node, STOP.  The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
# Otherwise, follow the arrow to the next node&lt;br /&gt;
#Add the permissions in the node using the numerical equivalents: N = 0, A = +1, P = -1&lt;br /&gt;
#* If the sum is positive, STOP. The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
#* If the sum is negative, STOP. The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
#* If the sum is zero, GO TO step 3 &lt;br /&gt;
&lt;br /&gt;
Notice that the algorithm stops when either (1) a conclusive result is obtained, or (2) the algorithm reaches the last node without a conclusive result.&lt;br /&gt;
&lt;br /&gt;
===Applying the algorithm to our example===&lt;br /&gt;
&lt;br /&gt;
If we execute the algorithm with the quiz data, we stop at step 1 with a calculated permission of X.  That&#039;s not very interesting, so let&#039;s change the X to a P and see what happens:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-8A.png|Change X to P in permission table]]&lt;br /&gt;
&lt;br /&gt;
Run the algorithm:&lt;br /&gt;
&lt;br /&gt;
*There is No X in the table&lt;br /&gt;
*Go to the START node&lt;br /&gt;
*Go to the next node&lt;br /&gt;
*N + N = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*P + A = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*N = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A = +1&lt;br /&gt;
*the sum is positive; STOP.  The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If the calculated permission is &#039;&#039;A&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039;, and the user is allowed to perform the action.&lt;br /&gt;
&lt;br /&gt;
Had the calculated permission been &#039;&#039;P&#039;&#039; or &#039;&#039;X&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; would not immediately return &#039;&#039;false&#039;&#039;. Rather, it would test if the user has &#039;&#039;moodle/site:doanything = Allow&#039;&#039; (since this permission trumps all others). The function does this by calling itself: &lt;br /&gt;
&lt;br /&gt;
    final result = has_capability(moodle/site:doanything,CONTEXT, USER);&lt;br /&gt;
&lt;br /&gt;
==A note about the algorithm==&lt;br /&gt;
&lt;br /&gt;
Earlier, we said that the algorithm &amp;quot;calculates the result you would expect.&amp;quot; But what do we expect?  Intuition tells us that permissions closer to the user should carry more weight than more distant permissions.  That&#039;s why we set up the table the way we did and why the algorithm walks the table in the order that it does.  The last column of the table represents the role assignment(s) closest to the user.  The second-to-last column represents the role assignent(s) that are next in terms of distance from the user, and so-on.  That&#039;s why the algorithm considers the columns from right-to-left.  Within a column, the algorithm searches upward in order to give higher weight to overrides that are closer to the user.  Once again, this matches our intuition about overrides.  If there are no overrides in a column (or the overrides are all Not set), the permission in the role definition is used.&lt;br /&gt;
&lt;br /&gt;
==Getting the result you expect==&lt;br /&gt;
&lt;br /&gt;
The calculation is more likely to give &amp;quot;the result you would expect&amp;quot; if you keep your permissions as simple as possible.  Therefore, we recommend the following &#039;rules&#039; for defining and overriding roles. If you understand the description of the calculation above, you should understand why they make sense.&lt;br /&gt;
&lt;br /&gt;
===When defining roles===&lt;br /&gt;
&lt;br /&gt;
... use Allow (A) for things you want the role to be able to do, and use Not set (N) for things you don&#039;t care about (which should include most things).&lt;br /&gt;
&lt;br /&gt;
===When overriding permissions===&lt;br /&gt;
&lt;br /&gt;
... leave the permission for every capability as Inherit (N) apart from the few you want to change. For those, use Allow (A) for things you want to allow, and Prevent (P) for things you want to prevent.&lt;br /&gt;
&lt;br /&gt;
===Only use prohibit in special roles===&lt;br /&gt;
&lt;br /&gt;
Prohibit exists to cover extreme scenarios such as the following: Suppose you have a naughty student who is posting inappropriate content in your Moodle site. You need to be able to remove their ability to contribute to public discussions until they have promised not to do it again, but during that time, you cannot completely block them from the resources, quizzes, etc. because they must keep up with their studying. Therefore, you need a way to block their access to specific capabilities e.g.  mod/forum:replypost in a way that cannot be overridden. You can do this by creating a special &#039;Naughty student&#039; role defined with the required permission(s) set to prohibit. Then when you are having problems with a user, you can temporarily assign them this role, either at site level or at course level.&lt;br /&gt;
&lt;br /&gt;
==A practical example==&lt;br /&gt;
&lt;br /&gt;
Suppose that a user, who is assigned the role of Course creator in category B, creates a course (becoming Teacher in the course) and then creates a Lesson within the course.  The user is about to edit the lesson (editing lessons is controlled by capability &#039;&#039;mod/lesson:edit&#039;&#039;).  Here is the permission data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define Auth user(N), Creator(N), Teacher(A)&lt;br /&gt;
            |               assign Auth user&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign Creator&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;---- assign Teacher&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4    Lesson       &amp;lt;---- user attempts to edit lesson&lt;br /&gt;
&lt;br /&gt;
We set up the table and populate it with permission data.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-10A.png|A practical example]]&lt;br /&gt;
&lt;br /&gt;
Since there are no overrides, the table only has data in the first row.  The algorithm quickly calculates a permission of &#039;&#039;A&#039;&#039; and returns true.  The user is allowed to edit the Lesson!&lt;br /&gt;
&lt;br /&gt;
Now suppose Teacher is overridden in the Lesson context with &#039;&#039;mod/lesson:edit = P&#039;&#039;.  Then the table changes&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-11A.png|A practical example with first override]]&lt;br /&gt;
&lt;br /&gt;
and clearly the user is no longer allowed to edit the Lesson.&lt;br /&gt;
&lt;br /&gt;
But suppose the administrator (or whoever is making the overrides) decided instead to override the &#039;&#039;Creator role&#039;&#039;, setting &#039;&#039;mod/lesson:edit = Prevent&#039;&#039; in the Categoy B context:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-12A.png|A practical example with second override]]             &lt;br /&gt;
&lt;br /&gt;
Much to everyone&#039;s surprise, the user is still allowed to edit the Lesson!  If you understood this article, you shouldn&#039;t be surprised, and you should be able to explain what happened.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=90140 Logged in: what role am I?] and [http://moodle.org/mod/forum/discuss.php?d=66782 What happens if a user has multiple roles in a course?] forum discussions.  &lt;br /&gt;
&lt;br /&gt;
There is a script that you can use to create tables like the ones in this article.  It is very useful for debugging roles-related problems.  See [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Comment les permissions sont calculées ?]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35927</id>
		<title>How permissions are calculated</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35927"/>
		<updated>2008-05-10T21:35:19Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
One of the most frequently asked question is: &#039;&#039;What are my permissions in this context?&#039;&#039; This article will document the function that Moodle uses to answer this question.  The article is written for non-programmers as well as programmers, since it describes &#039;&#039;what&#039;&#039; the function does, not &#039;&#039;how&#039;&#039;. The &#039;&#039;how&#039;&#039; is complicated. The &#039;&#039;what&#039;&#039; turns out to be relatively simple!  If you are a programmer and you insist on reading the code, look for &#039;&#039;has_capability()&#039;&#039; in &#039;&#039;lib/accesslib.php&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Given a user, a capability, and a context, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039; if the user is allowed to perform the action controlled by the capability in the given context, and &#039;&#039;false&#039;&#039; otherwise.  In calculating the permission, the function considers all of the relevant permission data, which include role definitions, assignments, and overrides.&lt;br /&gt;
&lt;br /&gt;
Moodle never calculates a user&#039;s complete set of permissions.  To do so would be very costly and also wasteful, since most permissions are never tested. Instead, Moodle calculates permissions only as needed. It does not store the permissions that it calculates, but recalculates them every time it needs to test them. This is why role assignments and overrides no longer have delayed effects, as they did in Moodle 1.7 and 1.8.&lt;br /&gt;
&lt;br /&gt;
Incidentally, you can generate permission tables like the ones in this article using [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
==The calculation==&lt;br /&gt;
&lt;br /&gt;
The function is called as follows:&lt;br /&gt;
&lt;br /&gt;
    has_capability(CAP,CONTEXT,USER);&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
*CAP is the capability being tested (e.g., mod/quiz:attempt)&lt;br /&gt;
*CONTEXT can be System context or some context nested arbitrarily deeply within System. Internally, the function uses Unix-style paths to represent contexts (e.g., /1/3/4/150), but such details do not concern us here&lt;br /&gt;
*USER is the user.&lt;br /&gt;
&lt;br /&gt;
The function returns a true/false result&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;true&#039;&#039;  means the user should be allowed to perform the action&lt;br /&gt;
* &#039;&#039;false&#039;&#039; means the user should be prevented from perfoming the action&lt;br /&gt;
&lt;br /&gt;
===Data used by the function===&lt;br /&gt;
&lt;br /&gt;
Suppose USER is about to attempt a quiz (&#039;&#039;CAP = mod/quiz:attempt&#039;&#039;) in a Module context nested four levels deep within System.  &lt;br /&gt;
&lt;br /&gt;
      System&lt;br /&gt;
         |&lt;br /&gt;
     Category A&lt;br /&gt;
         |					      &lt;br /&gt;
    Subcategory B&lt;br /&gt;
         |&lt;br /&gt;
       Course&lt;br /&gt;
         |&lt;br /&gt;
       Quiz  &amp;lt;--- the user is here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The quiz module will call &#039;&#039;has_capability()&#039;&#039; to see if the user should be allowed to perform this action.&lt;br /&gt;
&lt;br /&gt;
The function considers the following permissions data:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Role definitions&#039;&#039; (these are in the System context) &lt;br /&gt;
* &#039;&#039;Role assignments&#039;&#039; which have been made in any of the five contexts &lt;br /&gt;
* &#039;&#039;Role overrides&#039;&#039; which may occur in any of the contexts except System (there is no concept of override in System).  &lt;br /&gt;
&lt;br /&gt;
Note that there may be multiple assignments and/or overrides in any single context.  &lt;br /&gt;
&lt;br /&gt;
Whether or not the user can attempt the quiz is a function of the permissions data, as well as the location of the data in the context chain.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; considers all roles and overrides that impact USER in CONTEXT, but it ignores capabilities other than CAP.  This simplification lets us view each role or override as a &#039;&#039;single permission&#039;&#039; having one of the following values&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
We use the following notation: for a role &#039;&#039;R1&#039;&#039; with permission &#039;&#039;P&#039;&#039;, we write &#039;&#039;R1(P)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===An example===&lt;br /&gt;
&lt;br /&gt;
In the quiz example, suppose that the user has four roles (&#039;&#039;R1&#039;&#039;, &#039;&#039;R2&#039;&#039;, &#039;&#039;R3&#039;&#039;, and &#039;&#039;R4&#039;&#039;) and each of the roles has been assigned and overridden as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define R1(A), R2(N), R3(N), R4(P)&lt;br /&gt;
            |               assign R1&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A    &amp;lt;-------------- overide R1(N) and R4(N)&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign R2 and R3&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;-------------- override R2(X) and R3(A)&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4     Quiz        &amp;lt;---- assign R4 and R1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;R1&#039;&#039; has been assigned in two different contexts. This is an unusual practice (it is probably someone&#039;s error), but since it is legal, we have to consider the possibility that it can happen.  In fact this entire example has been contrived to explore the edge cases of the algorithm.  In practice, the calculation of permissions is trivial and the function calculates the result you would expect based on common sense and simple mental analysis (for further discussion of this, see [[#A note about the algorithm|A note about the algorithm]] near the end of this article.&lt;br /&gt;
&lt;br /&gt;
===Representing the data in tabular form===&lt;br /&gt;
&lt;br /&gt;
We will set up a table to hold the permission data.  The table has&lt;br /&gt;
*a column for each context, ordered from highest level (System) to lowest (the context where we want to compute the permission).&lt;br /&gt;
*a row for each context, also listed from highest to lowest.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-3A.png|Empty table]]&lt;br /&gt;
&lt;br /&gt;
The role definitions go in the first row.  Put each definition in the column(s) coresponding to the context(s) in which the role is assigned: &lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-5A.png|Table with assignments added]]&lt;br /&gt;
&lt;br /&gt;
The overrides go in the remaining rows.  Each override goes&lt;br /&gt;
*in the same column as the role being overridden&lt;br /&gt;
*in the row corresponding the context in which the override is made.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s add just one of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-6A.png|Table with just one override]]&lt;br /&gt;
&lt;br /&gt;
R2(X) represents the override to role R2 made in the course context.  Let&#039;s add the rest of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-7A.png|Table with remaining overrides shown]]&lt;br /&gt;
&lt;br /&gt;
The table is now fully populated, and we are ready to calculate the permission.&lt;br /&gt;
&lt;br /&gt;
===The algorithm===&lt;br /&gt;
&lt;br /&gt;
The algorithm follows a path through the table indicated by nodes and arrows in the diagram below and stops as soon as it has a conclusive result.&lt;br /&gt;
&lt;br /&gt;
[[Image:Algorithm_path_through_permission_table_A.png|Algorithm path through permissions data]]&lt;br /&gt;
&lt;br /&gt;
# If there is an X anywhere in the table, STOP.  The calculated permission is &#039;&#039;X&#039;&#039;&lt;br /&gt;
# Go to the START node&lt;br /&gt;
# If there is no next node, STOP.  The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
# Otherwise, follow the arrow to the next node&lt;br /&gt;
#Add the permissions in the node using the numerical equivalents: N = 0, A = +1, P = -1&lt;br /&gt;
#* If the sum is positive, STOP. The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
#* If the sum is negative, STOP. The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
#* If the sum is zero, GO TO step 3 &lt;br /&gt;
&lt;br /&gt;
Notice that the algorithm stops when either (1) a conclusive result is obtained, or (2) the algorithm reaches the last node without a conclusive result.&lt;br /&gt;
&lt;br /&gt;
===Applying the algorithm to our example===&lt;br /&gt;
&lt;br /&gt;
If we execute the algorithm with the quiz data, we stop at step 1 with a calculated permission of X.  That&#039;s not very interesting, so let&#039;s change the X to a P and see what happens:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-8A.png|Change X to P in permission table]]&lt;br /&gt;
&lt;br /&gt;
Run the algorithm:&lt;br /&gt;
&lt;br /&gt;
*There is No X in the table&lt;br /&gt;
*Go to the START node&lt;br /&gt;
*Go to the next node&lt;br /&gt;
*N + N = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*P + A = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*N = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A = +1&lt;br /&gt;
*the sum is positive; STOP.  The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If the calculated permission is &#039;&#039;A&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039;, and the user is allowed to perform the action.&lt;br /&gt;
&lt;br /&gt;
Had the calculated permission been &#039;&#039;P&#039;&#039; or &#039;&#039;X&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; would not immediately return &#039;&#039;false&#039;&#039;. Rather, it would test if the user has &#039;&#039;moodle/site:doanything = Allow&#039;&#039; (since this permission trumps all others). The function does this by calling itself: &lt;br /&gt;
&lt;br /&gt;
    final result = has_capability(moodle/site:doanything,CONTEXT, USER);&lt;br /&gt;
&lt;br /&gt;
==A note about the algorithm==&lt;br /&gt;
&lt;br /&gt;
Earlier, we said that the algorithm &amp;quot;calculates the result you would expect.&amp;quot; But what do we expect?  Intuition tells us that permissions closer to the user should carry more weight than more distant permissions.  That&#039;s why we set up the table the way we did and why the algorithm walks the table in the order that it does.  The last column of the table represents the role assignment(s) closest to the user.  The second-to-last column represents the role assignent(s) that are next in terms of distance from the user, and so-on.  That&#039;s why the algorithm considers the columns from right-to-left.  Within a column, the algorithm searches upward in order to give higher weight to overrides that are closer to the user.  Once again, this matches our intuition about overrides.  If there are no overrides in a column (or the overrides are all Not set), the permission in the role definition is used.&lt;br /&gt;
&lt;br /&gt;
==Getting the result you expect==&lt;br /&gt;
&lt;br /&gt;
The calculation is more likely to give &amp;quot;the result you would expect&amp;quot; if you keep your permissions as simple as possible.  Therefore, we recommend the following &#039;rules&#039; for defining and overriding roles. If you understand the description of the calculation above, you should understand why they make sense.&lt;br /&gt;
&lt;br /&gt;
===When defining roles===&lt;br /&gt;
&lt;br /&gt;
... use Allow (A) for things you want the role to be able to do, and use Not set (N) for things you don&#039;t care about (which should include most things).&lt;br /&gt;
&lt;br /&gt;
===When overriding permissions===&lt;br /&gt;
&lt;br /&gt;
... leave the permission for every capability as Inherit (N) apart from the few you want to change. For those, use Allow (A) for things you want to allow, and Prevent (P) for things you want to prevent.&lt;br /&gt;
&lt;br /&gt;
===Only use prohibit in special roles===&lt;br /&gt;
&lt;br /&gt;
Prohibit exists to cover extreme scenarios such as the following: Suppose you have a naughty student who is posting inappropriate content in your Moodle site. You need to be able to remove their ability to contribute to public discussions until they have promised not to do it again, but during that time, you cannot completely block them from the resources, quizzes, etc. because they must keep up with their studying. Therefore, you need a way to block their access to specific capabilities e.g.  mod/forum:replypost in a way that cannot be overridden. You can do this by creating a special &#039;Naughty student&#039; role defined with the required permission(s) set to prohibit. Then when you are having problems with a user, you can temporarily assign them this role, either at site level or at course level.&lt;br /&gt;
&lt;br /&gt;
==A practical example==&lt;br /&gt;
&lt;br /&gt;
Suppose that a user, who is assigned the role of Course creator in category B, creates a course (becoming Teacher in the course) and then creates a Lesson within the course.  The user is about to edit the lesson (editing lessons is controlled by capability &#039;&#039;mod/lesson:edit&#039;&#039;).  Here is the permission data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define Auth user(N), Creator(N), Teacher(A)&lt;br /&gt;
            |               assign Auth user&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign Creator&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;---- assign Teacher&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4    Lesson       &amp;lt;---- user attempts to edit lesson&lt;br /&gt;
&lt;br /&gt;
We set up the table and populate it with permission data.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-10A.png|A practical example]]&lt;br /&gt;
&lt;br /&gt;
Since there are no overrides, the table only has data in the first row.  The algorithm quickly calculates a permission of &#039;&#039;A&#039;&#039; and returns true.  The user is allowed to edit the Lesson!&lt;br /&gt;
&lt;br /&gt;
Now suppose Teacher is overridden in the Lesson context with &#039;&#039;mod/lesson:edit = P&#039;&#039;.  Then the table changes&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-11A.png|A practical example with first override]]&lt;br /&gt;
&lt;br /&gt;
and clearly the user is no longer allowed to edit the Lesson.&lt;br /&gt;
&lt;br /&gt;
But suppose the administrator (or whoever is making the overrides) decided instead to override the &#039;&#039;Creator role&#039;&#039;, setting &#039;&#039;mod/lesson:edit = Prevent&#039;&#039; in the Categoy B context:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-12A.png|A practical example with second override]]             &lt;br /&gt;
&lt;br /&gt;
Much to everyone&#039;s surprise, the user is still allowed to edit the Lesson!  If you understood this article, you shouldn&#039;t be surprised, and you should be able to explain what happened.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=90140 Logged in: what role am I?] and [http://moodle.org/mod/forum/discuss.php?d=66782 What happens if a user has multiple roles in a course?] forum discussions.  &lt;br /&gt;
&lt;br /&gt;
There is a script that you can use to create tables like the ones in this article.  It is very useful for debugging roles-related problems.  See [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Comment les permissions sont calculées ?]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35509</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35509"/>
		<updated>2008-05-01T12:50:06Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too!&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35508</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35508"/>
		<updated>2008-05-01T12:49:49Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  If you don&#039;t have access to an expert, post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].  After using the script a few times, you&#039;ll be an expert too.&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35507</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35507"/>
		<updated>2008-05-01T12:47:35Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* How Moodle calculates the final permission */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  Simply post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the permission====&lt;br /&gt;
For a full explanation of how permissions are calculated, see the article [[How permissions are calculated | How permissions are calculated]]. This section merely illustrates the calculation for the examples given in this article.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
Moodle scans the table from right to left.  &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
Since the first permission it hits is an &#039;A&#039; the calculated permission is &#039;A&#039;. &lt;br /&gt;
&lt;br /&gt;
When we added the override, Moodle scans the table in a zig-zag fashion, as shown below.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
Since the first permission it hits is a &#039;P&#039; the calculated permission is &#039;P&#039;.&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35504</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35504"/>
		<updated>2008-05-01T12:26:08Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* How to read the table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  Simply post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
The calculated permission is now P, as expected.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the final permission====&lt;br /&gt;
&lt;br /&gt;
By scanning the table in a certain way, you can see how Moodle &lt;br /&gt;
arrives at its calculated permission.  You can always do this with a quick visual scan, regardless of how many role assignments and overrides the table contains.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
scan row 1 from right to left, &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
* if there is an X anywhere in the row, the operation is prevented&lt;br /&gt;
* otherwise, scan the row from right to left, ignoring N&#039;s&lt;br /&gt;
* if the first R you hit is an A, the operation is allowed&lt;br /&gt;
* if the first R value you hit is P, the operation is prevented&lt;br /&gt;
* if a column contains one or more A&#039;s AND one or more P&#039;s cancel pairs of A-P pairs until either (1) all pairs cancel or (2) you are left with one or more A&#039;s or P&#039;s.  If you are left with A&#039;s, the operation is allowed.  If you are left with P&#039;s, the operation is prevented.&lt;br /&gt;
* if your scan takes you all the way to the leftmost column and you still haven&#039;t found a conclusive result, the operation is prevented.&lt;br /&gt;
&lt;br /&gt;
When there are overrides, you do the same thing, but your scan follows a different path.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
&lt;br /&gt;
For a complete explanation of how permissions are calculated, read the article [[How permissions are calculated | How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35503</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35503"/>
		<updated>2008-05-01T12:19:32Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* How to read the output */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  Simply post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then you will see the three lines immediately after the table (5).&lt;br /&gt;
* The first line gives the calculated permission, which is based on the table.  The value can be either A (Allow) or P (Prevent).  &lt;br /&gt;
* The second line tells you if you are able to &amp;quot;do anything,&amp;quot; that is, if you have  moodle/site:doanything = Allow  (this is typically only true for administrators)&lt;br /&gt;
* The third line tells you if you can &amp;quot;do this.&amp;quot;  If you can do anything, you can obviously do this regardless of the calculated permission.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
Finally, notice that Moodle now tells us that the calculated permission is &amp;quot;false,&amp;quot; exactly as we expect.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the final permission====&lt;br /&gt;
&lt;br /&gt;
By scanning the table in a certain way, you can see how Moodle &lt;br /&gt;
arrives at its calculated permission.  You can always do this with a quick visual scan, regardless of how many role assignments and overrides the table contains.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
scan row 1 from right to left, &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
* if there is an X anywhere in the row, the operation is prevented&lt;br /&gt;
* otherwise, scan the row from right to left, ignoring N&#039;s&lt;br /&gt;
* if the first R you hit is an A, the operation is allowed&lt;br /&gt;
* if the first R value you hit is P, the operation is prevented&lt;br /&gt;
* if a column contains one or more A&#039;s AND one or more P&#039;s cancel pairs of A-P pairs until either (1) all pairs cancel or (2) you are left with one or more A&#039;s or P&#039;s.  If you are left with A&#039;s, the operation is allowed.  If you are left with P&#039;s, the operation is prevented.&lt;br /&gt;
* if your scan takes you all the way to the leftmost column and you still haven&#039;t found a conclusive result, the operation is prevented.&lt;br /&gt;
&lt;br /&gt;
When there are overrides, you do the same thing, but your scan follows a different path.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
&lt;br /&gt;
For a complete explanation of how permissions are calculated, read the article [[How permissions are calculated | How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35502</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35502"/>
		<updated>2008-05-01T11:57:02Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* STEP1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  Simply post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.  For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
However if you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in after making the change.&lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then below the table, you&#039;ll see the &lt;br /&gt;
value of the permission that Moodle calculated (5).  &amp;quot;True&amp;quot; means you are allowed to perform the action and &amp;quot;False&amp;quot; means that you are prevented from performing the action.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
Finally, notice that Moodle now tells us that the calculated permission is &amp;quot;false,&amp;quot; exactly as we expect.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the final permission====&lt;br /&gt;
&lt;br /&gt;
By scanning the table in a certain way, you can see how Moodle &lt;br /&gt;
arrives at its calculated permission.  You can always do this with a quick visual scan, regardless of how many role assignments and overrides the table contains.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
scan row 1 from right to left, &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
* if there is an X anywhere in the row, the operation is prevented&lt;br /&gt;
* otherwise, scan the row from right to left, ignoring N&#039;s&lt;br /&gt;
* if the first R you hit is an A, the operation is allowed&lt;br /&gt;
* if the first R value you hit is P, the operation is prevented&lt;br /&gt;
* if a column contains one or more A&#039;s AND one or more P&#039;s cancel pairs of A-P pairs until either (1) all pairs cancel or (2) you are left with one or more A&#039;s or P&#039;s.  If you are left with A&#039;s, the operation is allowed.  If you are left with P&#039;s, the operation is prevented.&lt;br /&gt;
* if your scan takes you all the way to the leftmost column and you still haven&#039;t found a conclusive result, the operation is prevented.&lt;br /&gt;
&lt;br /&gt;
When there are overrides, you do the same thing, but your scan follows a different path.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
&lt;br /&gt;
For a complete explanation of how permissions are calculated, read the article [[How permissions are calculated | How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35501</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35501"/>
		<updated>2008-05-01T11:55:14Z</updated>

		<summary type="html">&lt;p&gt;Jisner: /* STEP1 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  Simply post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.&lt;br /&gt;
&lt;br /&gt;
For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
If you are debugging a problem related to a change to a user policy such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role, you must logout and log back in prior to STEP 1. &lt;br /&gt;
&lt;br /&gt;
Remain logged in for the next step!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then below the table, you&#039;ll see the &lt;br /&gt;
value of the permission that Moodle calculated (5).  &amp;quot;True&amp;quot; means you are allowed to perform the action and &amp;quot;False&amp;quot; means that you are prevented from performing the action.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
Finally, notice that Moodle now tells us that the calculated permission is &amp;quot;false,&amp;quot; exactly as we expect.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the final permission====&lt;br /&gt;
&lt;br /&gt;
By scanning the table in a certain way, you can see how Moodle &lt;br /&gt;
arrives at its calculated permission.  You can always do this with a quick visual scan, regardless of how many role assignments and overrides the table contains.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
scan row 1 from right to left, &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
* if there is an X anywhere in the row, the operation is prevented&lt;br /&gt;
* otherwise, scan the row from right to left, ignoring N&#039;s&lt;br /&gt;
* if the first R you hit is an A, the operation is allowed&lt;br /&gt;
* if the first R value you hit is P, the operation is prevented&lt;br /&gt;
* if a column contains one or more A&#039;s AND one or more P&#039;s cancel pairs of A-P pairs until either (1) all pairs cancel or (2) you are left with one or more A&#039;s or P&#039;s.  If you are left with A&#039;s, the operation is allowed.  If you are left with P&#039;s, the operation is prevented.&lt;br /&gt;
* if your scan takes you all the way to the leftmost column and you still haven&#039;t found a conclusive result, the operation is prevented.&lt;br /&gt;
&lt;br /&gt;
When there are overrides, you do the same thing, but your scan follows a different path.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
&lt;br /&gt;
For a complete explanation of how permissions are calculated, read the article [[How permissions are calculated | How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35261</id>
		<title>How permissions are calculated</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35261"/>
		<updated>2008-04-27T03:42:49Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
One of the most frequently asked question is: &#039;&#039;What are my permissions in this context?&#039;&#039; This article will document the function that Moodle uses to answer this question.  The article is written for non-programmers as well as programmers, since it describes &#039;&#039;what&#039;&#039; the function does, not &#039;&#039;how&#039;&#039;. The &#039;&#039;how&#039;&#039; is very complicated. The &#039;&#039;what&#039;&#039; turns out to be relatively simple!  If you insist on reading the code, the function is named &#039;&#039;has_capability()&#039;&#039; and can be found in &#039;&#039;lib/accesslib.php&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Given a user, a capability, and a context, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039; if the user is allowed to perform the action controlled by the capability in the given context, and &#039;&#039;false&#039;&#039; otherwise.  In calculating the permission, the function considers all of the relevant permission data, which include role definitions, assignments, and overrides.&lt;br /&gt;
&lt;br /&gt;
Moodle never calculates a user&#039;s complete set of permissions.  It would be very costly to do so and also wasteful, since most of those permissions would never be tested. Instead, Moodle calculates permissions only as needed. It does not store the permissions that it calculates, but recalculates them every time it needs to test them. This is why role assignments and overrides no longer have delayed effects, as they did in Moodle 1.7 and 1.8.&lt;br /&gt;
&lt;br /&gt;
You can generate tables like the ones in this article using [[The rolesdebug.php roles debugging script]].  The tables are very helpful in debugging roles-related problems.&lt;br /&gt;
&lt;br /&gt;
==The calculation==&lt;br /&gt;
&lt;br /&gt;
The function is called as follows:&lt;br /&gt;
&lt;br /&gt;
    has_capability(CAP,CONTEXT,USER);&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
*CAP is the capability being tested (e.g., mod/quiz:attempt)&lt;br /&gt;
*CONTEXT can be System context or some context nested arbitrarily deeply within System. Internally, the function uses Unix-style paths to represent contexts (e.g., /1/3/4/150), but such details do not concern us here&lt;br /&gt;
*USER is the user.&lt;br /&gt;
&lt;br /&gt;
The function returns a true/false result&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;true&#039;&#039;  means the user should be allowed to perform the action&lt;br /&gt;
* &#039;&#039;false&#039;&#039; means the user should be prevented from perfoming the action&lt;br /&gt;
&lt;br /&gt;
===Data used by the function===&lt;br /&gt;
&lt;br /&gt;
Suppose USER is about to attempt a quiz (&#039;&#039;CAP = mod/quiz:attempt&#039;&#039;) in a Module context nested four levels deep within System.  &lt;br /&gt;
&lt;br /&gt;
      System&lt;br /&gt;
         |&lt;br /&gt;
     Category A&lt;br /&gt;
         |					      &lt;br /&gt;
    Subcategory B&lt;br /&gt;
         |&lt;br /&gt;
       Course&lt;br /&gt;
         |&lt;br /&gt;
       Quiz  &amp;lt;--- the user is here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The quiz module will call &#039;&#039;has_capability()&#039;&#039; to see if the user should be allowed to perform this action.&lt;br /&gt;
&lt;br /&gt;
The function considers the following permissions data:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Role definitions&#039;&#039; (these are in the System context) &lt;br /&gt;
* &#039;&#039;Role assignments&#039;&#039; which have been made in any of the five contexts &lt;br /&gt;
* &#039;&#039;Role overrides&#039;&#039; which may occur in any of the contexts except System (there is no concept of override in System).  &lt;br /&gt;
&lt;br /&gt;
Note that there may be multiple assignments and/or overrides in any single context.  &lt;br /&gt;
&lt;br /&gt;
Whether or not the user can attempt the quiz is a function of the permissions data, as well as the location of the data in the context chain.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; considers all roles and overrides that impact USER in CONTEXT, but it ignores capabilities other than CAP.  This simplification lets us view each role or override as a &#039;&#039;single permission&#039;&#039; having one of the following values&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
We use the following notation: for a role &#039;&#039;R1&#039;&#039; with permission &#039;&#039;P&#039;&#039;, we write &#039;&#039;R1(P)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===An example===&lt;br /&gt;
&lt;br /&gt;
In the quiz example, suppose that the user has four roles (&#039;&#039;R1&#039;&#039;, &#039;&#039;R2&#039;&#039;, &#039;&#039;R3&#039;&#039;, and &#039;&#039;R4&#039;&#039;) and each of the roles has been assigned and overridden as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define R1(A), R2(N), R3(N), R4(P)&lt;br /&gt;
            |               assign R1&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A    &amp;lt;-------------- overide R1(N) and R4(N)&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign R2 and R3&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;-------------- override R2(X) and R3(A)&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4     Quiz        &amp;lt;---- assign R4 and R1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;R1&#039;&#039; has been assigned in two different contexts. This is an unusual practice (it is probably someone&#039;s error), but since it is legal, we have to consider the possibility that it can happen.  In fact this entire example has been contrived to explore the edge cases of the algorithm.  In practice, the calculation of permissions is trivial and the function calculates the result you would expect based on common sense and simple mental analysis (for further discussion of this, see [[#A note about the algorithm|A note about the algorithm]] near the end of this article.&lt;br /&gt;
&lt;br /&gt;
===Representing the data in tabular form===&lt;br /&gt;
&lt;br /&gt;
We will set up a table to hold the permission data.  The table has&lt;br /&gt;
*a column for each context, ordered from highest level (System) to lowest (the context where we want to compute the permission).&lt;br /&gt;
*a row for each context, also listed from highest to lowest.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-3A.png|Empty table]]&lt;br /&gt;
&lt;br /&gt;
The role definitions go in the first row.  Put each definition in the column(s) coresponding to the context(s) in which the role is assigned: &lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-5A.png|Table with assignments added]]&lt;br /&gt;
&lt;br /&gt;
The overrides go in the remaining rows.  Each override goes&lt;br /&gt;
*in the same column as the role being overridden&lt;br /&gt;
*in the row corresponding the context in which the override is made.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s add just one of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-6A.png|Table with just one override]]&lt;br /&gt;
&lt;br /&gt;
R2(X) represents the override to role R2 made in the course context.  Let&#039;s add the rest of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-7A.png|Table with remaining overrides shown]]&lt;br /&gt;
&lt;br /&gt;
The table is now fully populated, and we are ready to calculate the permission.&lt;br /&gt;
&lt;br /&gt;
===The algorithm===&lt;br /&gt;
&lt;br /&gt;
The algorithm follows a path through the table indicated by nodes and arrows in the diagram below and stops as soon as it has a conclusive result.&lt;br /&gt;
&lt;br /&gt;
[[Image:Algorithm_path_through_permission_table_A.png|Algorithm path through permissions data]]&lt;br /&gt;
&lt;br /&gt;
# If there is an X anywhere in the table, STOP.  The calculated permission is &#039;&#039;X&#039;&#039;&lt;br /&gt;
# Go to the START node&lt;br /&gt;
# If there is no next node, STOP.  The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
# Otherwise, follow the arrow to the next node&lt;br /&gt;
#Add the permissions in the node using the numerical equivalents: N = 0, A = +1, P = -1&lt;br /&gt;
#* If the sum is positive, STOP. The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
#* If the sum is negative, STOP. The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
#* If the sum is zero, GO TO step 3 &lt;br /&gt;
&lt;br /&gt;
Notice that the algorithm stops when either (1) a conclusive result is obtained, or (2) the algorithm reaches the last node without a conclusive result.&lt;br /&gt;
&lt;br /&gt;
===Applying the algorithm to our example===&lt;br /&gt;
&lt;br /&gt;
If we execute the algorithm with the quiz data, we stop at step 1 with a calculated permission of X.  That&#039;s not very interesting, so let&#039;s change the X to a P and see what happens:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-8A.png|Change X to P in permission table]]&lt;br /&gt;
&lt;br /&gt;
Run the algorithm:&lt;br /&gt;
&lt;br /&gt;
*There is No X in the table&lt;br /&gt;
*Go to the START node&lt;br /&gt;
*Go to the next node&lt;br /&gt;
*N + N = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*P + A = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*N = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A = +1&lt;br /&gt;
*the sum is positive; STOP.  The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If the calculated permission is &#039;&#039;A&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039;, and the user is allowed to perform the action.&lt;br /&gt;
&lt;br /&gt;
Had the calculated permission been &#039;&#039;P&#039;&#039; or &#039;&#039;X&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; would not immediately return &#039;&#039;false&#039;&#039;. Rather, it would test if the user has &#039;&#039;moodle/site:doanything = Allow&#039;&#039; (since this permission trumps all others). The function does this by calling itself: &lt;br /&gt;
&lt;br /&gt;
    final result = has_capability(moodle/site:doanything,CONTEXT, USER);&lt;br /&gt;
&lt;br /&gt;
==A note about the algorithm==&lt;br /&gt;
&lt;br /&gt;
Earlier, we said that the algorithm &amp;quot;calculates the result you would expect.&amp;quot; But what do we expect?  Intuition tells us that permissions closer to the user should carry more weight than more distant permissions.  That&#039;s why we set up the table the way we did and why the algorithm walks the table in the order that it does.  The last column of the table represents the role assignment(s) closest to the user.  The second-to-last column represents the role assignent(s) that are next in terms of distance from the user, and so-on.  That&#039;s why the algorithm considers the columns from right-to-left.  Within a column, the algorithm searches upward in order to give higher weight to overrides that are closer to the user.  Once again, this matches our intuition about overrides.  If there are no overrides in a column (or the overrides are all Not set), the permission in the role definition is used.&lt;br /&gt;
&lt;br /&gt;
==Getting the result you expect==&lt;br /&gt;
&lt;br /&gt;
The calculation is more likely to give &amp;quot;the result you would expect&amp;quot; if you keep your permissions as simple as possible.  Therefore, we recommend the following &#039;rules&#039; for defining and overriding roles. If you understand the description of the calculation above, you should understand why they make sense.&lt;br /&gt;
&lt;br /&gt;
===When defining roles===&lt;br /&gt;
&lt;br /&gt;
... use Allow (A) for things you want the role to be able to do, and use Not set (N) for things you don&#039;t care about (which should include most things).&lt;br /&gt;
&lt;br /&gt;
===When overriding permissions===&lt;br /&gt;
&lt;br /&gt;
... leave the permission for every capability as Inherit (N) apart from the few you want to change. For those, use Allow (A) for things you want to allow, and Prevent (P) for things you want to prevent.&lt;br /&gt;
&lt;br /&gt;
===Only use prohibit in special roles===&lt;br /&gt;
&lt;br /&gt;
Prohibit exists to cover extreme scenarios such as the following: Suppose you have a naughty student who is posting inappropriate content in your Moodle site. You need to be able to remove their ability to contribute to public discussions until they have promised not to do it again, but during that time, you cannot completely block them from the resources, quizzes, etc. because they must keep up with their studying. Therefore, you need a way to block their access to specific capabilities e.g.  mod/forum:replypost in a way that cannot be overridden. You can do this by creating a special &#039;Naughty student&#039; role defined with the required permission(s) set to prohibit. Then when you are having problems with a user, you can temporarily assign them this role, either at site level or at course level.&lt;br /&gt;
&lt;br /&gt;
==A practical example==&lt;br /&gt;
&lt;br /&gt;
Suppose that a user, who is assigned the role of Course creator in category B, creates a course (becoming Teacher in the course) and then creates a Lesson within the course.  The user is about to edit the lesson (editing lessons is controlled by capability &#039;&#039;mod/lesson:edit&#039;&#039;).  Here is the permission data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define Auth user(N), Creator(N), Teacher(A)&lt;br /&gt;
            |               assign Auth user&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign Creator&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;---- assign Teacher&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4    Lesson       &amp;lt;---- user attempts to edit lesson&lt;br /&gt;
&lt;br /&gt;
We set up the table and populate it with permission data.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-10A.png|A practical example]]&lt;br /&gt;
&lt;br /&gt;
Since there are no overrides, the table only has data in the first row.  The algorithm quickly calculates a permission of &#039;&#039;A&#039;&#039; and returns true.  The user is allowed to edit the Lesson!&lt;br /&gt;
&lt;br /&gt;
Now suppose Teacher is overridden in the Lesson context with &#039;&#039;mod/lesson:edit = P&#039;&#039;.  Then the table changes&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-11A.png|A practical example with first override]]&lt;br /&gt;
&lt;br /&gt;
and clearly the user is no longer allowed to edit the Lesson.&lt;br /&gt;
&lt;br /&gt;
But suppose the administrator (or whoever is making the overrides) decided instead to override the &#039;&#039;Creator role&#039;&#039;, setting &#039;&#039;mod/lesson:edit = Prevent&#039;&#039; in the Categoy B context:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-12A.png|A practical example with second override]]             &lt;br /&gt;
&lt;br /&gt;
Much to everyone&#039;s surprise, the user is still allowed to edit the Lesson!  If you understood this article, you shouldn&#039;t be surprised, and you should be able to explain what happened.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=90140 Logged in: what role am I?] and [http://moodle.org/mod/forum/discuss.php?d=66782 What happens if a user has multiple roles in a course?] forum discussions.  &lt;br /&gt;
&lt;br /&gt;
There is a script that you can use to create tables like the ones in this article.  It is very useful for debugging roles-related problems.  See [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Comment les permissions sont calculées ?]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35260</id>
		<title>How permissions are calculated</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=How_permissions_are_calculated&amp;diff=35260"/>
		<updated>2008-04-27T03:36:29Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}&lt;br /&gt;
One of the most frequently asked question is: &#039;&#039;What permissions do I have in this context?&#039;&#039; This article will document the function that Moodle uses to answer this question.  The article is written for non-programmers as well as programmers, since it describes &#039;&#039;what&#039;&#039; the function does, not &#039;&#039;how&#039;&#039;. The &#039;&#039;how&#039;&#039; is complicated. The &#039;&#039;what&#039;&#039; turns out to be relatively simple!  In case you want to look it up, the function is named &#039;&#039;has_capability()&#039;&#039; and can be found in &#039;&#039;lib/accesslib.php&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
Given a user, a capability, and a context, the function returns &#039;&#039;true&#039;&#039; if the user is allowed to perform the action controlled by the capability in the given context, and &#039;&#039;false&#039;&#039; otherwise.  In calculating the permission, the function considers all of the relevant permission data, which include role definitions, assignments, and overrides.&lt;br /&gt;
&lt;br /&gt;
Notice that the function does not actually answer the big question posed in the first sentence of this article. Moodle never calculates a user&#039;s complete set of permissions.  It would be very costly to do so and also wasteful, since most of the permissions would never be tested.  Instead, Moodle calculates permissions &#039;&#039;as needed&#039;&#039;. Moodle does not store the permissions that it calculates, but recalculates them every time it needs to test them. This is why role assignments and overrides no longer have delayed effects, as they did in Moodle 1.7 and 1.8.&lt;br /&gt;
&lt;br /&gt;
You can generate tables like the ones in this article using [[The rolesdebug.php roles debugging script]].  The tables are very helpful in debugging roles-related problems.&lt;br /&gt;
&lt;br /&gt;
==The calculation==&lt;br /&gt;
&lt;br /&gt;
The function is called as follows:&lt;br /&gt;
&lt;br /&gt;
    has_capability(CAP,CONTEXT,USER);&lt;br /&gt;
&lt;br /&gt;
where&lt;br /&gt;
*CAP is the capability being tested (e.g., mod/quiz:attempt)&lt;br /&gt;
*CONTEXT can be System context or some context nested arbitrarily deeply within System. Internally, the function uses Unix-style paths to represent contexts (e.g., /1/3/4/150), but such details do not concern us here&lt;br /&gt;
*USER is the user.&lt;br /&gt;
&lt;br /&gt;
The function returns a true/false result&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;true&#039;&#039;  means the user should be allowed to perform the action&lt;br /&gt;
* &#039;&#039;false&#039;&#039; means the user should be prevented from perfoming the action&lt;br /&gt;
&lt;br /&gt;
===Data used by the function===&lt;br /&gt;
&lt;br /&gt;
Suppose USER is about to attempt a quiz (&#039;&#039;CAP = mod/quiz:attempt&#039;&#039;) in a Module context nested four levels deep within System.  &lt;br /&gt;
&lt;br /&gt;
      System&lt;br /&gt;
         |&lt;br /&gt;
     Category A&lt;br /&gt;
         |					      &lt;br /&gt;
    Subcategory B&lt;br /&gt;
         |&lt;br /&gt;
       Course&lt;br /&gt;
         |&lt;br /&gt;
       Quiz  &amp;lt;--- the user is here&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The quiz module will call &#039;&#039;has_capability()&#039;&#039; to see if the user should be allowed to perform this action.&lt;br /&gt;
&lt;br /&gt;
The function considers the following permissions data:&lt;br /&gt;
&lt;br /&gt;
* &#039;&#039;Role definitions&#039;&#039; (these are in the System context) &lt;br /&gt;
* &#039;&#039;Role assignments&#039;&#039; which have been made in any of the five contexts &lt;br /&gt;
* &#039;&#039;Role overrides&#039;&#039; which may occur in any of the contexts except System (there is no concept of override in System).  &lt;br /&gt;
&lt;br /&gt;
Note that there may be multiple assignments and/or overrides in any single context.  &lt;br /&gt;
&lt;br /&gt;
Whether or not the user can attempt the quiz is a function of the permissions data, as well as the location of the data in the context chain.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;has_capability()&#039;&#039; considers all roles and overrides that impact USER in CONTEXT, but it ignores capabilities other than CAP.  This simplification lets us view each role or override as a &#039;&#039;single permission&#039;&#039; having one of the following values&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
We use the following notation: for a role &#039;&#039;R1&#039;&#039; with permission &#039;&#039;P&#039;&#039;, we write &#039;&#039;R1(P)&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
===An example===&lt;br /&gt;
&lt;br /&gt;
In the quiz example, suppose that the user has four roles (&#039;&#039;R1&#039;&#039;, &#039;&#039;R2&#039;&#039;, &#039;&#039;R3&#039;&#039;, and &#039;&#039;R4&#039;&#039;) and each of the roles has been assigned and overridden as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define R1(A), R2(N), R3(N), R4(P)&lt;br /&gt;
            |               assign R1&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A    &amp;lt;-------------- overide R1(N) and R4(N)&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign R2 and R3&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;-------------- override R2(X) and R3(A)&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4     Quiz        &amp;lt;---- assign R4 and R1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that &#039;&#039;R1&#039;&#039; has been assigned in two different contexts. This is an unusual practice (it is probably someone&#039;s error), but since it is legal, we have to consider the possibility that it can happen.  In fact this entire example has been contrived to explore the edge cases of the algorithm.  In practice, the calculation of permissions is trivial and the function calculates the result you would expect based on common sense and simple mental analysis (for further discussion of this, see [[#A note about the algorithm|A note about the algorithm]] near the end of this article.&lt;br /&gt;
&lt;br /&gt;
===Representing the data in tabular form===&lt;br /&gt;
&lt;br /&gt;
We will set up a table to hold the permission data.  The table has&lt;br /&gt;
*a column for each context, ordered from highest level (System) to lowest (the context where we want to compute the permission).&lt;br /&gt;
*a row for each context, also listed from highest to lowest.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-3A.png|Empty table]]&lt;br /&gt;
&lt;br /&gt;
The role definitions go in the first row.  Put each definition in the column(s) coresponding to the context(s) in which the role is assigned: &lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-5A.png|Table with assignments added]]&lt;br /&gt;
&lt;br /&gt;
The overrides go in the remaining rows.  Each override goes&lt;br /&gt;
*in the same column as the role being overridden&lt;br /&gt;
*in the row corresponding the context in which the override is made.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s add just one of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-6A.png|Table with just one override]]&lt;br /&gt;
&lt;br /&gt;
R2(X) represents the override to role R2 made in the course context.  Let&#039;s add the rest of the overrides:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-7A.png|Table with remaining overrides shown]]&lt;br /&gt;
&lt;br /&gt;
The table is now fully populated, and we are ready to calculate the permission.&lt;br /&gt;
&lt;br /&gt;
===The algorithm===&lt;br /&gt;
&lt;br /&gt;
The algorithm follows a path through the table indicated by nodes and arrows in the diagram below and stops as soon as it has a conclusive result.&lt;br /&gt;
&lt;br /&gt;
[[Image:Algorithm_path_through_permission_table_A.png|Algorithm path through permissions data]]&lt;br /&gt;
&lt;br /&gt;
# If there is an X anywhere in the table, STOP.  The calculated permission is &#039;&#039;X&#039;&#039;&lt;br /&gt;
# Go to the START node&lt;br /&gt;
# If there is no next node, STOP.  The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
# Otherwise, follow the arrow to the next node&lt;br /&gt;
#Add the permissions in the node using the numerical equivalents: N = 0, A = +1, P = -1&lt;br /&gt;
#* If the sum is positive, STOP. The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
#* If the sum is negative, STOP. The calculated permission is &#039;&#039;P&#039;&#039;&lt;br /&gt;
#* If the sum is zero, GO TO step 3 &lt;br /&gt;
&lt;br /&gt;
Notice that the algorithm stops when either (1) a conclusive result is obtained, or (2) the algorithm reaches the last node without a conclusive result.&lt;br /&gt;
&lt;br /&gt;
===Applying the algorithm to our example===&lt;br /&gt;
&lt;br /&gt;
If we execute the algorithm with the quiz data, we stop at step 1 with a calculated permission of X.  That&#039;s not very interesting, so let&#039;s change the X to a P and see what happens:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-8A.png|Change X to P in permission table]]&lt;br /&gt;
&lt;br /&gt;
Run the algorithm:&lt;br /&gt;
&lt;br /&gt;
*There is No X in the table&lt;br /&gt;
*Go to the START node&lt;br /&gt;
*Go to the next node&lt;br /&gt;
*N + N = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*P + A = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A + P = 0 &lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*N = 0&lt;br /&gt;
*the sum is zero; go to the next node&lt;br /&gt;
*A = +1&lt;br /&gt;
*the sum is positive; STOP.  The calculated permission is &#039;&#039;A&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
If the calculated permission is &#039;&#039;A&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; returns &#039;&#039;true&#039;&#039;, and the user is allowed to perform the action.&lt;br /&gt;
&lt;br /&gt;
Had the calculated permission been &#039;&#039;P&#039;&#039; or &#039;&#039;X&#039;&#039;, &#039;&#039;has_capability()&#039;&#039; would not immediately return &#039;&#039;false&#039;&#039;. Rather, it would test if the user has &#039;&#039;moodle/site:doanything = Allow&#039;&#039; (since this permission trumps all others). The function does this by calling itself: &lt;br /&gt;
&lt;br /&gt;
    final result = has_capability(moodle/site:doanything,CONTEXT, USER);&lt;br /&gt;
&lt;br /&gt;
==A note about the algorithm==&lt;br /&gt;
&lt;br /&gt;
Earlier, we said that the algorithm &amp;quot;calculates the result you would expect.&amp;quot; But what do we expect?  Intuition tells us that permissions closer to the user should carry more weight than more distant permissions.  That&#039;s why we set up the table the way we did and why the algorithm walks the table in the order that it does.  The last column of the table represents the role assignment(s) closest to the user.  The second-to-last column represents the role assignent(s) that are next in terms of distance from the user, and so-on.  That&#039;s why the algorithm considers the columns from right-to-left.  Within a column, the algorithm searches upward in order to give higher weight to overrides that are closer to the user.  Once again, this matches our intuition about overrides.  If there are no overrides in a column (or the overrides are all Not set), the permission in the role definition is used.&lt;br /&gt;
&lt;br /&gt;
==Getting the result you expect==&lt;br /&gt;
&lt;br /&gt;
The calculation is more likely to give &amp;quot;the result you would expect&amp;quot; if you keep your permissions as simple as possible.  Therefore, we recommend the following &#039;rules&#039; for defining and overriding roles. If you understand the description of the calculation above, you should understand why they make sense.&lt;br /&gt;
&lt;br /&gt;
===When defining roles===&lt;br /&gt;
&lt;br /&gt;
... use Allow (A) for things you want the role to be able to do, and use Not set (N) for things you don&#039;t care about (which should include most things).&lt;br /&gt;
&lt;br /&gt;
===When overriding permissions===&lt;br /&gt;
&lt;br /&gt;
... leave the permission for every capability as Inherit (N) apart from the few you want to change. For those, use Allow (A) for things you want to allow, and Prevent (P) for things you want to prevent.&lt;br /&gt;
&lt;br /&gt;
===Only use prohibit in special roles===&lt;br /&gt;
&lt;br /&gt;
Prohibit exists to cover extreme scenarios such as the following: Suppose you have a naughty student who is posting inappropriate content in your Moodle site. You need to be able to remove their ability to contribute to public discussions until they have promised not to do it again, but during that time, you cannot completely block them from the resources, quizzes, etc. because they must keep up with their studying. Therefore, you need a way to block their access to specific capabilities e.g.  mod/forum:replypost in a way that cannot be overridden. You can do this by creating a special &#039;Naughty student&#039; role defined with the required permission(s) set to prohibit. Then when you are having problems with a user, you can temporarily assign them this role, either at site level or at course level.&lt;br /&gt;
&lt;br /&gt;
==A practical example==&lt;br /&gt;
&lt;br /&gt;
Suppose that a user, who is assigned the role of Course creator in category B, creates a course (becoming Teacher in the course) and then creates a Lesson within the course.  The user is about to edit the lesson (editing lessons is controlled by capability &#039;&#039;mod/lesson:edit&#039;&#039;).  Here is the permission data:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    0     System      &amp;lt;---- define Auth user(N), Creator(N), Teacher(A)&lt;br /&gt;
            |               assign Auth user&lt;br /&gt;
            |&lt;br /&gt;
    1   Category A&lt;br /&gt;
            |                          &lt;br /&gt;
            |                          &lt;br /&gt;
    2  Subcategory B  &amp;lt;---- assign Creator&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    3     Course      &amp;lt;---- assign Teacher&lt;br /&gt;
            |&lt;br /&gt;
            |&lt;br /&gt;
    4    Lesson       &amp;lt;---- user attempts to edit lesson&lt;br /&gt;
&lt;br /&gt;
We set up the table and populate it with permission data.&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-10A.png|A practical example]]&lt;br /&gt;
&lt;br /&gt;
Since there are no overrides, the table only has data in the first row.  The algorithm quickly calculates a permission of &#039;&#039;A&#039;&#039; and returns true.  The user is allowed to edit the Lesson!&lt;br /&gt;
&lt;br /&gt;
Now suppose Teacher is overridden in the Lesson context with &#039;&#039;mod/lesson:edit = P&#039;&#039;.  Then the table changes&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-11A.png|A practical example with first override]]&lt;br /&gt;
&lt;br /&gt;
and clearly the user is no longer allowed to edit the Lesson.&lt;br /&gt;
&lt;br /&gt;
But suppose the administrator (or whoever is making the overrides) decided instead to override the &#039;&#039;Creator role&#039;&#039;, setting &#039;&#039;mod/lesson:edit = Prevent&#039;&#039; in the Categoy B context:&lt;br /&gt;
&lt;br /&gt;
[[Image:Calculation-12A.png|A practical example with second override]]             &lt;br /&gt;
&lt;br /&gt;
Much to everyone&#039;s surprise, the user is still allowed to edit the Lesson!  If you understood this article, you shouldn&#039;t be surprised, and you should be able to explain what happened.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*Using Moodle [http://moodle.org/mod/forum/discuss.php?d=90140 Logged in: what role am I?] and [http://moodle.org/mod/forum/discuss.php?d=66782 What happens if a user has multiple roles in a course?] forum discussions.  &lt;br /&gt;
&lt;br /&gt;
There is a script that you can use to create tables like the ones in this article.  It is very useful for debugging roles-related problems.  See [[The rolesdebug.php roles debugging script]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Roles]]&lt;br /&gt;
&lt;br /&gt;
[[fr:Comment les permissions sont calculées ?]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35227</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=35227"/>
		<updated>2008-04-25T14:25:14Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a good understanding of Moodle&#039;s [[Roles and capabilities]] system.  If you&#039;re a &amp;quot;roles novice&amp;quot; and you need help with a roles-related problem, you can ask a roles expert to help you with running the script and interpreting the output.  Simply post a request for help to the [http://moodle.org/mod/forum/view.php?id=6826 Roles and Capabilities forum].&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will be able to see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.&lt;br /&gt;
&lt;br /&gt;
For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
If you are debugging a problem related to an &#039;&#039;automatic role assignment&#039;&#039;, you must logout and log back in prior to STEP 1.  Automatic role assignments are those which are controlled by user policies such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role. &lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then below the table, you&#039;ll see the &lt;br /&gt;
value of the permission that Moodle calculated (5).  &amp;quot;True&amp;quot; means you are allowed to perform the action and &amp;quot;False&amp;quot; means that you are prevented from performing the action.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
Finally, notice that Moodle now tells us that the calculated permission is &amp;quot;false,&amp;quot; exactly as we expect.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the final permission====&lt;br /&gt;
&lt;br /&gt;
By scanning the table in a certain way, you can see how Moodle &lt;br /&gt;
arrives at its calculated permission.  You can always do this with a quick visual scan, regardless of how many role assignments and overrides the table contains.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
scan row 1 from right to left, &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
* if there is an X anywhere in the row, the operation is prevented&lt;br /&gt;
* otherwise, scan the row from right to left, ignoring N&#039;s&lt;br /&gt;
* if the first R you hit is an A, the operation is allowed&lt;br /&gt;
* if the first R value you hit is P, the operation is prevented&lt;br /&gt;
* if a column contains one or more A&#039;s AND one or more P&#039;s cancel pairs of A-P pairs until either (1) all pairs cancel or (2) you are left with one or more A&#039;s or P&#039;s.  If you are left with A&#039;s, the operation is allowed.  If you are left with P&#039;s, the operation is prevented.&lt;br /&gt;
* if your scan takes you all the way to the leftmost column and you still haven&#039;t found a conclusive result, the operation is prevented.&lt;br /&gt;
&lt;br /&gt;
When there are overrides, you do the same thing, but your scan follows a different path.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
&lt;br /&gt;
For a complete explanation of how permissions are calculated, read the article [[How permissions are calculated | How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=34968</id>
		<title>The rolesdebug.php roles debugging script</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/test/index.php?title=The_rolesdebug.php_roles_debugging_script&amp;diff=34968"/>
		<updated>2008-04-20T16:30:58Z</updated>

		<summary type="html">&lt;p&gt;Jisner: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Roles}}{{Moodle 1.9}}&lt;br /&gt;
Rolesdebug.php is a stand-alone script that is extremely useful for debugging problems related to roles and permissions.  The output can be interpreted by anyone with a basic understanding of Moodle&#039;s [[Roles and capabilities]] system.&lt;br /&gt;
&lt;br /&gt;
You can download rolesdebug.php from the [http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=1204 Modules and Plugins database].  To install the script, simply drop it into the Moodle root directory or any directory under the root directory.&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php requires a login, so only someone with a Moodle user account who is currently logged in can use it. Since it is a php script, you will see the output in your browser.  No one else will see it unless they&#039;re looking over your shoulder.  Furthermore, rolesdebug.php gives you information about YOUR permissions.  You cannot use it to get information about another user&#039;s permissions, unless you can login as them.  &lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php returns a table that gives you a spatial view of the role assignments and overrides that affect you in a specified context. From the table, you will can easily see how Moodle calculates a specified permission.  The table format is explained (and several examples are given) in the article [[How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php reads permission data from the Moodle database but does not modify the database in any way.  In this respect, it is similar to other debug scripts in the standard distribution, like the [[TeX_notation_filter#Debugging_TeX_filter | TeX notation debugger]].&lt;br /&gt;
&lt;br /&gt;
==The use case for rolesdebug.php==&lt;br /&gt;
&lt;br /&gt;
The main use case for rolesdebug.php is a &#039;&#039;roles expert helping a roles novice troubleshoot a roles-related problem&#039;&#039;.  A &#039;&#039;roles expert&#039;&#039; is anyone with a basic understanding of the [[#Essential roles and capabilities concepts | essential roles concepts]] listed in the next section.  A &#039;&#039;roles novice&#039;&#039; is any Moodle user with the ability to follow simple instructions from the expert.  While the expert and novice may occasionally share the same physical location and have accounts on the same Moodle site, it is not required.  The expert must be able to help the novice without logging in to the novice&#039;s site, and by communicating with the novice only by e-mail, messaging, forum posts, etc..  For example, the novice may be a user posting to a moodle.org forum and the expert may be a moodler wanting to be helpful. Even when expert and novice share a physical location and have accounts on the same Moodle site, the expert may not be in a position to give direct help, e.g., by &amp;quot;logging in as&amp;quot; the novice or meeting with the novice.  For example, the expert may be a Moodle administrator with an extremely busy schedule.&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a typical scenario.  Supposed the novice is a teacher who has created a quiz, but is being prevented from previewing the quiz for some unknown reason.  The novice reports the problem to moodle.org in a forum post.  The expert (a helpful moodler) suspects a roles problem and replies by asking the novice to (1) log in to Moodle, reproduce the problem (2) browse to rolesdebug.php (3) enter two or three parameters as specified by the expert (4) paste the output from rolesdebug.php into a reply to this forum post.  The expert reviews the output and (hopefully) diagnoses the problem.&lt;br /&gt;
&lt;br /&gt;
Secondary use cases for rolesdebug.php include &lt;br /&gt;
* a user troubleshooting his own problems&lt;br /&gt;
* a user troubleshooting another user&#039;s problem while logged in as that user&lt;br /&gt;
&lt;br /&gt;
Note that both of these secondary use cases are equivalent, since there is only one actor (the expert), not two.  To keep things simple in the remainder of the article, I&#039;ll describe the secondary use case, and I&#039;ll refer only to YOU.  Keeping the primary use case in mind, it should be clear when &amp;quot;you&amp;quot; means roles expert and when it means the roles novice.&lt;br /&gt;
&lt;br /&gt;
==Essential roles and capabilities concepts==&lt;br /&gt;
&lt;br /&gt;
Interpreting the output from rolesdebug.php requires at least a basic understanding of the concepts listed below. If any of these concepts are unfamiliar to you, stop and follow the documentation link.&lt;br /&gt;
&lt;br /&gt;
* [[Assign_roles#Contexts | Context]]&lt;br /&gt;
* [[Capabilities | Capability]]&lt;br /&gt;
* [[Capabilities | Permission]]&lt;br /&gt;
* [[Capabilities | Role]]&lt;br /&gt;
* [[Assign_roles | Role assignment]]&lt;br /&gt;
* [[Override_permissions | Role override]]&lt;br /&gt;
* [[How permissions are calculated]]&lt;br /&gt;
&lt;br /&gt;
==Overview of a script session==&lt;br /&gt;
&lt;br /&gt;
First, you will log in to Moodle and navigate to the context where you&#039;re having the problem.  Perhaps this is a quiz which Moodle, for some unknown reason, is preventing you from attempting.  Then, without logging out of Moodle, point your browser at rolesdebug.php (I find it convenient to open a new browser tab for this).  Input the &#039;&#039;context&#039;&#039; you&#039;re interested in and (optionally) the name of a &#039;&#039;capability&#039;&#039; to investigate, then press the Go button.  The script will return a page with a table presenting a spatial view of the role assignments and overrides that affect you in the specified context. From the table, you will be able to see why Moodle is preventing you from attempting the quiz.&lt;br /&gt;
&lt;br /&gt;
==Using the script==&lt;br /&gt;
&lt;br /&gt;
===STEP1===&lt;br /&gt;
This step is done in Moodle (you won&#039;t use the script until STEP 2).  Login to Moodle and navigate into the context where the problem is occurring.  Once you&#039;re there, you&#039;ll make note of the context id, which is needed in STEP 2.  I&#039;ll tell you [[#How to determine the context id|how to determine the context id]] later.&lt;br /&gt;
&lt;br /&gt;
Incidentally, even if you know the context id, it is essential that you actually navigate to the context.  This is because Moodle loads certain permission data &amp;quot;lazily&amp;quot; -- i.e., only when actually needed. Navigating to the context guarantees that Moodle will have loaded the data.&lt;br /&gt;
&lt;br /&gt;
For example, suppose the target context is a certain quiz in some course.  You must enter the course and click on the Quiz icon.&lt;br /&gt;
&lt;br /&gt;
If you are debugging a problem related to an &#039;&#039;automatic role assignment&#039;&#039;, you must logout and log back in prior to STEP 1.  Automatic role assignments are those which are controlled by user policies such as Site administration -&amp;gt; Front page -&amp;gt; Front page settings -&amp;gt; Default front page role. &lt;br /&gt;
&lt;br /&gt;
Do not log out!&lt;br /&gt;
&lt;br /&gt;
===STEP 2===&lt;br /&gt;
Open a second browser window.  In the window, point your browser at &lt;br /&gt;
rolesdebug.php.  The script URL will be something like&lt;br /&gt;
&lt;br /&gt;
    http://yoursite/moodle/rolesdebug.php&lt;br /&gt;
&lt;br /&gt;
Rolesdebug.php will NOT ask you to login because you are already logged in.  The script will ask you for three inputs:  &lt;br /&gt;
&lt;br /&gt;
* CAPABILITY.  If you&#039;re only interested in seeing your role assignments and overrides, you can leave this field empty.  If you&#039;re interested in analyzing a particular permission, you&#039;ll need to enter the capability name.  For example, if you&#039;re interested in the capability that controls your ability to attempt quizzes, enter [[Capabilities/mod/quiz:attempt | mod/quiz:attempt]].&lt;br /&gt;
&lt;br /&gt;
* CONTEXT TYPE.  Choose one of the following from the dropdown menu:&lt;br /&gt;
**COURSE&lt;br /&gt;
**MODULE &lt;br /&gt;
**BLOCK&lt;br /&gt;
**COURSECAT&lt;br /&gt;
**USER&lt;br /&gt;
**SYSTEM&lt;br /&gt;
&lt;br /&gt;
* CONTEXT ID. The context id is a number at the end of the URL of the page you found in STEP 1.  See [[#How to determine the context id|How to determine the context id]] below.&lt;br /&gt;
&lt;br /&gt;
Incidentally, MODULE means activity or resource.  There is no FRONT PAGE context.  If you&#039;re interested in the Front page context, choose COURSE and specify a context id of 1.  &lt;br /&gt;
&lt;br /&gt;
Here&#039;s an example of input:&lt;br /&gt;
&lt;br /&gt;
[[Image:sample_input_quiz_attempt.png|sample input when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
===STEP 3=== &lt;br /&gt;
Press the Go button.  Rolesdebug.php will return a page of information.  The main item on the page is a table giving a spatial view of all the role assignments and overrides that affect you in the specified context.&lt;br /&gt;
&lt;br /&gt;
==How to read the output==&lt;br /&gt;
Let&#039;s look at a typical output for the input parameters from the last section.&lt;br /&gt;
[[Image:sample_output_quiz_attempt.png|sample output when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
The first three lines of output (1) simply echo your input values, and the next two lines (2) remind you of who YOU are, and tell you the actual name of the context you have selected.  Check these carefully to make &lt;br /&gt;
sure you are who you think you are, and have specified the correct context.&lt;br /&gt;
&lt;br /&gt;
For each of your roles, you will see a line of the form &#039;&#039;alias = role name&#039;&#039; where &lt;br /&gt;
* &#039;&#039;role name&#039;&#039; is the actual role name&lt;br /&gt;
* &#039;&#039;alias&#039;&#039; is the name used to represent the role in the table&lt;br /&gt;
&lt;br /&gt;
In the example, &#039;&#039;R7 = user&#039;&#039; means the the role user (the shortname of Authorized user) will be represented in the table by the alias R7.  Aliases are used because long role names could make the table very wide, forcing you to scroll horizontally.  By using aliases, the table will hopefully fit in a window, allowing you to see the entire table in a single a glance.&lt;br /&gt;
&lt;br /&gt;
Next comes the table (4). I&#039;ll have a lot more to say about the table below.&lt;br /&gt;
&lt;br /&gt;
If you specified a capability, then below the table, you&#039;ll see the &lt;br /&gt;
value of the permission that Moodle calculated (5).  &amp;quot;True&amp;quot; means you are allowed to perform the action and &amp;quot;False&amp;quot; means that you are prevented from performing the action.&lt;br /&gt;
&lt;br /&gt;
====How to read the table====&lt;br /&gt;
&lt;br /&gt;
If the target context is N levels deep, the table will have N rows and N columns, one for each context level.  The example above has four levels:&lt;br /&gt;
&lt;br /&gt;
    System&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Category &amp;quot;A&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Course &amp;quot;cooking&amp;quot;&lt;br /&gt;
       |&lt;br /&gt;
       |&lt;br /&gt;
    Module &amp;quot;quiz-1&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The column headings give the names of the contexts.  These are listed in order of increasing depth: System, A, cooking, quiz-1.&lt;br /&gt;
&lt;br /&gt;
To save space, the table does not have row headings.  If it did, they would be the same as the column headings.  For example, row 1 would be labeled &amp;quot;System&amp;quot; and row 4 would be labeled &amp;quot;quiz-1&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The first row of the table contains the role assignments made in each context level. In the example, you can see that R7 (Authorized user) is assigned in the System context and R5 (Student) is assigned in the course context.  If there are no overrides (as in this example) you will only see entries in row 1.&lt;br /&gt;
&lt;br /&gt;
The letters N and A in parentheses are the values of the capabilities in the role definitions.  The possible values are:&lt;br /&gt;
&lt;br /&gt;
    N - Not set&lt;br /&gt;
    A - Allow&lt;br /&gt;
    P - Prevent&lt;br /&gt;
    X - Prohibit&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Not set&amp;quot; means that the role doesn&#039;t say anything about the capability.  In the example, we see that the Student role allows &lt;br /&gt;
quiz attempts, while the Authorized user role doesn&#039;t have anything &lt;br /&gt;
to say about quiz attempts.&lt;br /&gt;
&lt;br /&gt;
If there are role overrides, there will be entries in other rows of the table.  Overrides have the same format as the assignments in row 1.  An override is shown in the ROW of the context where it is made, and the COLUMN of the assignment that it overrides.&lt;br /&gt;
&lt;br /&gt;
To illustrate, let&#039;s override the Student role in the Quiz context, setting mod/quiz:attempt to Prevent, and then rerun rolesdebug.php.  Of course before running the script, the student must attempt the quiz.  This time, the student should be prevented because of the override.  Now we run the script and get the following output:&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override.png|sample output when investigating a quiz attempt and there is an override]]&lt;br /&gt;
&lt;br /&gt;
Notice the newly added R5(P).  This is the override.  It is in the fourth row because the override was made in the quiz context, and it is in the course column because the Student role was assigned in the Course context.&lt;br /&gt;
&lt;br /&gt;
Finally, notice that Moodle now tells us that the calculated permission is &amp;quot;false,&amp;quot; exactly as we expect.&lt;br /&gt;
&lt;br /&gt;
====How Moodle calculates the final permission====&lt;br /&gt;
&lt;br /&gt;
By scanning the table in a certain way, you can see how Moodle &lt;br /&gt;
arrives at its calculated permission.  You can always do this with a quick visual scan, regardless of how many role assignments and overrides the table contains.&lt;br /&gt;
&lt;br /&gt;
For the original example (where we only had role assignments in row 1),&lt;br /&gt;
scan row 1 from right to left, &lt;br /&gt;
[[Image:sample_output_quiz_attempt_showing_path.png|how to scan the table when investigating a quiz attempt]]&lt;br /&gt;
&lt;br /&gt;
* if there is an X anywhere in the row, the operation is prevented&lt;br /&gt;
* otherwise, scan the row from right to left, ignoring N&#039;s&lt;br /&gt;
* if the first R you hit is an A, the operation is allowed&lt;br /&gt;
* if the first R value you hit is P, the operation is prevented&lt;br /&gt;
* if a column contains one or more A&#039;s AND one or more P&#039;s cancel pairs of A-P pairs until either (1) all pairs cancel or (2) you are left with one or more A&#039;s or P&#039;s.  If you are left with A&#039;s, the operation is allowed.  If you are left with P&#039;s, the operation is prevented.&lt;br /&gt;
* if your scan takes you all the way to the leftmost column and you still haven&#039;t found a conclusive result, the operation is prevented.&lt;br /&gt;
&lt;br /&gt;
When there are overrides, you do the same thing, but your scan follows a different path.&lt;br /&gt;
[[Image:sample_output_quiz_attempt_with_override_showing_path.png|how to scan the table when investigating a quiz attempt and there is an override]] &lt;br /&gt;
&lt;br /&gt;
For a complete explanation of how permissions are calculated, read the article [[How permissions are calculated | How permissions are calculated]].&lt;br /&gt;
&lt;br /&gt;
==How to determine the context id==&lt;br /&gt;
Here are rules for determining the context id for each context type.&lt;br /&gt;
===COURSE===&lt;br /&gt;
For a COURSE context, the context id is the course id.  You can get the course id from the URL that appears in the address bar when when you&#039;re on the course page.  For example when I point my browser at the &amp;quot;Features&amp;quot; course on demo.moodle.org, I see this:&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_in_address_bar.png|URI of course is shown in the address bar]]&lt;br /&gt;
&lt;br /&gt;
The course id, and therefore the context id for this course is 2.&lt;br /&gt;
&lt;br /&gt;
If Moodle won&#039;t let you enter the course for some reason, but you can see a link to the course, let your mouse hover over the link as in the following screenshot.  Your browser will show you the address at the bottom of the window.&lt;br /&gt;
&lt;br /&gt;
[[Image:URI_of_course_at_bottom_of_browser_window.png|URI of course is shown at the bottom of the browser window]]&lt;br /&gt;
&lt;br /&gt;
The front page of a Moodle site is also a course, but you can&#039;t use either of the above tricks to get the id.  &#039;&#039;The front page course id is 1.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===MODULE (activity or resource)=== &lt;br /&gt;
For a MODULE context, the context id is the activity or resource id. You can get the id from the URL that appears in the address bar when you&#039;re viewing the activity or resource, or from the bottom of the browser window when you let your mouse hover over a link.  Here are some examples:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/mod/choice/view.php?id=25&lt;br /&gt;
    http://demo.moodle.org/mod/forum/view.php?id=28&lt;br /&gt;
    http://demo.moodle.org/mod/lesson/view.php?id=38&lt;br /&gt;
    http://demo.moodle.org/mod/quiz/view.php?id=61&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=10&lt;br /&gt;
    http://demo.moodle.org/mod/resource/view.php?id=48&lt;br /&gt;
&lt;br /&gt;
The context id&#039;s for these modules are 25, 28, 38, 61, 10, and 48.&lt;br /&gt;
&lt;br /&gt;
===BLOCK===&lt;br /&gt;
For a BLOCK context, the context id is the &amp;quot;instanceid&amp;quot; of the block. To get the instanceid, turn editing on and let the mouse hover over the &amp;quot;eye&amp;quot; icon in the block header.  Then take the instanceid from URL that appears in the at the bottom of the window.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/course/view.php?id=28&amp;amp;instanceid=19...&lt;br /&gt;
&lt;br /&gt;
The context id for this block is 19.  Note that for blocks, only a user who can turn editing on can get the instanceid.&lt;br /&gt;
&lt;br /&gt;
===COURSECAT===&lt;br /&gt;
For a COURSECAT context, the context id is the category id. You can get the id from the URL that appears in the address bar when you&#039;re on the category page.  If the site has only one category (usually called &amp;quot;Miscellaneous&amp;quot;) the id is 1. If there is more than one category, the easiest way to get the category id for a specific category is to have a Category list or a Combo list on the front page of the site (or a Courses block) and let your mouse hover over one of the links.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://mysite/course/category.php?id=3&lt;br /&gt;
&lt;br /&gt;
The context id for this category is 3&lt;br /&gt;
&lt;br /&gt;
===USER===&lt;br /&gt;
For a USER context, the context id is the user id. You can get the id from the URL that appears in the address bar when you&#039;re on a profile page, or from the bottom of the browser window when you let your mouse hover over a user&#039;s name.  For example:&lt;br /&gt;
&lt;br /&gt;
    http://demo.moodle.org/user/view.php?id=6&amp;amp;course=1&lt;br /&gt;
&lt;br /&gt;
The context id for this user is 6&lt;br /&gt;
&lt;br /&gt;
===SYSTEM===&lt;br /&gt;
There is only one SYSTEM context.  Its id is 1.&lt;br /&gt;
&lt;br /&gt;
[[Category:Contributed code]]&lt;/div&gt;</summary>
		<author><name>Jisner</name></author>
	</entry>
</feed>