Method: Scrivito::UserDefinition#can_always

Defined in:
app/cms/scrivito/user_definition.rb

#can_always(verb, subject, message = nil) ⇒ Object

Note:

Usually, the memberships of a workspace decide whether a user is allowed or not to perform a specific action. This method lets you add an exception to this logic and thus should be used carefully.

Note:

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 an action verb, the subject of the action, and an optional message.

Examples:

User can always read from, write to, and publish a workspace, ignoring the memberships:

Scrivito::User.define('alice') do |user|
  user.can_always(:read, :workspace)
  user.can_always(:write, :workspace)
  user.can_always(:publish, :workspace, 'You can always publish a workspace.')
end

Parameters:

  • verb (Symbol)

    the verb of the action (see Scrivito::User::VERBS).

  • subject (Symbol)

    the subject of the action. Currently, only :workspace is supported.

  • message (String) (defaults to: nil)

    an optional message to be displayed in the UI.

Raises:

See Also:



41
42
43
44
# File 'app/cms/scrivito/user_definition.rb', line 41

def can_always(verb, subject, message = nil)
  assert_no_conflict(:never, verb, subject)
  @explicit_rules << [:always, verb, subject, message]
end