Class: Scrivito::User
- Inherits:
-
Object
- Object
- Scrivito::User
- Defined in:
- lib/scrivito/user.rb
Constant Summary collapse
- VERBS =
Valid action verbs for the explicit rules.
[ :create, :delete, :invite_to, :publish, :read, :write, ].freeze
Class Method Summary collapse
-
.define(id) {|user| ... } ⇒ Object
Defines a new user.
-
.system_user ⇒ Scrivito::User
Returns an anonymous system user, who can always create workspaces, can always read, write, publish, delete and invite to any workspace.
Instance Method Summary collapse
-
#can_publish?(obj) ⇒ Boolean
Verifies if the User is able to publish changes to a certain Obj.
-
#restriction_messages_for(obj) ⇒ Array<String>
Checks if the User is able to publish changes and returns the message specified in a Scrivito::UserDefinition#restrict_obj_publish callback if they are not If the user can publish the obj an empty array is returned.
Class Method Details
.define(id) {|user| ... } ⇒ Object
Defines a new user.
64 65 66 67 |
# File 'lib/scrivito/user.rb', line 64 def define(id, &block) assert_valid_id(id) define_user(id, &block) end |
.system_user ⇒ Scrivito::User
Returns an anonymous system user, who can always create workspaces, can always read, write, publish, delete and invite to any workspace.
76 77 78 |
# File 'lib/scrivito/user.rb', line 76 def system_user define_user { |user| user.is_admin! } end |
Instance Method Details
#can_publish?(obj) ⇒ Boolean
Verifies if the User is able to publish changes to a certain Obj
154 155 156 |
# File 'lib/scrivito/user.rb', line 154 def can_publish?(obj) (obj).empty? end |
#restriction_messages_for(obj) ⇒ Array<String>
Checks if the User is able to publish changes and returns the message specified in a Scrivito::UserDefinition#restrict_obj_publish callback if they are not If the user can publish the obj an empty array is returned
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/scrivito/user.rb', line 167 def (obj) assert_restrictions_applicable(obj) return [] if can_always?(:publish, :workspace) if obj.modification == Modification::EDITED base_revision_obj = obj.in_revision(obj.revision.workspace.base_revision) restriction_set.(obj) | restriction_set.(base_revision_obj) else restriction_set.(obj) end end |