You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
899 B

  1. # frozen_string_literal: true
  2. class StatusPolicy < ApplicationPolicy
  3. def index?
  4. staff?
  5. end
  6. def show?
  7. return false if local_only? && current_account.nil?
  8. if direct?
  9. owned? || record.mentions.where(account: current_account).exists?
  10. elsif private?
  11. owned? || current_account&.following?(author) || record.mentions.where(account: current_account).exists?
  12. else
  13. current_account.nil? || !author.blocking?(current_account)
  14. end
  15. end
  16. def reblog?
  17. !direct? && !private? && show?
  18. end
  19. def destroy?
  20. staff? || owned?
  21. end
  22. alias unreblog? destroy?
  23. def update?
  24. staff?
  25. end
  26. private
  27. def direct?
  28. record.direct_visibility?
  29. end
  30. def owned?
  31. author.id == current_account&.id
  32. end
  33. def private?
  34. record.private_visibility?
  35. end
  36. def author
  37. record.account
  38. end
  39. def local_only?
  40. record.local_only?
  41. end
  42. end