2017-05-29 12:22:22 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-11 14:23:33 -05:00
|
|
|
class StatusPolicy < ApplicationPolicy
|
|
|
|
def index?
|
|
|
|
staff?
|
2017-05-29 12:22:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def show?
|
2017-11-17 10:07:21 -05:00
|
|
|
return false if local_only? && current_account.nil?
|
2017-10-09 09:56:17 -04:00
|
|
|
|
2017-05-30 09:16:14 -04:00
|
|
|
if direct?
|
2017-11-11 14:23:33 -05:00
|
|
|
owned? || record.mentions.where(account: current_account).exists?
|
2017-05-30 09:16:14 -04:00
|
|
|
elsif private?
|
2017-11-11 14:23:33 -05:00
|
|
|
owned? || current_account&.following?(author) || record.mentions.where(account: current_account).exists?
|
2017-05-29 12:22:22 -04:00
|
|
|
else
|
2017-11-11 14:23:33 -05:00
|
|
|
current_account.nil? || !author.blocking?(current_account)
|
2017-05-29 12:22:22 -04:00
|
|
|
end
|
|
|
|
end
|
2017-05-30 09:16:14 -04:00
|
|
|
|
|
|
|
def reblog?
|
2018-04-17 17:35:45 -04:00
|
|
|
!direct? && (!private? || owned?) && show?
|
2017-05-30 09:16:14 -04:00
|
|
|
end
|
|
|
|
|
2017-05-30 16:56:31 -04:00
|
|
|
def destroy?
|
2017-11-11 14:23:33 -05:00
|
|
|
staff? || owned?
|
2017-05-30 16:56:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
alias unreblog? destroy?
|
|
|
|
|
2017-11-11 14:23:33 -05:00
|
|
|
def update?
|
|
|
|
staff?
|
2017-05-30 16:56:31 -04:00
|
|
|
end
|
|
|
|
|
2017-11-11 14:23:33 -05:00
|
|
|
private
|
|
|
|
|
2017-05-30 09:16:14 -04:00
|
|
|
def direct?
|
2017-11-11 14:23:33 -05:00
|
|
|
record.direct_visibility?
|
2017-05-30 09:16:14 -04:00
|
|
|
end
|
|
|
|
|
2017-05-30 16:56:31 -04:00
|
|
|
def owned?
|
2017-11-11 14:23:33 -05:00
|
|
|
author.id == current_account&.id
|
2017-05-30 16:56:31 -04:00
|
|
|
end
|
|
|
|
|
2017-05-30 09:16:14 -04:00
|
|
|
def private?
|
2017-11-11 14:23:33 -05:00
|
|
|
record.private_visibility?
|
|
|
|
end
|
|
|
|
|
|
|
|
def author
|
|
|
|
record.account
|
2017-05-30 09:16:14 -04:00
|
|
|
end
|
2017-10-09 09:56:17 -04:00
|
|
|
|
|
|
|
def local_only?
|
2017-11-16 02:21:16 -05:00
|
|
|
record.local_only?
|
2017-10-09 09:56:17 -04:00
|
|
|
end
|
2017-05-29 12:22:22 -04:00
|
|
|
end
|