Sha256: 78cea6210dbfc2c28e2e97c6e73ee21be33d2c4f9ac09362e9d690e5b217683e

Contents?: true

Size: 1.13 KB

Versions: 19

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true
module Thredded
  class MessageboardPolicy
    # The scope of readable messageboards
    class Scope
      # @param user [Thredded.user_class]
      # @param scope [ActiveRecord::Relation<Thredded::Messageboard>]
      def initialize(user, scope)
        @user = user
        @scope = scope
      end

      # @return [ActiveRecord::Relation<Thredded::Messageboards>]
      def resolve
        @scope.merge(@user.thredded_can_read_messageboards)
      end
    end

    # @param user [Thredded.user_class]
    # @param messageboard [Thredded::Messageboard]
    def initialize(user, messageboard)
      @user = user
      @messageboard = messageboard
    end

    def create?
      @user.thredded_admin?
    end

    def read?
      @user.thredded_admin? || @user.thredded_can_read_messageboards.include?(@messageboard)
    end

    def update?
      @user.thredded_admin?
    end

    def post?
      @user.thredded_admin? || @user.thredded_can_write_messageboards.include?(@messageboard)
    end

    def moderate?
      @user.thredded_admin? || @user.thredded_can_moderate_messageboards.include?(@messageboard)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
thredded-0.12.1 app/policies/thredded/messageboard_policy.rb
thredded-0.12.0 app/policies/thredded/messageboard_policy.rb
thredded-0.11.1 app/policies/thredded/messageboard_policy.rb
thredded-0.11.0 app/policies/thredded/messageboard_policy.rb
thredded-0.10.1 app/policies/thredded/messageboard_policy.rb
thredded-0.10.0 app/policies/thredded/messageboard_policy.rb
thredded-0.9.4 app/policies/thredded/messageboard_policy.rb
thredded-0.9.3 app/policies/thredded/messageboard_policy.rb
thredded-0.9.2 app/policies/thredded/messageboard_policy.rb
thredded-0.9.1 app/policies/thredded/messageboard_policy.rb
thredded-0.8.4 app/policies/thredded/messageboard_policy.rb
thredded-0.8.2 app/policies/thredded/messageboard_policy.rb
thredded-0.7.0 app/policies/thredded/messageboard_policy.rb
thredded-0.6.3 app/policies/thredded/messageboard_policy.rb
thredded-0.6.2 app/policies/thredded/messageboard_policy.rb
thredded-0.6.1 app/policies/thredded/messageboard_policy.rb
thredded-0.6.0 app/policies/thredded/messageboard_policy.rb
thredded-0.5.1 app/policies/thredded/messageboard_policy.rb
thredded-0.5.0 app/policies/thredded/messageboard_policy.rb