mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-28 20:55:37 +01:00
Fix sort order of moderation notes on Reports and Accounts (#31528)
This commit is contained in:
parent
a9d0b48b65
commit
c88ba523ee
12 changed files with 105 additions and 8 deletions
|
@ -13,7 +13,7 @@ module Admin
|
||||||
redirect_to admin_account_path(@account_moderation_note.target_account_id), notice: I18n.t('admin.account_moderation_notes.created_msg')
|
redirect_to admin_account_path(@account_moderation_note.target_account_id), notice: I18n.t('admin.account_moderation_notes.created_msg')
|
||||||
else
|
else
|
||||||
@account = @account_moderation_note.target_account
|
@account = @account_moderation_note.target_account
|
||||||
@moderation_notes = @account.targeted_moderation_notes.latest
|
@moderation_notes = @account.targeted_moderation_notes.chronological.includes(:account)
|
||||||
@warnings = @account.strikes.custom.latest
|
@warnings = @account.strikes.custom.latest
|
||||||
|
|
||||||
render 'admin/accounts/show'
|
render 'admin/accounts/show'
|
||||||
|
|
|
@ -33,7 +33,7 @@ module Admin
|
||||||
|
|
||||||
@deletion_request = @account.deletion_request
|
@deletion_request = @account.deletion_request
|
||||||
@account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
|
@account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
|
||||||
@moderation_notes = @account.targeted_moderation_notes.latest
|
@moderation_notes = @account.targeted_moderation_notes.chronological.includes(:account)
|
||||||
@warnings = @account.strikes.includes(:target_account, :account, :appeal).latest
|
@warnings = @account.strikes.includes(:target_account, :account, :appeal).latest
|
||||||
@domain_block = DomainBlock.rule_for(@account.domain)
|
@domain_block = DomainBlock.rule_for(@account.domain)
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ module Admin
|
||||||
|
|
||||||
redirect_to after_create_redirect_path, notice: I18n.t('admin.report_notes.created_msg')
|
redirect_to after_create_redirect_path, notice: I18n.t('admin.report_notes.created_msg')
|
||||||
else
|
else
|
||||||
@report_notes = @report.notes.includes(:account).order(id: :desc)
|
@report_notes = @report.notes.chronological.includes(:account)
|
||||||
@action_logs = @report.history.includes(:target)
|
@action_logs = @report.history.includes(:target)
|
||||||
@form = Admin::StatusBatchAction.new
|
@form = Admin::StatusBatchAction.new
|
||||||
@statuses = @report.statuses.with_includes
|
@statuses = @report.statuses.with_includes
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Admin
|
||||||
authorize @report, :show?
|
authorize @report, :show?
|
||||||
|
|
||||||
@report_note = @report.notes.new
|
@report_note = @report.notes.new
|
||||||
@report_notes = @report.notes.includes(:account).order(id: :desc)
|
@report_notes = @report.notes.chronological.includes(:account)
|
||||||
@action_logs = @report.history.includes(:target)
|
@action_logs = @report.history.includes(:target)
|
||||||
@form = Admin::StatusBatchAction.new
|
@form = Admin::StatusBatchAction.new
|
||||||
@statuses = @report.statuses.with_includes
|
@statuses = @report.statuses.with_includes
|
||||||
|
|
|
@ -18,7 +18,7 @@ class AccountModerationNote < ApplicationRecord
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :target_account, class_name: 'Account'
|
belongs_to :target_account, class_name: 'Account'
|
||||||
|
|
||||||
scope :latest, -> { reorder('created_at DESC') }
|
scope :chronological, -> { reorder(id: :asc) }
|
||||||
|
|
||||||
validates :content, presence: true, length: { maximum: CONTENT_SIZE_LIMIT }
|
validates :content, presence: true, length: { maximum: CONTENT_SIZE_LIMIT }
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ReportNote < ApplicationRecord
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :report, inverse_of: :notes, touch: true
|
belongs_to :report, inverse_of: :notes, touch: true
|
||||||
|
|
||||||
scope :latest, -> { reorder(created_at: :desc) }
|
scope :chronological, -> { reorder(id: :asc) }
|
||||||
|
|
||||||
validates :content, presence: true, length: { maximum: CONTENT_SIZE_LIMIT }
|
validates :content, presence: true, length: { maximum: CONTENT_SIZE_LIMIT }
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,6 +55,23 @@ RSpec.describe Admin::AccountsController do
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
let(:current_user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
|
||||||
|
|
||||||
|
describe 'account moderation notes' do
|
||||||
|
let(:account) { Fabricate(:account) }
|
||||||
|
|
||||||
|
it 'includes moderation notes' do
|
||||||
|
note1 = Fabricate(:account_moderation_note, target_account: account)
|
||||||
|
note2 = Fabricate(:account_moderation_note, target_account: account)
|
||||||
|
|
||||||
|
get :show, params: { id: account.id }
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
moderation_notes = assigns(:moderation_notes).to_a
|
||||||
|
|
||||||
|
expect(moderation_notes.size).to be 2
|
||||||
|
expect(moderation_notes).to eq [note1, note2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'with a remote account' do
|
context 'with a remote account' do
|
||||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,24 @@ RSpec.describe Admin::ReportsController do
|
||||||
expect(response.body)
|
expect(response.body)
|
||||||
.to include(report.comment)
|
.to include(report.comment)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'account moderation notes' do
|
||||||
|
let(:report) { Fabricate(:report) }
|
||||||
|
|
||||||
|
it 'includes moderation notes' do
|
||||||
|
note1 = Fabricate(:report_note, report: report)
|
||||||
|
note2 = Fabricate(:report_note, report: report)
|
||||||
|
|
||||||
|
get :show, params: { id: report }
|
||||||
|
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
report_notes = assigns(:report_notes).to_a
|
||||||
|
|
||||||
|
expect(report_notes.size).to be 2
|
||||||
|
expect(report_notes).to eq [note1, note2]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #resolve' do
|
describe 'POST #resolve' do
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
Fabricator(:account_moderation_note) do
|
Fabricator(:account_moderation_note) do
|
||||||
content 'MyText'
|
content { Faker::Lorem.sentences }
|
||||||
account { Fabricate.build(:account) }
|
account { Fabricate.build(:account) }
|
||||||
target_account { Fabricate.build(:account) }
|
target_account { Fabricate.build(:account) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
Fabricator(:report_note) do
|
Fabricator(:report_note) do
|
||||||
report { Fabricate.build(:report) }
|
report { Fabricate.build(:report) }
|
||||||
account { Fabricate.build(:account) }
|
account { Fabricate.build(:account) }
|
||||||
content 'Test Content'
|
content { Faker::Lorem.sentences }
|
||||||
end
|
end
|
||||||
|
|
31
spec/models/account_moderation_note_spec.rb
Normal file
31
spec/models/account_moderation_note_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe AccountModerationNote do
|
||||||
|
describe 'chronological scope' do
|
||||||
|
it 'returns account moderation notes oldest to newest' do
|
||||||
|
account = Fabricate(:account)
|
||||||
|
note1 = Fabricate(:account_moderation_note, target_account: account)
|
||||||
|
note2 = Fabricate(:account_moderation_note, target_account: account)
|
||||||
|
|
||||||
|
expect(account.targeted_moderation_notes.chronological).to eq [note1, note2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'validations' do
|
||||||
|
it 'is invalid if the content is empty' do
|
||||||
|
report = Fabricate.build(:account_moderation_note, content: '')
|
||||||
|
expect(report.valid?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is invalid if content is longer than character limit' do
|
||||||
|
report = Fabricate.build(:account_moderation_note, content: comment_over_limit)
|
||||||
|
expect(report.valid?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
def comment_over_limit
|
||||||
|
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
31
spec/models/report_note_spec.rb
Normal file
31
spec/models/report_note_spec.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ReportNote do
|
||||||
|
describe 'chronological scope' do
|
||||||
|
it 'returns report notes oldest to newest' do
|
||||||
|
report = Fabricate(:report)
|
||||||
|
note1 = Fabricate(:report_note, report: report)
|
||||||
|
note2 = Fabricate(:report_note, report: report)
|
||||||
|
|
||||||
|
expect(report.notes.chronological).to eq [note1, note2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'validations' do
|
||||||
|
it 'is invalid if the content is empty' do
|
||||||
|
report = Fabricate.build(:report_note, content: '')
|
||||||
|
expect(report.valid?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is invalid if content is longer than character limit' do
|
||||||
|
report = Fabricate.build(:report_note, content: comment_over_limit)
|
||||||
|
expect(report.valid?).to be false
|
||||||
|
end
|
||||||
|
|
||||||
|
def comment_over_limit
|
||||||
|
Faker::Lorem.paragraph_by_chars(number: described_class::CONTENT_SIZE_LIMIT * 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue