about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/api/v1/filters_controller.rb2
-rw-r--r--app/controllers/filters_controller.rb2
-rw-r--r--app/helpers/filter_helper.rb1
-rw-r--r--app/models/custom_filter.rb1
-rw-r--r--app/views/filters/_fields.html.haml7
-rw-r--r--config/locales/simple_form.en.yml1
-rw-r--r--db/migrate/20191010005320_add_no_desc_to_custom_filters.rb7
-rw-r--r--db/schema.rb3
8 files changed, 20 insertions, 4 deletions
diff --git a/app/controllers/api/v1/filters_controller.rb b/app/controllers/api/v1/filters_controller.rb
index 6b8b82285..8194480fa 100644
--- a/app/controllers/api/v1/filters_controller.rb
+++ b/app/controllers/api/v1/filters_controller.rb
@@ -43,6 +43,6 @@ class Api::V1::FiltersController < Api::BaseController
   end
 
   def resource_params
-    params.permit(:phrase, :expires_in, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, :desc, context: [])
+    params.permit(:phrase, :expires_in, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, :desc, :no_desc, context: [])
   end
 end
diff --git a/app/controllers/filters_controller.rb b/app/controllers/filters_controller.rb
index c80e6853a..8a4636ba2 100644
--- a/app/controllers/filters_controller.rb
+++ b/app/controllers/filters_controller.rb
@@ -58,7 +58,7 @@ class FiltersController < ApplicationController
   end
 
   def resource_params
-    params.require(:custom_filter).permit(:phrase, :expires_in, :irreversible, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, :desc, context: [])
+    params.require(:custom_filter).permit(:phrase, :expires_in, :irreversible, :whole_word, :exclude_media, :media_only, :status_text, :spoiler, :tags, :custom_cw, :override_cw, :desc, :no_desc, context: [])
   end
 
   def set_body_classes
diff --git a/app/helpers/filter_helper.rb b/app/helpers/filter_helper.rb
index 3e3b4b748..a4a86496f 100644
--- a/app/helpers/filter_helper.rb
+++ b/app/helpers/filter_helper.rb
@@ -41,6 +41,7 @@ module FilterHelper
       matched ||= regex.match(spoiler_text).present? if filter.spoiler && spoiler_text.present?
       matched ||= regex.match(tags).present? if filter.tags && tags.present?
       matched ||= regex.match(descs).present? if filter.desc && descs.present?
+      matched ||= status.media_attachments.all { |a| a.description.blank? } if filter.no_desc && status.media_attachments.any?
 
       if matched
         filter_thread(receiver_id, status.conversation_id) if filter.thread && filter.custom_cw.blank?
diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb
index fb269d8f4..5feb5fd7d 100644
--- a/app/models/custom_filter.rb
+++ b/app/models/custom_filter.rb
@@ -21,6 +21,7 @@
 #  custom_cw     :text
 #  override_cw   :boolean          default(FALSE), not null
 #  desc          :boolean          default(FALSE), not null
+#  no_desc       :boolean          default(FALSE), not null
 #
 
 class CustomFilter < ApplicationRecord
diff --git a/app/views/filters/_fields.html.haml b/app/views/filters/_fields.html.haml
index 6389e11b1..da0add2ea 100644
--- a/app/views/filters/_fields.html.haml
+++ b/app/views/filters/_fields.html.haml
@@ -16,8 +16,13 @@
   = f.input :status_text, wrapper: :with_label
   = f.input :spoiler, wrapper: :with_label
   = f.input :tags, wrapper: :with_label
-  = f.input :desc, wrapper: :with_label
   = f.input :thread, wrapper: :with_label
+
+.fields-group
+  = f.input :desc, wrapper: :with_label
+  = f.input :no_desc, wrapper: :with_label
+
+.fields-group
   = f.input :media_only, wrapper: :with_label
   = f.input :exclude_media, wrapper: :with_label
 
diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index 9f0e5aad7..7035f85e1 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -183,6 +183,7 @@ en:
         whole_word: Whole word
         custom_cw: Set or prepend content warning
         desc: Filter roars with matching media descriptions
+        no_desc: Filter roars WITHOUT media descriptions
         override_cw: Override existing content warning
       boost_interval:
         1: 1 minute
diff --git a/db/migrate/20191010005320_add_no_desc_to_custom_filters.rb b/db/migrate/20191010005320_add_no_desc_to_custom_filters.rb
new file mode 100644
index 000000000..af8144c87
--- /dev/null
+++ b/db/migrate/20191010005320_add_no_desc_to_custom_filters.rb
@@ -0,0 +1,7 @@
+class AddNoDescToCustomFilters < ActiveRecord::Migration[5.2]
+  def change
+    safety_assured {
+      add_column :custom_filters, :no_desc, :boolean, null: false, default: false
+    }
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9636d0e6a..15bfe9943 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: 2019_10_09_231327) do
+ActiveRecord::Schema.define(version: 2019_10_10_005320) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -259,6 +259,7 @@ ActiveRecord::Schema.define(version: 2019_10_09_231327) do
     t.text "custom_cw"
     t.boolean "override_cw", default: false, null: false
     t.boolean "desc", default: false, null: false
+    t.boolean "no_desc", default: false, null: false
     t.index ["account_id"], name: "index_custom_filters_on_account_id"
   end