Sha256: 0e98fd34dcbeb672b50cf69cdc023ea872a82d06be653b20497f4b80e0eb02df

Contents?: true

Size: 1.13 KB

Versions: 12

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

12 entries across 12 versions & 1 rubygems

Version Path
thredded-0.13.8 app/policies/thredded/messageboard_policy.rb
thredded-0.13.7 app/policies/thredded/messageboard_policy.rb
thredded-0.13.6 app/policies/thredded/messageboard_policy.rb
thredded-0.13.5 app/policies/thredded/messageboard_policy.rb
thredded-0.13.4 app/policies/thredded/messageboard_policy.rb
thredded-0.13.3 app/policies/thredded/messageboard_policy.rb
thredded-0.13.2 app/policies/thredded/messageboard_policy.rb
thredded-0.13.1 app/policies/thredded/messageboard_policy.rb
thredded-0.13.0 app/policies/thredded/messageboard_policy.rb
thredded-0.12.4 app/policies/thredded/messageboard_policy.rb
thredded-0.12.3 app/policies/thredded/messageboard_policy.rb
thredded-0.12.2 app/policies/thredded/messageboard_policy.rb