Note: You are currently viewing documentation for Moodle 2.3. Up-to-date documentation for the latest stable version is available here: Creating custom roles.

Creating custom roles: Difference between revisions

From MoodleDocs
No edit summary
(→‎Example custom roles: added template creator role)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Roles and capabilities}}
{{Roles}}
==Creating a new role==


Custom Roles are roles that are not part of the core code, not downloaded with the installation files. There are always reasons to establish a custom role, and each custom role needs to be created. The basic process is the same for all custom roles so in this page we will create a role then use it as a [[Parent role]].  
To create a custom role:
#Go to ''Settings > Site administration > Users > Permissions > Define roles''.
#Click the "Add a new role" button.
#On the add a new role page, give the role a name e.g. 'Parent'. If you need to name the role for multiple languages you can use [[Multi language content|multi-lang syntax]] if you wish.
#Give the role a meaningful short name. The short name is necessary for other plugins in Moodle that may need to refer to the role (e.g. when uploading users from a file or setting enrolments via an enrolment plugin).
#Give the role a description (optional).
#Select an appropriate role archetype (see below for further information).
#Select the contexts where the role may be assigned e.g. 'User' for Parent role.
#Set permissions as required.
#Scroll to the top or bottom of the page and click the "Create this role" button.


Go to: '''Site Administration > Users > Permissions > Define Roles'''
{|
|-
| [[Image:CustomRole01.png|thumb|Adding a new role]]
| [[Image:customrole02.png|thumb|Setting the context types]]
|-
|}
 
==Role archetypes==


Scroll to the bottom of the page and click on Add New Role button.
A role archetype


This brings up the Adding a new role screen.
* Is a hard-coded template for a role
* Is used during upgrades when adding defaults for new capabilities - no archetype = no new capabilities during upgrade
* Is used during when resetting a role to determine the defaults - no archetype = reset removes all capabilities


In the Role name dialog, enter the name of the role that you want to create, "Parent" and retype the name in the "Short name" dialog.
There is no need to set a role archetype for custom roles used for overrides or if the site admin wants to specify new capabilities manually after upgrading.


In the Summary dialog enter something like as shown here:
==Creating a duplicate role==


[[Image:CustomRole01.png|frame|center|Naming a Custom Role]] 
To create a duplicate role:
*Go to ''Settings > Site administration > Users > Permissions > Define roles''.  
*In the "edit" column on the right, click the  x2 icon.
*Give a name and set permissions for your new role; scroll down and click "create this role".
*The list of roles will now show the "... copy 1" at the bottom, for example "Guest copy 1".


Moodle 2 uses Roles in a context, so we have to place the Role into a context so we can use it. Scroll down to "Context where this role may be assigned" and click on the User check box.
==New role considerations==


[[Image:customrole02.png|frame|center|Providing a context for the Custom Role]]
A newly-created role does not have the ability to assign or override any other roles. This is true even when the new role is a copy of a role that had such abilities.  If such ability is needed, the administrator must grant it explicitly via the 'Allow role assignments' and 'Allow role overrides' tabs.


We then need to scroll back up to the top of the page and click the "Create this role" button.
A new role is not automatically listed in course descriptions even if was created by copying a role that is listed, such as Teacher. If you want the new role to appear in the course listing, you must set it explicitly via ''Settings > Site administration > Appearance > Course managers''.


[[Image:customrole03.png|frame|center|Saving the new Custom Role]]
==Testing a new role==
''Settings > Switch role to''
Use the "Switch role to" link to see what another role will see in that context.


This creates a Custom Role and it is the Context in which the role is to be used that determines what [[Role_permissions|permissions]] the role actually begins with. If you wish to use the role in a particular way, then you may want change permissions to suit your purpose, as in this [[Parent role]].
Since switching roles confines you to those roles you can assign in a course context, this method is only useful for testing course-scoped capabilities (i.e. it will not be useful for testing permissions that apply outside the course context, like moodle/user:edit).


As you get more familiar with the ideas of custom roles, and you have a better idea of the permissions and capabilities you want the role to actually have when you create it, you will find that you can edit the capabilities of that role on this same page you used to create the Role.
''Tip:'' You can always create test user and assign the new role to them.  Then logout as admin and login as the test user.  This is really the best way to test a new role.


Once the Custom Role has been created, it then needs to be managed appropriately. In the graphic below, there are three more tabs that can be visited to assign permissions to access and assign the Custom Role in all circumstances.
==Example custom roles==


