Module: Authorized::UserModel::InstanceMethods
- Defined in:
- lib/authorized/user_model.rb
Instance Method Summary collapse
- #deputize ⇒ Object
- #is_administrator?(*args) ⇒ Boolean
- #is_editor?(*args) ⇒ Boolean
- #is_interviewer?(*args) ⇒ Boolean
- #is_reader?(*args) ⇒ Boolean
-
#is_superuser?(*args) ⇒ Boolean
(also: #is_super_user?)
The 4 common CCLS roles are .…
- #is_user?(user = nil) ⇒ Boolean (also: #may_be_user?)
- #may_administrate?(*args) ⇒ Boolean (also: #may_view_permissions?, #may_create_user_invitations?, #may_view_users?, #may_assign_roles?)
- #may_edit?(*args) ⇒ Boolean (also: #may_maintain_pages?)
-
#may_interview?(*args) ⇒ Boolean
Add tests for may_interview and may_read.
-
#may_read?(*args) ⇒ Boolean
(also: #may_view?)
This is pretty lame as all current roles can read.
- #may_share_document?(document = nil) ⇒ Boolean
- #may_view_document?(document = nil) ⇒ Boolean
- #may_view_user?(user = nil) ⇒ Boolean
- #role_names ⇒ Object
Instance Method Details
#deputize ⇒ Object
51 52 53 |
# File 'lib/authorized/user_model.rb', line 51 def deputize roles << Role.find_or_create_by_name('administrator') end |
#is_administrator?(*args) ⇒ Boolean
61 62 63 |
# File 'lib/authorized/user_model.rb', line 61 def is_administrator?(*args) self.role_names.include?('administrator') end |
#is_editor?(*args) ⇒ Boolean
65 66 67 |
# File 'lib/authorized/user_model.rb', line 65 def is_editor?(*args) self.role_names.include?('editor') end |
#is_interviewer?(*args) ⇒ Boolean
69 70 71 |
# File 'lib/authorized/user_model.rb', line 69 def is_interviewer?(*args) self.role_names.include?('interviewer') end |
#is_reader?(*args) ⇒ Boolean
73 74 75 |
# File 'lib/authorized/user_model.rb', line 73 def is_reader?(*args) self.role_names.include?('reader') end |
#is_superuser?(*args) ⇒ Boolean Also known as: is_super_user?
The 4 common CCLS roles are .…
56 57 58 |
# File 'lib/authorized/user_model.rb', line 56 def is_superuser?(*args) self.role_names.include?('superuser') end |
#is_user?(user = nil) ⇒ Boolean Also known as: may_be_user?
77 78 79 |
# File 'lib/authorized/user_model.rb', line 77 def is_user?(user=nil) !user.nil? && self == user end |
#may_administrate?(*args) ⇒ Boolean Also known as: may_view_permissions?, may_create_user_invitations?, may_view_users?, may_assign_roles?
82 83 84 |
# File 'lib/authorized/user_model.rb', line 82 def may_administrate?(*args) (self.role_names & ['superuser','administrator']).length > 0 end |
#may_edit?(*args) ⇒ Boolean Also known as: may_maintain_pages?
90 91 92 93 94 |
# File 'lib/authorized/user_model.rb', line 90 def may_edit?(*args) (self.role_names & ['superuser','administrator','editor'] ).length > 0 end |
#may_interview?(*args) ⇒ Boolean
Add tests for may_interview and may_read
99 100 101 102 103 |
# File 'lib/authorized/user_model.rb', line 99 def may_interview?(*args) (self.role_names & ['superuser','administrator','editor','interviewer'] ).length > 0 end |
#may_read?(*args) ⇒ Boolean Also known as: may_view?
This is pretty lame as all current roles can read
106 107 108 109 110 |
# File 'lib/authorized/user_model.rb', line 106 def may_read?(*args) (self.role_names & ['superuser','administrator','editor','interviewer','reader'] ).length > 0 end |
#may_share_document?(document = nil) ⇒ Boolean
122 123 124 125 126 127 |
# File 'lib/authorized/user_model.rb', line 122 def may_share_document?(document=nil) document && ( self.is_administrator? || ( document.owner && self == document.owner ) ) end |
#may_view_document?(document = nil) ⇒ Boolean
129 130 131 132 133 134 135 136 |
# File 'lib/authorized/user_model.rb', line 129 def may_view_document?(document=nil) document end |
#may_view_user?(user = nil) ⇒ Boolean
115 116 117 |
# File 'lib/authorized/user_model.rb', line 115 def may_view_user?(user=nil) self.is_user?(user) || self.may_administrate? end |
#role_names ⇒ Object
47 48 49 |
# File 'lib/authorized/user_model.rb', line 47 def role_names roles.collect(&:name).uniq end |