about summary refs log tree commit diff
path: root/app/models/admin
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/admin')
-rw-r--r--app/models/admin/account_action.rb8
-rw-r--r--app/models/admin/import.rb29
-rw-r--r--app/models/admin/status_batch_action.rb6
3 files changed, 40 insertions, 3 deletions
diff --git a/app/models/admin/account_action.rb b/app/models/admin/account_action.rb
index 850ea6d82..aed3bc0c7 100644
--- a/app/models/admin/account_action.rb
+++ b/app/models/admin/account_action.rb
@@ -92,6 +92,10 @@ class Admin::AccountAction
       text: text_for_warning,
       status_ids: status_ids
     )
+
+    # A log entry is only interesting if the warning contains
+    # custom text from someone. Otherwise it's just noise.
+    log_action(:create, @warning) if @warning.text.present? && type == 'none'
   end
 
   def process_reports!
@@ -160,8 +164,8 @@ class Admin::AccountAction
 
   def reports
     @reports ||= begin
-      if type == 'none' && with_report?
-        [report]
+      if type == 'none'
+        with_report? ? [report] : []
       else
         Report.where(target_account: target_account).unresolved
       end
diff --git a/app/models/admin/import.rb b/app/models/admin/import.rb
new file mode 100644
index 000000000..c305be237
--- /dev/null
+++ b/app/models/admin/import.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+# A non-activerecord helper class for csv upload
+class Admin::Import
+  extend ActiveModel::Callbacks
+  include ActiveModel::Model
+  include Paperclip::Glue
+
+  FILE_TYPES = %w(text/plain text/csv application/csv).freeze
+
+  # Paperclip required callbacks
+  define_model_callbacks :save, only: [:after]
+  define_model_callbacks :destroy, only: [:before, :after]
+
+  attr_accessor :data_file_name, :data_content_type
+
+  has_attached_file :data
+  validates_attachment_content_type :data, content_type: FILE_TYPES
+  validates_attachment_presence :data
+  validates_with AdminImportValidator, on: :create
+
+  def save
+    run_callbacks :save
+  end
+
+  def destroy
+    run_callbacks :destroy
+  end
+end
diff --git a/app/models/admin/status_batch_action.rb b/app/models/admin/status_batch_action.rb
index 631af183c..7bf6fa6da 100644
--- a/app/models/admin/status_batch_action.rb
+++ b/app/models/admin/status_batch_action.rb
@@ -103,7 +103,7 @@ class Admin::StatusBatchAction
 
   def handle_report!
     @report = Report.new(report_params) unless with_report?
-    @report.status_ids = (@report.status_ids + status_ids.map(&:to_i)).uniq
+    @report.status_ids = (@report.status_ids + allowed_status_ids).uniq
     @report.save!
 
     @report_id = @report.id
@@ -135,4 +135,8 @@ class Admin::StatusBatchAction
   def report_params
     { account: current_account, target_account: target_account }
   end
+
+  def allowed_status_ids
+    AccountStatusesFilter.new(@report.target_account, current_account).results.with_discarded.where(id: status_ids).pluck(:id)
+  end
 end