Scrivito is proudly made by JustRelate Group in Berlin, Germany, and Wrocław, Poland.
Scrivito is proudly made by JustRelate Group

Granting Scrivito Users Access

Granting Scrivito Users Access

The content maintained with Scrivito should only be editable by users logged in as a Solidus admin. To achieve this, first create the file app/models/solidus_scrivito_user.rb and set its contents to:

# app/models/solidus_scrivito_user.rb
# provide a scrivito user based on the 'solidus_auth_devise' gem
module SolidusScrivitoUser
  def self.to_scrivito_user(solidus_user)
    # return nil, when no user is given
    return if solidus_user.blank?

    # return nil, when _not_ admin
    return unless solidus_user.admin?

    # return new Scrivito::User
    Scrivito::User.define(solidus_user.id.to_s) do |user|
      user.description {
        solidus_user.login
      }
      user.suggest_users do |input|
        Spree::User.search(login: input).result.map do |found_user|
          to_scrivito_user(found_user)
        end
      end

      # allow everything
      Scrivito::User::VERBS.each { |can_have| user.can_always(can_have, :workspace) }
    end
  end
end

Now add the following to config/initializers/scrivito.rb inside the Scrivito.configure block:

config.editing_auth do |env|
  SolidusScrivitoUser.to_scrivito_user(env["warden"].user)
end

config.find_user do |user_id|
  SolidusScrivitoUser.to_scrivito_user(Spree::User.find(user_id))
end

Restart your application using bundle exec rails s, then visit localhost:3000/login and log in with your admin credentials (e.g. admin@example.com/test123).

You should now be able to edit content again. Once logged out (by visiting localhost:3000/logout) you will no longer be able to edit the content.