about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-01-23 21:36:08 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-01-23 21:36:08 +0100
commit434cf8237e7960305b95199b2f0fab75d4da2e60 (patch)
treeee238be51edf0965d87c04393c52a5eb4abbf7f7
parentcca82bf0a2f0ccbf0feda00763fd7df0877845b6 (diff)
Optional domain block attribute that prevents media attachments from being downloaded
-rw-r--r--app/services/process_feed_service.rb2
-rw-r--r--app/services/process_hashtags_service.rb2
-rw-r--r--db/migrate/20170123203248_add_reject_media_to_domain_blocks.rb5
-rw-r--r--db/schema.rb11
4 files changed, 14 insertions, 6 deletions
diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb
index fad03e580..84273680d 100644
--- a/app/services/process_feed_service.rb
+++ b/app/services/process_feed_service.rb
@@ -180,6 +180,8 @@ class ProcessFeedService < BaseService
     end
 
     def media_from_xml(parent, xml)
+      return if DomainBlock.find_by(domain: parent.account.domain)&.reject_media?
+
       xml.xpath('./xmlns:link[@rel="enclosure"]', xmlns: TagManager::XMLNS).each do |link|
         next unless link['href']
 
diff --git a/app/services/process_hashtags_service.rb b/app/services/process_hashtags_service.rb
index 8d7fbe92b..617a38159 100644
--- a/app/services/process_hashtags_service.rb
+++ b/app/services/process_hashtags_service.rb
@@ -4,7 +4,7 @@ class ProcessHashtagsService < BaseService
   def call(status, tags = [])
     tags = status.text.scan(Tag::HASHTAG_RE).map(&:first) if status.local?
 
-    tags.map { |str| str.mb_chars.downcase }.uniq{ |t| t.to_s }.each do |tag|
+    tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |tag|
       status.tags << Tag.where(name: tag).first_or_initialize(name: tag)
     end
 
diff --git a/db/migrate/20170123203248_add_reject_media_to_domain_blocks.rb b/db/migrate/20170123203248_add_reject_media_to_domain_blocks.rb
new file mode 100644
index 000000000..999fccda0
--- /dev/null
+++ b/db/migrate/20170123203248_add_reject_media_to_domain_blocks.rb
@@ -0,0 +1,5 @@
+class AddRejectMediaToDomainBlocks < ActiveRecord::Migration[5.0]
+  def change
+    add_column :domain_blocks, :reject_media, :boolean
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 6d28f059d..3876faa56 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20170123162658) do
+ActiveRecord::Schema.define(version: 20170123203248) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -55,10 +55,11 @@ ActiveRecord::Schema.define(version: 20170123162658) do
   end
 
   create_table "domain_blocks", force: :cascade do |t|
-    t.string   "domain",     default: "", null: false
-    t.datetime "created_at",              null: false
-    t.datetime "updated_at",              null: false
-    t.integer  "severity",   default: 0
+    t.string   "domain",       default: "", null: false
+    t.datetime "created_at",                null: false
+    t.datetime "updated_at",                null: false
+    t.integer  "severity",     default: 0
+    t.boolean  "reject_media"
     t.index ["domain"], name: "index_domain_blocks_on_domain", unique: true, using: :btree
   end