Class: Mumukit::Auth::Permissions

Inherits:
Object
  • Object
show all
Defined in:
lib/mumukit/auth/token.rb,
lib/mumukit/auth/permissions.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grants) ⇒ Permissions

Returns a new instance of Permissions.



4
5
6
# File 'lib/mumukit/auth/permissions.rb', line 4

def initialize(grants)
  @grants = grants
end

Class Method Details

.dump(permission) ⇒ Object



36
37
38
# File 'lib/mumukit/auth/permissions.rb', line 36

def self.dump(permission)
  permission.to_s
end

.load(pattern) ⇒ Object



40
41
42
# File 'lib/mumukit/auth/permissions.rb', line 40

def self.load(pattern)
  parse(pattern)
end

.parse(pattern) ⇒ Object



44
45
46
# File 'lib/mumukit/auth/permissions.rb', line 44

def self.parse(pattern)
  new(pattern.split(':').map { |grant_pattern| Grant.parse(grant_pattern) })
end

Instance Method Details

#[](organization) ⇒ Object



20
21
22
# File 'lib/mumukit/auth/permissions.rb', line 20

def [](organization)
  any_grant? { |grant| grant[organization] }
end

#access?(organization) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/mumukit/auth/permissions.rb', line 16

def access?(organization)
  any_grant? { |grant| grant.access? organization }
end

#allows?(slug) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/mumukit/auth/permissions.rb', line 12

def allows?(slug)
  any_grant? { |grant| grant.allows? slug }
end

#as_jsonObject



24
25
26
# File 'lib/mumukit/auth/permissions.rb', line 24

def as_json
  to_s
end

#present?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/mumukit/auth/permissions.rb', line 32

def present?
  to_s.present?
end

#protect!(slug) ⇒ Object



8
9
10
# File 'lib/mumukit/auth/permissions.rb', line 8

def protect!(slug)
  raise Mumukit::Auth::UnauthorizedAccessError.new(unauthorized_message(slug)) unless allows?(slug)
end

#to_mumukit_auth_permissionsObject



53
54
55
# File 'lib/mumukit/auth/token.rb', line 53

def to_mumukit_auth_permissions
  self
end

#to_sObject



28
29
30
# File 'lib/mumukit/auth/permissions.rb', line 28

def to_s
  @grants.map(&:to_s).uniq.join(':')
end