Add moderation note (#5240)
* Add moderation note * Add frozen_string_literal * Make rspec passgh/stable
parent
f486ef2666
commit
633426b261
|
@ -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
|
|
@ -9,7 +9,10 @@ module Admin
|
||||||
@accounts = filtered_accounts.page(params[:page])
|
@accounts = filtered_accounts.page(params[:page])
|
||||||
end
|
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
|
def subscribe
|
||||||
Pubsubhubbub::SubscribeWorker.perform_async(@account.id)
|
Pubsubhubbub::SubscribeWorker.perform_async(@account.id)
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Admin::AccountModerationNotesHelper
|
||||||
|
end
|
|
@ -90,6 +90,10 @@ class Account < ApplicationRecord
|
||||||
has_many :reports
|
has_many :reports
|
||||||
has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id
|
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 :remote, -> { where.not(domain: nil) }
|
||||||
scope :local, -> { where(domain: nil) }
|
scope :local, -> { where(domain: nil) }
|
||||||
scope :without_followers, -> { where(followers_count: 0) }
|
scope :without_followers, -> { where(followers_count: 0) }
|
||||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -129,3 +129,25 @@
|
||||||
%tr
|
%tr
|
||||||
%th= t('admin.accounts.followers_url')
|
%th= t('admin.accounts.followers_url')
|
||||||
%td= link_to @account.followers_url, @account.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
|
||||||
|
|
|
@ -76,6 +76,7 @@ en:
|
||||||
silenced: Silenced
|
silenced: Silenced
|
||||||
suspended: Suspended
|
suspended: Suspended
|
||||||
title: Moderation
|
title: Moderation
|
||||||
|
moderation_notes: Moderation notes
|
||||||
most_recent_activity: Most recent activity
|
most_recent_activity: Most recent activity
|
||||||
most_recent_ip: Most recent IP
|
most_recent_ip: Most recent IP
|
||||||
not_subscribed: Not subscribed
|
not_subscribed: Not subscribed
|
||||||
|
@ -109,6 +110,15 @@ en:
|
||||||
unsubscribe: Unsubscribe
|
unsubscribe: Unsubscribe
|
||||||
username: Username
|
username: Username
|
||||||
web: Web
|
web: Web
|
||||||
|
|
||||||
|
account_moderation_notes:
|
||||||
|
account: Moderator
|
||||||
|
created_at: Date
|
||||||
|
create: Create
|
||||||
|
created_msg: Moderation note successfully created!
|
||||||
|
delete: Delete
|
||||||
|
destroyed_msg: Moderation note successfully destroyed!
|
||||||
|
|
||||||
custom_emojis:
|
custom_emojis:
|
||||||
copied_msg: Successfully created local copy of the emoji
|
copied_msg: Successfully created local copy of the emoji
|
||||||
copy: Copy
|
copy: Copy
|
||||||
|
|
|
@ -147,6 +147,8 @@ Rails.application.routes.draw do
|
||||||
post :disable
|
post :disable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :account_moderation_notes, only: [:create, :destroy]
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/admin', to: redirect('/admin/settings/edit', status: 302)
|
get '/admin', to: redirect('/admin/settings/edit', status: 302)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
class CreateAccountModerationNotes < ActiveRecord::Migration[5.1]
|
||||||
|
def change
|
||||||
|
create_table :account_moderation_notes do |t|
|
||||||
|
t.text :content, null: false
|
||||||
|
t.references :account
|
||||||
|
t.references :target_account
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
add_foreign_key :account_moderation_notes, :accounts, column: :target_account_id
|
||||||
|
end
|
||||||
|
end
|
11
db/schema.rb
11
db/schema.rb
|
@ -23,6 +23,16 @@ ActiveRecord::Schema.define(version: 20171006142024) do
|
||||||
t.index ["account_id", "domain"], name: "index_account_domain_blocks_on_account_id_and_domain", unique: true
|
t.index ["account_id", "domain"], name: "index_account_domain_blocks_on_account_id_and_domain", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "account_moderation_notes", force: :cascade do |t|
|
||||||
|
t.text "content", null: false
|
||||||
|
t.bigint "account_id"
|
||||||
|
t.bigint "target_account_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
t.index ["account_id"], name: "index_account_moderation_notes_on_account_id"
|
||||||
|
t.index ["target_account_id"], name: "index_account_moderation_notes_on_target_account_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "accounts", force: :cascade do |t|
|
create_table "accounts", force: :cascade do |t|
|
||||||
t.string "username", default: "", null: false
|
t.string "username", default: "", null: false
|
||||||
t.string "domain"
|
t.string "domain"
|
||||||
|
@ -449,6 +459,7 @@ ActiveRecord::Schema.define(version: 20171006142024) do
|
||||||
end
|
end
|
||||||
|
|
||||||
add_foreign_key "account_domain_blocks", "accounts", name: "fk_206c6029bd", on_delete: :cascade
|
add_foreign_key "account_domain_blocks", "accounts", name: "fk_206c6029bd", on_delete: :cascade
|
||||||
|
add_foreign_key "account_moderation_notes", "accounts", column: "target_account_id"
|
||||||
add_foreign_key "blocks", "accounts", column: "target_account_id", name: "fk_9571bfabc1", on_delete: :cascade
|
add_foreign_key "blocks", "accounts", column: "target_account_id", name: "fk_9571bfabc1", on_delete: :cascade
|
||||||
add_foreign_key "blocks", "accounts", name: "fk_4269e03e65", on_delete: :cascade
|
add_foreign_key "blocks", "accounts", name: "fk_4269e03e65", on_delete: :cascade
|
||||||
add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
|
add_foreign_key "conversation_mutes", "accounts", name: "fk_225b4212bb", on_delete: :cascade
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Admin::AccountModerationNotesController, type: :controller do
|
||||||
|
end
|
|
@ -0,0 +1,4 @@
|
||||||
|
Fabricator(:account_moderation_note) do
|
||||||
|
content "MyText"
|
||||||
|
account nil
|
||||||
|
end
|
|
@ -0,0 +1,15 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
# Specs in this file have access to a helper object that includes
|
||||||
|
# the Admin::AccountModerationNotesHelper. For example:
|
||||||
|
#
|
||||||
|
# describe Admin::AccountModerationNotesHelper do
|
||||||
|
# describe "string concat" do
|
||||||
|
# it "concats two strings with spaces" do
|
||||||
|
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
RSpec.describe Admin::AccountModerationNotesHelper, type: :helper do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe AccountModerationNote, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Reference in New Issue