hummingbird-me/kitsu-server

View on GitHub
app/policies/comment_like_policy.rb

Summary

Maintainability
A
2 hrs
Test Coverage
A
90%
class CommentLikePolicy < ApplicationPolicy
  include GroupPermissionsHelpers

  def update?
    false
  end

  def create?
    return false unless user
    return false if user.unregistered?
    return false if user.blocked?(record.comment.user)
    return false if user.blocked?(record.comment.post.user)
    return false if user.has_role?(:banned)
    if group
      return false if banned_from_group?
      return false if group.closed? && !member?
    end
    is_owner?
  end
  alias_method :destroy?, :create?

  def group
    record.comment.post.target_group
  end

  class Scope < Scope
    def resolve
      scope.where.not(user_id: blocked_users)
    end
  end
end