Sha256: 5681df291f1bfb79de26cbd624536787c1619477990fd0730b95dad216db2979

Contents?: true

Size: 550 Bytes

Versions: 3

Compression:

Stored size: 550 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)
    end

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

    def destroy?
      @post.postable.first_post != @post && update?
    end

    private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
thredded-0.3.2 app/policies/thredded/private_post_policy.rb
thredded-0.3.1 app/policies/thredded/private_post_policy.rb
thredded-0.3.0 app/policies/thredded/private_post_policy.rb