Module: IMS::LTI::RoleChecks

Included in:
ToolProvider
Defined in:
lib/ims/lti/role_checks.rb

Overview

Some convenience methods for the most used roles Take care when using context_ helpers, as the context of an LTI launch determines the meaning of that role. For example, if the context is an institution context instead of a course context, then the short role of “Instructor” means they are a teacher at the institution, but not necessarily of the course you’re working in.

Also note that these only check for the base roles. So, asking context_student? only matches ‘urn:lti:role:ims/lis/Learner`, not `urn:lti:role:ims/lis/Learner/NonCreditLearner` If you make use of the more specific roles you’ll need to ask specifically for those: @tool_provider.has_exact_role?(“urn:lti:role:ims/lis/Learner/NonCreditLearner”) Or you can use ‘has_base_role?`

Instance Method Summary collapse

Instance Method Details

#context_admin?Boolean

Convenience method for checking if the user has ‘administrator’ role in the current launch context

Returns:

  • (Boolean)


87
88
89
# File 'lib/ims/lti/role_checks.rb', line 87

def context_admin?
  has_exact_role?('Administrator') || has_exact_role?('urn:lti:role:ims/lis/Administrator')
end

#context_content_developer?Boolean

Convenience method for checking if the user has ‘contentdeveloper’ role in the current launch context

Returns:

  • (Boolean)


77
78
79
# File 'lib/ims/lti/role_checks.rb', line 77

def context_content_developer?
  has_exact_role?('ContentDeveloper') || has_exact_role?('urn:lti:role:ims/lis/ContentDeveloper')
end

#context_instructor?Boolean

Convenience method for checking if the user has ‘instructor’ role in the current launch context

Returns:

  • (Boolean)


72
73
74
# File 'lib/ims/lti/role_checks.rb', line 72

def context_instructor?
  has_exact_role?('instructor') || has_exact_role?('urn:lti:role:ims/lis/Instructor')
end

#context_mentor?Boolean

Convenience method for checking if the user has ‘Mentor’ role in the current launch context

Returns:

  • (Boolean)


82
83
84
# File 'lib/ims/lti/role_checks.rb', line 82

def context_mentor?
  has_exact_role?('Mentor') || has_exact_role?('urn:lti:role:ims/lis/Mentor')
end

#context_student?Boolean

Convenience method for checking if the user has ‘learner’ role in the current launch context

Returns:

  • (Boolean)


67
68
69
# File 'lib/ims/lti/role_checks.rb', line 67

def context_student?
  has_exact_role?('Learner') || has_exact_role?('urn:lti:role:ims/lis/Learner')
end

#context_ta?Boolean

Convenience method for checking if the user has ‘TeachingAssistant’ role in the current launch context

Returns:

  • (Boolean)


92
93
94
# File 'lib/ims/lti/role_checks.rb', line 92

def context_ta?
  has_exact_role?('TeachingAssistant') || has_exact_role?('urn:lti:role:ims/lis/TeachingAssistant')
end

#has_base_role?(role) ⇒ Boolean

Check whether the Launch Parameters have a given role ignoring sub roles. So asking: @tool_provider.has_base_role?(“urn:lti:role:ims/lis/Instructor/”) will return true if the role is ‘urn:lti:role:ims/lis/Instructor/GuestInstructor`

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/ims/lti/role_checks.rb', line 26

def has_base_role?(role)
  role = role.downcase
  @roles && @roles.any? { |r| r.start_with?(role) }
end

#has_exact_role?(role) ⇒ Boolean

Check whether the Launch Parameters have a given role

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/ims/lti/role_checks.rb', line 17

def has_exact_role?(role)
  role = role.downcase
  @roles && @roles.any? { |r| r == role }
end

#institution_admin?Boolean

Convenience method for checking if the user has ‘Administrator’ role at the institution

Returns:

  • (Boolean)


54
55
56
# File 'lib/ims/lti/role_checks.rb', line 54

def institution_admin?
  has_exact_role?('urn:lti:instrole:ims/lis/Administrator')
end

#institution_instructor?Boolean

Convenience method for checking if the user has ‘Instructor’ role at the institution

Returns:

  • (Boolean)


49
50
51
# File 'lib/ims/lti/role_checks.rb', line 49

def institution_instructor?
  has_exact_role?('urn:lti:instrole:ims/lis/Instructor')
end

#institution_student?Boolean

Convenience method for checking if the user has ‘student’ or ‘learner’ roles at the institution

Returns:

  • (Boolean)


44
45
46
# File 'lib/ims/lti/role_checks.rb', line 44

def institution_student?
  has_exact_role?('urn:lti:instrole:ims/lis/Student') || has_exact_role?('urn:lti:instrole:ims/lis/Learner')
end

#system_administrator?Boolean

Convenience method for checking if the user is the system administrator of the TC

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/ims/lti/role_checks.rb', line 32

def system_administrator?
  has_exact_role?('urn:lti:sysrole:ims/lis/SysAdmin') ||
          has_exact_role?('SysAdmin') ||
          has_exact_role?('urn:lti:sysrole:ims/lis/Administrator')
end