Sha256: ee77428c727f7ef2346ceb503e1ebf69857dda9e36cb425416a4c5c5cf4b20d3

Contents?: true

Size: 521 Bytes

Versions: 8

Compression:

Stored size: 521 Bytes

Contents

module Storytime
  class CommentPolicy
    attr_reader :user, :comment

    def initialize(user, comment)
      @user = user
      @comment = comment
    end

    def is_owner?
      @comment.user == @user
    end

    def is_admin_or_editor?
      (@user && (@user.storytime_admin?(@comment.site) || @user.storytime_editor?(@comment.site)))
    end

    def create?
      is_owner?
    end

    def destroy?
      is_owner? || is_admin_or_editor?
    end

    def permitted_attributes
      [:content]
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
storytime-2.1.6 app/policies/storytime/comment_policy.rb
storytime-2.1.5 app/policies/storytime/comment_policy.rb
storytime-2.1.4 app/policies/storytime/comment_policy.rb
storytime-2.1.3 app/policies/storytime/comment_policy.rb
storytime-2.1.2 app/policies/storytime/comment_policy.rb
storytime-2.1.1 app/policies/storytime/comment_policy.rb
storytime-2.1.0 app/policies/storytime/comment_policy.rb
storytime-2.0.0 app/policies/storytime/comment_policy.rb