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
1 changed files with 18 additions and 4 deletions

View File

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