Sha256: 7d7c486ce0fceb449526615a2694f25ab055e2e38695ab9c8d243d1769e666ff

Contents?: true

Size: 735 Bytes

Versions: 18

Compression:

Stored size: 735 Bytes

Contents

# frozen_string_literal: true

module Thredded
  class PrivatePostPolicy
    # @param user [Thredded.user_class]
    # @param post [Thredded::PrivatePost]
    def initialize(user, post)
      @user = user
      @post = post
    end

    def create?
      @user.thredded_admin? || @post.postable.users.include?(@user) && !@user.thredded_user_detail.blocked?
    end

    def read?
      Thredded::PrivateTopicPolicy.new(@user, @post.postable).read?
    end

    def update?
      @user.thredded_admin? || own_post?
    end

    def destroy?
      !@post.first_post_in_topic? && update?
    end

    def anonymous?
      @user.thredded_anonymous?
    end

    private

    def own_post?
      @user.id == @post.user_id
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
threddedDANIEL-0.14.5 app/policies/thredded/private_post_policy.rb
thredded-0.14.4 app/policies/thredded/private_post_policy.rb
thredded-0.14.3 app/policies/thredded/private_post_policy.rb
thredded-0.14.2 app/policies/thredded/private_post_policy.rb
thredded-0.14.1 app/policies/thredded/private_post_policy.rb
thredded-0.14.0 app/policies/thredded/private_post_policy.rb
thredded-0.13.8 app/policies/thredded/private_post_policy.rb
thredded-0.13.7 app/policies/thredded/private_post_policy.rb
thredded-0.13.6 app/policies/thredded/private_post_policy.rb
thredded-0.13.5 app/policies/thredded/private_post_policy.rb
thredded-0.13.4 app/policies/thredded/private_post_policy.rb
thredded-0.13.3 app/policies/thredded/private_post_policy.rb
thredded-0.13.2 app/policies/thredded/private_post_policy.rb
thredded-0.13.1 app/policies/thredded/private_post_policy.rb
thredded-0.13.0 app/policies/thredded/private_post_policy.rb
thredded-0.12.4 app/policies/thredded/private_post_policy.rb
thredded-0.12.3 app/policies/thredded/private_post_policy.rb
thredded-0.12.2 app/policies/thredded/private_post_policy.rb