module IMS::LTI::RoleChecks

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?`

Public Instance Methods

context_admin?() click to toggle source

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

# 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?() click to toggle source

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

# 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?() click to toggle source

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

# 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?() click to toggle source

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

# 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_observer?() click to toggle source

Convenience method for checking if the user has 'Observer' role in the current launch context

# File lib/ims/lti/role_checks.rb, line 97
def context_observer?
  has_exact_role?('Observer') || has_exact_role?('urn:lti:instrole:ims/lis/Observer')
end
context_student?() click to toggle source

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

# 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?() click to toggle source

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

# 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) click to toggle source

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`

# File lib/ims/lti/role_checks.rb, line 26
def has_base_role?(role)
  role = role.downcase
  @roles && @roles.any? { |r| r.downcase.start_with?(role) }
end
has_exact_role?(role) click to toggle source

Check whether the Launch Parameters have a given role

# File lib/ims/lti/role_checks.rb, line 17
def has_exact_role?(role)
  role = role.downcase
  @roles && @roles.any? { |r| r.downcase == role }
end
institution_admin?() click to toggle source

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

# File lib/ims/lti/role_checks.rb, line 54
def institution_admin?
  has_exact_role?('urn:lti:instrole:ims/lis/Administrator')
end
institution_instructor?() click to toggle source

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

# File lib/ims/lti/role_checks.rb, line 49
def institution_instructor?
  has_exact_role?('urn:lti:instrole:ims/lis/Instructor')
end
institution_student?() click to toggle source

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

# 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?() click to toggle source

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

# 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