mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-24 01:08:08 +01:00
dcded13a99
Conflicts: - .github/ISSUE_TEMPLATE/bug_report.md Took our version. - CONTRIBUTING.md Updated the embedded copy of upstream's version. - README.md Took our version. - app/policies/status_policy.rb Not a real conflict, took code from both. - app/views/layouts/embedded.html.haml Added upstream's changes (dns-prefetch) and fixed `%body.embed` - app/views/settings/preferences/show.html.haml Reverted some of upstream changes, as we have a page dedicated for flavours and skins. - config/initializers/content_security_policy.rb Kept our version of the CSP. - config/initializers/doorkeeper.rb Not a real conflict, took code from both.
93 lines
1.9 KiB
Ruby
93 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class StatusPolicy < ApplicationPolicy
|
|
def initialize(current_account, record, preloaded_relations = {})
|
|
super(current_account, record)
|
|
|
|
@preloaded_relations = preloaded_relations
|
|
end
|
|
|
|
def index?
|
|
staff?
|
|
end
|
|
|
|
def show?
|
|
return false if local_only? && (current_account.nil? || !current_account.local?)
|
|
|
|
if requires_mention?
|
|
owned? || mention_exists?
|
|
elsif private?
|
|
owned? || following_author? || mention_exists?
|
|
else
|
|
current_account.nil? || !author_blocking?
|
|
end
|
|
end
|
|
|
|
def reblog?
|
|
!requires_mention? && (!private? || owned?) && show? && !blocking_author?
|
|
end
|
|
|
|
def favourite?
|
|
show? && !blocking_author?
|
|
end
|
|
|
|
def destroy?
|
|
staff? || owned?
|
|
end
|
|
|
|
alias unreblog? destroy?
|
|
|
|
def update?
|
|
staff?
|
|
end
|
|
|
|
private
|
|
|
|
def requires_mention?
|
|
record.direct_visibility? || record.limited_visibility?
|
|
end
|
|
|
|
def owned?
|
|
author.id == current_account&.id
|
|
end
|
|
|
|
def private?
|
|
record.private_visibility?
|
|
end
|
|
|
|
def mention_exists?
|
|
return false if current_account.nil?
|
|
|
|
if record.mentions.loaded?
|
|
record.mentions.any? { |mention| mention.account_id == current_account.id }
|
|
else
|
|
record.mentions.where(account: current_account).exists?
|
|
end
|
|
end
|
|
|
|
def blocking_author?
|
|
return false if current_account.nil?
|
|
|
|
@preloaded_relations[:blocking] ? @preloaded_relations[:blocking][author.id] : current_account.blocking?(author)
|
|
end
|
|
|
|
def author_blocking?
|
|
return false if current_account.nil?
|
|
|
|
@preloaded_relations[:blocked_by] ? @preloaded_relations[:blocked_by][author.id] : author.blocking?(current_account)
|
|
end
|
|
|
|
def following_author?
|
|
return false if current_account.nil?
|
|
|
|
@preloaded_relations[:following] ? @preloaded_relations[:following][author.id] : current_account.following?(author)
|
|
end
|
|
|
|
def author
|
|
record.account
|
|
end
|
|
|
|
def local_only?
|
|
record.local_only?
|
|
end
|
|
end
|