[[Image:customrole16.png|frame|center|Assigning rights to access and assign the new Custom Role]]
*[[Parent role|Parent]] - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees
*[[Demo teacher role|Demo teacher]] - for providing a demonstration teacher account with a password which can't be changed
*[[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
*[[Calendar editor role|Calendar editor]] - for enabling a user to add site or course events to the calendar
*[[Blogger role|Blogger]] - for limiting blogging to specific users only
*[[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
*[[Question creator role|Question creator]] - for enabling students to create questions for use in quizzes
*[[Course requester role]] - for restricting users who can make course requests
*[[Cohort enroller]] - for allowing teachers to enrol category cohorts into their course
*[[Template creator]] - for allowing teachers to save as "Public" a Feedback template.


In this case, the Admin User, the Manager and a Teacher can all assign rights to this role.
==See also==


{| class = "nicetable"
Using Moodle forum discussions:
|-
* [http://moodle.org/mod/forum/discuss.php?d=66782 What happens if a user has multiple roles in a course?]
| [[Image:lightbulb.png|center]]
* [http://moodle.org/mod/forum/discuss.php?d=90140 logged in: what role am I?]
| It is suggested, although not always recommended, that Teachers be given the rights to switch their Roles to Non-Editing Teacher, to Student, to Guest, if Guests are allowed on the site as well as to any Custom Role that access a Course. The reasons for this are obvious - but if stated then it would have to be that the Teacher can check to ensure the Role works as it should work, as they want it to work in the context of their courses. This way they do not have to rely upon an Admin to check for them.
|}


==See Also==
[[Category:Site administration]]


* [[Parent role]]
[[de:Neue Rollen anlegen]]

Latest revision as of 11:46, 20 October 2012


Creating a new role

To create a custom role:

  1. Go to Settings > Site administration > Users > Permissions > Define roles.
  2. Click the "Add a new role" button.
  3. On the add a new role page, give the role a name e.g. 'Parent'. If you need to name the role for multiple languages you can use multi-lang syntax if you wish.
  4. Give the role a meaningful short name. The short name is necessary for other plugins in Moodle that may need to refer to the role (e.g. when uploading users from a file or setting enrolments via an enrolment plugin).
  5. Give the role a description (optional).
  6. Select an appropriate role archetype (see below for further information).
  7. Select the contexts where the role may be assigned e.g. 'User' for Parent role.
  8. Set permissions as required.
  9. Scroll to the top or bottom of the page and click the "Create this role" button.
Adding a new role
Setting the context types

Role archetypes

A role archetype

  • Is a hard-coded template for a role
  • Is used during upgrades when adding defaults for new capabilities - no archetype = no new capabilities during upgrade
  • Is used during when resetting a role to determine the defaults - no archetype = reset removes all capabilities

There is no need to set a role archetype for custom roles used for overrides or if the site admin wants to specify new capabilities manually after upgrading.

Creating a duplicate role

To create a duplicate role:

  • Go to Settings > Site administration > Users > Permissions > Define roles.
  • In the "edit" column on the right, click the x2 icon.
  • Give a name and set permissions for your new role; scroll down and click "create this role".
  • The list of roles will now show the "... copy 1" at the bottom, for example "Guest copy 1".

New role considerations

A newly-created role does not have the ability to assign or override any other roles. This is true even when the new role is a copy of a role that had such abilities. If such ability is needed, the administrator must grant it explicitly via the 'Allow role assignments' and 'Allow role overrides' tabs.

A new role is not automatically listed in course descriptions even if was created by copying a role that is listed, such as Teacher. If you want the new role to appear in the course listing, you must set it explicitly via Settings > Site administration > Appearance > Course managers.

Testing a new role

Settings > Switch role to Use the "Switch role to" link to see what another role will see in that context.

Since switching roles confines you to those roles you can assign in a course context, this method is only useful for testing course-scoped capabilities (i.e. it will not be useful for testing permissions that apply outside the course context, like moodle/user:edit).

Tip: You can always create test user and assign the new role to them. Then logout as admin and login as the test user. This is really the best way to test a new role.

Example custom roles

  • Parent - for providing parents/mentors/tutors with permission to view certain information about their children/mentees/tutees
  • Demo teacher - for providing a demonstration teacher account with a password which can't be changed
  • 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
  • Calendar editor - for enabling a user to add site or course events to the calendar
  • Blogger - for limiting blogging to specific users only
  • Quiz user with unlimited time - for allowing a user unlimited time to attempt a quiz which has a time limit set
  • Question creator - for enabling students to create questions for use in quizzes
  • Course requester role - for restricting users who can make course requests
  • Cohort enroller - for allowing teachers to enrol category cohorts into their course
  • Template creator - for allowing teachers to save as "Public" a Feedback template.

See also

Using Moodle forum discussions: