Creating custom roles

Roles and permissions



Contents


Creating a new role

To create a custom role:

  1. Go to Administration > Site administration > Users > Permissions > Define roles.
  2. Click the "Add a new role" button.
  3. If desired, select an existing role or upload a preset, otherwise click the continue button.
  4. Give the role a Short name e.g. 'Parent'.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. You must provide a full name for all custom roles. If you need to name the role for multiple languages we can use multi-lang syntax if you wish.
  6. Give the role a description (optional).
  7. Select an appropriate role archetype (see below for further information).
  8. Select the contexts where the role may be assigned e.g. 'User' for Parent role.
  9. Set permissions as required.
  10. Scroll to the top or bottom of the page and click the "Create this role" button.



Role archetypes

A role archetype

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.

The archetypes (which relate directly to the built-in roles) are:


Creating a duplicate role

To create a duplicate role:

  1. Go to Administration > Site administration > Users > Permissions > Define roles.
  2. Click the "Add a new role" button.
  3. Select existing role as a template
  4. Give a name and set permissions for your new role; scroll down and click "Create this role".


New role considerations

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 Administration > Site administration > Appearance > Courses>Course Contacts"


Testing a new role

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

Since switching roles confines us to those roles we 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: We 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


Uploading users to a system role

Where certain custom roles are applied in the system context, it is possible to upload users to that role in bulk by adding the field sysrole1 (etc) to the CSV file


See also

Using Moodle forum discussions: