Class: Scrivito::UserDefinition
- Inherits:
-
Object
- Object
- Scrivito::UserDefinition
- Defined in:
- lib/scrivito/user_definition.rb
Instance Method Summary collapse
-
#can_always(verb, subject, message = nil) ⇒ Object
Adds an explicit rule, that allows the user to always execute an action.
-
#can_never(verb, subject, message = nil) ⇒ Object
Adds an explicit rule, that forbids the user to execute an action.
-
#description(description_string = nil, &description_proc) ⇒ Object
Defines the user description to be displayed, when the user is shown in the in-place GUI.
-
#is_admin! ⇒ Object
Make the user to be always able to create workspaces, to read, to write, to publish, to delete and to invite to any workspace.
-
#restrict_obj_publish(options) {|attribute| ... } ⇒ Object
Lets you restrict the rule of a user to publish a certain object.
-
#suggest_users(&suggest_users_proc) {|input| ... } ⇒ Object
Defines the proc for fetching users for the user autocompletion of the in-place GUI.
Instance Method Details
#can_always(verb, subject, message = nil) ⇒ Object
Normally the memberships of a workspace decide whether a user is allowed or not to execute a specific action. This method allows to add an exception to this logic and thus should be used carefully.
By default all users are allowed to create a new workspace.
Adds an explicit rule, that allows the user to always execute an action. A rule consists of a verb of the action, the subject of the action and an optional message.
40 41 42 43 |
# File 'lib/scrivito/user_definition.rb', line 40 def can_always(verb, subject, = nil) assert_no_conflict(:can_never, verb, subject) @explicit_rules[[:can_always, verb, subject]] = end |
#can_never(verb, subject, message = nil) ⇒ Object
Normally the memberships of a workspace decide whether a user is allowed or not to execute a specific action. This method allows to add an exception to this logic and thus should be used carefully.
By default all users are allowed to create a new workspace. Use this method to forbid a user to create a new workspace.
Adds an explicit rule, that forbids the user to execute an action. A rule consists of a verb of the action, the subject of the action and an optional message.
78 79 80 81 |
# File 'lib/scrivito/user_definition.rb', line 78 def can_never(verb, subject, = nil) assert_no_conflict(:can_always, verb, subject) @explicit_rules[[:can_never, verb, subject]] = end |
#description(description_string = nil, &description_proc) ⇒ Object
The description is calculated “lazy”.
The calculated description will be cached.
Defines the user description to be displayed, when the user is shown in the in-place GUI.
120 121 122 123 124 125 126 |
# File 'lib/scrivito/user_definition.rb', line 120 def description(description_string = nil, &description_proc) if description_string description { description_string } else @description_proc = description_proc end end |
#is_admin! ⇒ Object
Make the user to be always able to create workspaces, to read, to write, to publish, to delete and to invite to any workspace.
89 90 91 |
# File 'lib/scrivito/user_definition.rb', line 89 def is_admin! User::VERBS.each { |verb| @explicit_rules[[:can_always, verb, :workspace]] ||= nil } end |
#restrict_obj_publish(options) {|attribute| ... } ⇒ Object
Lets you restrict the rule of a user to publish a certain object. Each registered callback can access a certain attribute of an object. Multiple callbacks are possible
198 199 200 |
# File 'lib/scrivito/user_definition.rb', line 198 def restrict_obj_publish(, &block) restriction_set.add(, &block) end |
#suggest_users(&suggest_users_proc) {|input| ... } ⇒ Object
Only the first 20 of the returnes users will be displayed in the in-place GUI.
suggest_users_proc
may also be invoked with an empty string.
Defines the proc for fetching users for the user autocompletion of the in-place GUI. The user autocompletion is for example used in the details dialog of a workspace. If the proc is not set, then Scrivito::User.find will be used to fetch the suggested users with input as the user id.
155 156 157 |
# File 'lib/scrivito/user_definition.rb', line 155 def suggest_users(&suggest_users_proc) @suggest_users_proc = suggest_users_proc end |