Sha256: 281d3695dfd7aef0f53349627d17260fa807137d6a3c91e4f68daad4bff75605

Contents?: true

Size: 1.25 KB

Versions: 15

Compression:

Stored size: 1.25 KB

Contents

module Locomotive
  class ApplicationPolicy

    class Scope

      attr_reader :membership, :scope

      def initialize(membership, scope)
        @membership = membership
        @scope      = scope
      end

    end

    delegate :site, :account, to: :membership

    attr_reader :membership, :resource

    # The resource is always scoped by the site defined by the membership.
    def initialize(membership, resource)
      @membership = membership
      @resource   = resource

      raise Pundit::NotAuthorizedError, 'must be logged in' unless account
      raise Pundit::NotAuthorizedError, 'should have a resource' unless resource
    end

    def index?
      false
    end

    def show?
      index?
    end

    def edit?
      update?
    end

    def update?
      false
    end

    def new?
      create?
    end

    def create?
      false
    end

    def destroy?
      false
    end

    def destroy_all?
      false
    end

    def site_staff?
      membership.site.present?
    end

    def super_admin?
      account.super_admin?
    end

    def site_admin_or_designer?
      membership.admin? || membership.designer?
    end

    def site_admin?
      membership.admin?
    end

    def persisted?
      resource.try(:persisted?)
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 app/policies/locomotive/application_policy.rb
locomotivecms-4.2.0.alpha1 app/policies/locomotive/application_policy.rb
locomotivecms-4.1.1 app/policies/locomotive/application_policy.rb
locomotivecms-4.1.0 app/policies/locomotive/application_policy.rb
locomotivecms-4.1.0.rc1 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.3 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.2 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.1 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.0 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.0.rc0 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.0.alpha3 app/policies/locomotive/application_policy.rb
locomotivecms-3.4.1 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.0.alpha2 app/policies/locomotive/application_policy.rb
locomotivecms-4.0.0.alpha1 app/policies/locomotive/application_policy.rb
locomotivecms-3.4.0 app/policies/locomotive/application_policy.rb