Skip to content

Commit

Permalink
Enhance the role checking algorithm to test for different role types …
Browse files Browse the repository at this point in the history
…and subroles
  • Loading branch information
David Kosub committed Sep 9, 2014
1 parent 1e1cf47 commit 83a207f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/provider.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ class Provider


# has_role Helper
#
#
has_role: (role) ->
role = role.replace /([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'
regex = new RegExp "^(urn:lti:role:ims/lis/)?#{role}$", 'i'
# There's 3 different types of roles: system, institution, and context. Each one has their own unique identifier
# string within the urn prefix. This regular expression can verify the prefix is there at all, and if it is, ensure
# that it matches one of the three different ways that it can be formatted. Additionally, context roles can have a
# suffix that futher describes what the role may be (such as an instructor that is a lecturer). Those details are
# probably a bit too specific for most cases, so we can just verify that they are optionally there
regex = new RegExp "^(urn:lti:(sys|inst)?role:ims/lis/)?#{role}(/.+)?$", 'i'
@body.roles && @body.roles.some (r) -> regex.test(r)


Expand Down

0 comments on commit 83a207f

Please sign in to comment.