mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-17 20:32:56 +00:00
92c06a1113
Conflicts: - `app/controllers/admin/base_controller.rb`: Minor conflict caused by glitch-soc's theming system. - `app/javascript/mastodon/initial_state.js`: Minor conflict caused by glitch-soc making use of max_toot_chars. - `app/models/form/admin_settings.rb`: Minor conflict caused by glitch-soc's theming system. - `app/models/trends.rb`: Minor conflict caused by glitch-soc having more granular notification settings for trends. - `app/views/admin/accounts/index.html.haml`: Minor conflict caused by glitch-soc's theming system. - `app/views/admin/instances/show.html.haml`: Minor conflict caused by glitch-soc's theming system. - `app/views/layouts/application.html.haml`: Minor conflict caused by glitch-soc's theming system. - `app/views/settings/preferences/notifications/show.html.haml`: Minor conflict caused by glitch-soc having more granular notification settings for trends. - `config/navigation.rb`: Minor conflict caused by glitch-soc having additional navigation items for the theming system while upstream slightly changed every line.
105 lines
2.3 KiB
Ruby
105 lines
2.3 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?
|
|
role.can?(:manage_reports, :manage_users)
|
|
end
|
|
|
|
def show?
|
|
return false if author.suspended?
|
|
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? && !author_blocking_domain?)
|
|
end
|
|
end
|
|
|
|
def reblog?
|
|
!requires_mention? && (!private? || owned?) && show? && !blocking_author?
|
|
end
|
|
|
|
def favourite?
|
|
show? && !blocking_author?
|
|
end
|
|
|
|
def destroy?
|
|
role.can?(:manage_reports) || owned?
|
|
end
|
|
|
|
alias unreblog? destroy?
|
|
|
|
def update?
|
|
role.can?(:manage_reports) || owned?
|
|
end
|
|
|
|
def review?
|
|
role.can?(:manage_taxonomies)
|
|
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 author_blocking_domain?
|
|
return false if current_account.nil? || current_account.domain.nil?
|
|
|
|
author.domain_blocking?(current_account.domain)
|
|
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
|