Method: Scrivito::UserDefinition#can_never

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

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

Examples:

User can never publish a workspace, even if they’re a workspace owner:

Scrivito::User.define('alice') do |user|
  user.can_never(:publish, :workspace, 'You cannot publish workspaces.')
end

User cannot create a workspace:

Scrivito::User.define('bob') do |user|
  user.can_never(:create, :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:



79
80
81
82
# File 'app/cms/scrivito/user_definition.rb', line 79

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