Sha256: d501edeb88a5595085ce8b5e97195c9aaf71da0acf529fa5e7a0fc25014509b8

Contents?: true

Size: 674 Bytes

Versions: 5

Compression:

Stored size: 674 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

    private

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thredded-0.10.0 app/policies/thredded/private_post_policy.rb
thredded-0.9.4 app/policies/thredded/private_post_policy.rb
thredded-0.9.3 app/policies/thredded/private_post_policy.rb
thredded-0.9.2 app/policies/thredded/private_post_policy.rb
thredded-0.9.1 app/policies/thredded/private_post_policy.rb