about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authornullkal <nullkal@nil.nu>2017-10-08 03:26:43 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-10-07 20:26:43 +0200
commit633426b2616e8559acfa76f4294a51afcf434fc2 (patch)
tree38759fbbd11bb3b40bc29e1a0f8ce048d15c7ce3 /app
parentf486ef2666dacbcb6fcd26e371bb5e945369dcfe (diff)
Add moderation note (#5240)
* Add moderation note

* Add frozen_string_literal

* Make rspec pass
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/account_moderation_notes_controller.rb31
-rw-r--r--app/controllers/admin/accounts_controller.rb5
-rw-r--r--app/helpers/admin/account_moderation_notes_helper.rb4
-rw-r--r--app/models/account.rb4
-rw-r--r--app/models/account_moderation_note.rb22
-rw-r--r--app/views/admin/account_moderation_notes/_account_moderation_note.html.haml10
-rw-r--r--app/views/admin/accounts/show.html.haml22
7 files changed, 97 insertions, 1 deletions
diff --git a/app/controllers/admin/account_moderation_notes_controller.rb b/app/controllers/admin/account_moderation_notes_controller.rb
new file mode 100644
index 000000000..414a875d0
--- /dev/null
+++ b/app/controllers/admin/account_moderation_notes_controller.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+class Admin::AccountModerationNotesController < Admin::BaseController
+  def create
+    @account_moderation_note = current_account.account_moderation_notes.new(resource_params)
+    if @account_moderation_note.save
+      @target_account = @account_moderation_note.target_account
+      redirect_to admin_account_path(@target_account.id), notice: I18n.t('admin.account_moderation_notes.created_msg')
+    else
+      @account = @account_moderation_note.target_account
+      @moderation_notes = @account.targeted_moderation_notes.latest
+      render template: 'admin/accounts/show'
+    end
+  end
+
+  def destroy
+    @account_moderation_note = AccountModerationNote.find(params[:id])
+    @target_account = @account_moderation_note.target_account
+    @account_moderation_note.destroy
+    redirect_to admin_account_path(@target_account.id), notice: I18n.t('admin.account_moderation_notes.destroyed_msg')
+  end
+
+  private
+
+  def resource_params
+    params.require(:account_moderation_note).permit(
+      :content,
+      :target_account_id
+    )
+  end
+end
diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb
index 54c659e1b..ffa4dc850 100644
--- a/app/controllers/admin/accounts_controller.rb
+++ b/app/controllers/admin/accounts_controller.rb
@@ -9,7 +9,10 @@ module Admin
       @accounts = filtered_accounts.page(params[:page])
     end
 
-    def show; end
+    def show
+      @account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
+      @moderation_notes = @account.targeted_moderation_notes.latest
+    end
 
     def subscribe
       Pubsubhubbub::SubscribeWorker.perform_async(@account.id)
diff --git a/app/helpers/admin/account_moderation_notes_helper.rb b/app/helpers/admin/account_moderation_notes_helper.rb
new file mode 100644
index 000000000..b17c52264
--- /dev/null
+++ b/app/helpers/admin/account_moderation_notes_helper.rb
@@ -0,0 +1,4 @@
+# frozen_string_literal: true
+
+module Admin::AccountModerationNotesHelper
+end
diff --git a/app/models/account.rb b/app/models/account.rb
index 54035d94a..88f16026d 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -90,6 +90,10 @@ class Account < ApplicationRecord
   has_many :reports
   has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id
 
+  # Moderation notes
+  has_many :account_moderation_notes
+  has_many :targeted_moderation_notes, class_name: 'AccountModerationNote', foreign_key: :target_account_id
+
   scope :remote, -> { where.not(domain: nil) }
   scope :local, -> { where(domain: nil) }
   scope :without_followers, -> { where(followers_count: 0) }
diff --git a/app/models/account_moderation_note.rb b/app/models/account_moderation_note.rb
new file mode 100644
index 000000000..be52d10b6
--- /dev/null
+++ b/app/models/account_moderation_note.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+# == Schema Information
+#
+# Table name: account_moderation_notes
+#
+#  id                :integer          not null, primary key
+#  content           :text             not null
+#  account_id        :integer
+#  target_account_id :integer
+#  created_at        :datetime         not null
+#  updated_at        :datetime         not null
+#
+
+class AccountModerationNote < ApplicationRecord
+  belongs_to :account
+  belongs_to :target_account, class_name: 'Account'
+
+  scope :latest, -> { reorder('created_at DESC') }
+
+  validates :content, presence: true, length: { maximum: 500 }
+end
diff --git a/app/views/admin/account_moderation_notes/_account_moderation_note.html.haml b/app/views/admin/account_moderation_notes/_account_moderation_note.html.haml
new file mode 100644
index 000000000..4651630e9
--- /dev/null
+++ b/app/views/admin/account_moderation_notes/_account_moderation_note.html.haml
@@ -0,0 +1,10 @@
+%tr
+  %td
+    = simple_format(h(account_moderation_note.content))
+  %td
+    = account_moderation_note.account.acct
+  %td
+    %time.formatted{ datetime: account_moderation_note.created_at.iso8601, title: l(account_moderation_note.created_at) }
+      = l account_moderation_note.created_at
+  %td
+    = link_to t('admin.account_moderation_notes.delete'), admin_account_moderation_note_path(account_moderation_note), method: :delete
diff --git a/app/views/admin/accounts/show.html.haml b/app/views/admin/accounts/show.html.haml
index 3775b6721..1f5c8fcf5 100644
--- a/app/views/admin/accounts/show.html.haml
+++ b/app/views/admin/accounts/show.html.haml
@@ -129,3 +129,25 @@
         %tr
           %th= t('admin.accounts.followers_url')
           %td= link_to @account.followers_url, @account.followers_url
+
+%hr
+%h3= t('admin.accounts.moderation_notes')
+
+= simple_form_for @account_moderation_note, url: admin_account_moderation_notes_path do |f|
+  = render 'shared/error_messages', object: @account_moderation_note
+
+  = f.input :content
+  = f.hidden_field :target_account_id
+
+  .actions
+  = f.button :button, t('admin.account_moderation_notes.create'), type: :submit
+
+.table-wrapper
+  %table.table
+    %thead
+      %tr
+        %th
+        %th= t('admin.account_moderation_notes.account')
+        %th= t('admin.account_moderation_notes.created_at')
+    %tbody
+      = render @moderation_notes