Updated StatusPolicy for private group posts

• Updated:
- StatusPolicy for private group posts
- check if owner or staff first if so, show
This commit is contained in:
mgabdev 2021-01-15 16:23:05 -05:00
parent 8c14983e19
commit 33e758a80f

View File

@ -12,10 +12,16 @@ class StatusPolicy < ApplicationPolicy
end
def show?
if requires_mention?
owned? || mention_exists?
elsif private?
owned? || following_author? || mention_exists?
return true if owned? || staff?
if private?
if record.group_id
private_group_member?
else
following_author?
end
elsif requires_mention?
mention_exists?
else
current_account.nil? || !author_blocking?
end
@ -84,6 +90,14 @@ class StatusPolicy < ApplicationPolicy
@preloaded_relations[:following] ? @preloaded_relations[:following][author.id] : current_account.following?(author)
end
def private_group_member?
return false if current_account.nil?
return false if record.group_id.nil?
return true if owned?
GroupAccount.where(group_id: record.group_id, account: current_account).exists?
end
def author
record.account
end