Class: Etna::User
- Inherits:
-
Object
- Object
- Etna::User
- Defined in:
- lib/etna/user.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #active?(project = nil) ⇒ Boolean
- #can_edit?(project) ⇒ Boolean
-
#can_see_restricted?(project) ⇒ Boolean
superusers - administrators of the Administration group - cannot automatically see restricted data, they should be granted project-specific access.
- #can_view?(project) ⇒ Boolean
- #display_name ⇒ Object
- #has_any_role?(project, *roles) ⇒ Boolean
- #has_flag?(flag) ⇒ Boolean
-
#initialize(params, token = nil) ⇒ User
constructor
A new instance of User.
- #is_admin?(project) ⇒ Boolean
- #is_supereditor?(project = nil) ⇒ Boolean
- #is_superuser?(project = nil) ⇒ Boolean
- #is_superviewer?(project = nil) ⇒ Boolean
- #permissions ⇒ Object
- #projects ⇒ Object
- #task? ⇒ Boolean
Constructor Details
#initialize(params, token = nil) ⇒ User
Returns a new instance of User.
5 6 7 8 9 10 11 |
# File 'lib/etna/user.rb', line 5 def initialize params, token=nil @name, @email, @encoded_permissions, encoded_flags, @task = params.values_at(:name, :email, :perm, :flags, :task) @flags = encoded_flags&.split(/;/) || [] @token = token unless !token raise ArgumentError, "No email given!" unless @email end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
13 14 15 |
# File 'lib/etna/user.rb', line 13 def email @email end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/etna/user.rb', line 13 def name @name end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
13 14 15 |
# File 'lib/etna/user.rb', line 13 def token @token end |
Instance Method Details
#active?(project = nil) ⇒ Boolean
71 72 73 |
# File 'lib/etna/user.rb', line 71 def active? project=nil .keys.length > 0 end |
#can_edit?(project) ⇒ Boolean
51 52 53 |
# File 'lib/etna/user.rb', line 51 def can_edit? project is_supereditor? || has_any_role?(project, :admin, :editor) end |
#can_see_restricted?(project) ⇒ Boolean
superusers - administrators of the Administration group - cannot automatically see restricted data, they should be granted project-specific access.
62 63 64 65 |
# File 'lib/etna/user.rb', line 62 def can_see_restricted? project perm = [project.to_s] perm && perm[:restricted] end |
#can_view?(project) ⇒ Boolean
55 56 57 |
# File 'lib/etna/user.rb', line 55 def can_view? project is_superviewer? || has_any_role?(project, :admin, :editor, :viewer, :guest) end |
#display_name ⇒ Object
75 76 77 |
# File 'lib/etna/user.rb', line 75 def display_name [ email, name ].join('|') end |
#has_any_role?(project, *roles) ⇒ Boolean
31 32 33 34 35 36 37 |
# File 'lib/etna/user.rb', line 31 def has_any_role?(project, *roles) perm = [project.to_s] return false unless perm return roles.map(&:to_sym).include?(perm[:role]) end |
#has_flag?(flag) ⇒ Boolean
23 24 25 |
# File 'lib/etna/user.rb', line 23 def has_flag?(flag) @flags.include?(flag) end |
#is_admin?(project) ⇒ Boolean
67 68 69 |
# File 'lib/etna/user.rb', line 67 def is_admin? project is_supereditor? || has_any_role?(project, :admin) end |
#is_supereditor?(project = nil) ⇒ Boolean
43 44 45 |
# File 'lib/etna/user.rb', line 43 def is_supereditor? project=nil has_any_role?(:administration, :admin, :editor) end |
#is_superuser?(project = nil) ⇒ Boolean
39 40 41 |
# File 'lib/etna/user.rb', line 39 def is_superuser? project=nil has_any_role?(:administration, :admin) end |
#is_superviewer?(project = nil) ⇒ Boolean
47 48 49 |
# File 'lib/etna/user.rb', line 47 def is_superviewer? project=nil has_any_role?(:administration, :admin, :editor, :viewer) end |
#permissions ⇒ Object
19 20 21 |
# File 'lib/etna/user.rb', line 19 def @permissions ||= Etna::Permissions.(@encoded_permissions).to_hash end |
#projects ⇒ Object
27 28 29 |
# File 'lib/etna/user.rb', line 27 def projects .keys end |
#task? ⇒ Boolean
15 16 17 |
# File 'lib/etna/user.rb', line 15 def task? !!@task end |