Browse Source

try to tighten up local only toot stuff, like... properly (#163)

* try to tighten up local only toot stuff, like... properly

* try to un-break tests
closed-social-glitch-2
beatrix 7 years ago
committed by GitHub
parent
commit
f0a2a6c875
4 changed files with 13 additions and 2 deletions
  1. +1
    -1
      app/controllers/stream_entries_controller.rb
  2. +5
    -0
      app/models/status.rb
  3. +1
    -1
      app/models/stream_entry.rb
  4. +6
    -0
      app/policies/status_policy.rb

+ 1
- 1
app/controllers/stream_entries_controller.rb View File

@ -48,7 +48,7 @@ class StreamEntriesController < ApplicationController
@type = @stream_entry.activity_type.downcase @type = @stream_entry.activity_type.downcase
raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil? raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
authorize @stream_entry.activity, :show? if @stream_entry.hidden?
authorize @stream_entry.activity, :show? if @stream_entry.hidden? || @stream_entry.local_only?
rescue Mastodon::NotPermittedError rescue Mastodon::NotPermittedError
# Reraise in order to get a 404 # Reraise in order to get a 404
raise ActiveRecord::RecordNotFound raise ActiveRecord::RecordNotFound

+ 5
- 0
app/models/status.rb View File

@ -257,6 +257,11 @@ class Status < ApplicationRecord
end end
end end
def local_only?
# match both with and without U+FE0F (the emoji variation selector)
/👁\ufe0f?\z/.match?(content)
end
private private
def store_uri def store_uri

+ 1
- 1
app/models/stream_entry.rb View File

@ -28,7 +28,7 @@ class StreamEntry < ApplicationRecord
scope :recent, -> { reorder(id: :desc) } scope :recent, -> { reorder(id: :desc) }
scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES) } scope :with_includes, -> { includes(:account, status: STATUS_INCLUDES) }
delegate :target, :title, :content, :thread,
delegate :target, :title, :content, :thread, :local_only?,
to: :status, to: :status,
allow_nil: true allow_nil: true

+ 6
- 0
app/policies/status_policy.rb View File

@ -9,6 +9,8 @@ class StatusPolicy
end end
def show? def show?
return false if local_only? && account.nil?
if direct? if direct?
owned? || status.mentions.where(account: account).exists? owned? || status.mentions.where(account: account).exists?
elsif private? elsif private?
@ -45,4 +47,8 @@ class StatusPolicy
def private? def private?
status.private_visibility? status.private_visibility?
end end
def local_only?
status.local_only?
end
end end

Loading…
Cancel
Save