Method: Scrivito::UserDefinition#restrict_obj_publish

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

#restrict_obj_publish(options) {|attribute| ... } ⇒ Object

Note:

The callback is only executed for Objs equipped with the attribute specified using the :using option. It is not executed for a Widget with this attribute.

Lets you restrict a user’s capability to publish a specific CMS object. Each registered callback may refer to one attribute of an object. Multiple callbacks are possible.

Examples:

class MyUserModel
  def to_scrivito_user
    Scrivito::User.define(id) do |user|
      user.restrict_obj_publish(using: :_path) do |path|
        if path.start_with?("/en")
          false
        else
          "You are only allowed to edit the English site."
        end
      end

      user.restrict_obj_publish(using: :_obj_class) do |obj_class|
        if obj_class == 'BlogPost'
          false
        else
          'You are only allowed to edit Blog Posts.'
        end
      end
    end
  end
end

Parameters:

  • options (Hash)

Options Hash (options):

  • :using (Symbol)

    the attribute you wish to refer to in the callback

Yields:

  • (attribute)

    the value of the specified attribute

Yield Returns:

  • (String, false)

    either return a message for the user or false if no restriction applies



199
200
201
# File 'app/cms/scrivito/user_definition.rb', line 199

def restrict_obj_publish(options, &block)
  restriction_set.add(options, &block)
end