hummingbird-me/kitsu-server

View on GitHub
app/policies/follow_policy.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
91%
# frozen_string_literal: true

class FollowPolicy < ApplicationPolicy
  def create?
    is_owner? && !user.has_role?(:banned)
  end
  alias_method :update?, :create?
  alias_method :destroy?, :create?

  def visible_attributes(all)
    is_owner? ? all : all - %i[hidden]
  end
  alias_method :editable_attributes, :visible_attributes

  # Override to user follower instead of user
  def is_owner? # rubocop:disable Naming/PredicateName
    return false unless user && record.follower_id == user.id
    return false if record.follower_id_was && record.follower_id_was != user.id

    true
  end
end