status_policy.rb 916 B

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