mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-06 18:01:05 +00:00
Compare commits
4 Commits
6fe2a34325
...
23a2aa1896
Author | SHA1 | Date | |
---|---|---|---|
![]() |
23a2aa1896 | ||
![]() |
49063a30d5 | ||
![]() |
63b79c302c | ||
![]() |
18a045e221 |
|
@ -7,16 +7,13 @@ module Admin
|
||||||
def new
|
def new
|
||||||
authorize @account, :show?
|
authorize @account, :show?
|
||||||
|
|
||||||
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true, include_statuses: true)
|
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true, include_statuses: true)
|
||||||
@warning_presets = AccountWarningPreset.all
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
authorize @account, :show?
|
authorize @account, :show?
|
||||||
|
|
||||||
@account_action = Admin::AccountAction.new(resource_params)
|
@account_action = Admin::AccountAction.new(resource_params.merge(target_account: @account, current_account:))
|
||||||
@account_action.target_account = @account
|
|
||||||
@account_action.current_account = current_account
|
|
||||||
|
|
||||||
if @account_action.save
|
if @account_action.save
|
||||||
if @account_action.with_report?
|
if @account_action.with_report?
|
||||||
|
@ -25,8 +22,6 @@ module Admin
|
||||||
redirect_to admin_account_path(@account.id)
|
redirect_to admin_account_path(@account.id)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@warning_presets = AccountWarningPreset.all
|
|
||||||
|
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Admin::AccountActionsHelper
|
module Admin::AccountActionsHelper
|
||||||
|
def account_warning_presets
|
||||||
|
AccountWarningPreset.alphabetic
|
||||||
|
end
|
||||||
|
|
||||||
def account_action_type_label(type)
|
def account_action_type_label(type)
|
||||||
safe_join(
|
safe_join(
|
||||||
[
|
[
|
||||||
|
|
|
@ -12,7 +12,15 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class AccountWarningPreset < ApplicationRecord
|
class AccountWarningPreset < ApplicationRecord
|
||||||
|
LABEL_TEXT_LENGTH = 30
|
||||||
|
|
||||||
validates :text, presence: true
|
validates :text, presence: true
|
||||||
|
|
||||||
scope :alphabetic, -> { order(title: :asc, text: :asc) }
|
scope :alphabetic, -> { order(title: :asc, text: :asc) }
|
||||||
|
|
||||||
|
def to_label
|
||||||
|
[title.presence, text.to_s.truncate(LABEL_TEXT_LENGTH)]
|
||||||
|
.compact
|
||||||
|
.join(' - ')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,11 +38,11 @@
|
||||||
|
|
||||||
%hr.spacer/
|
%hr.spacer/
|
||||||
|
|
||||||
- unless @warning_presets.empty?
|
- unless account_warning_presets.empty?
|
||||||
.fields-group
|
.fields-group
|
||||||
= f.input :warning_preset_id,
|
= f.input :warning_preset_id,
|
||||||
collection: @warning_presets,
|
collection: account_warning_presets,
|
||||||
label_method: ->(warning_preset) { [warning_preset.title.presence, truncate(warning_preset.text)].compact.join(' - ') },
|
label_method: ->(warning_preset) { warning_preset.to_label },
|
||||||
wrapper: :with_block_label
|
wrapper: :with_block_label
|
||||||
|
|
||||||
.fields-group
|
.fields-group
|
||||||
|
|
|
@ -3,7 +3,11 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe AccountWarningPreset do
|
RSpec.describe AccountWarningPreset do
|
||||||
describe 'alphabetical' do
|
describe 'Validations' do
|
||||||
|
it { is_expected.to validate_presence_of(:text) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '.alphabetical' do
|
||||||
let(:first) { Fabricate(:account_warning_preset, title: 'aaa', text: 'aaa') }
|
let(:first) { Fabricate(:account_warning_preset, title: 'aaa', text: 'aaa') }
|
||||||
let(:second) { Fabricate(:account_warning_preset, title: 'bbb', text: 'aaa') }
|
let(:second) { Fabricate(:account_warning_preset, title: 'bbb', text: 'aaa') }
|
||||||
let(:third) { Fabricate(:account_warning_preset, title: 'bbb', text: 'bbb') }
|
let(:third) { Fabricate(:account_warning_preset, title: 'bbb', text: 'bbb') }
|
||||||
|
@ -14,4 +18,29 @@ RSpec.describe AccountWarningPreset do
|
||||||
expect(results).to eq([first, second, third])
|
expect(results).to eq([first, second, third])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#to_label' do
|
||||||
|
subject { Fabricate.build(:account_warning_preset, title:, text:).to_label }
|
||||||
|
|
||||||
|
let(:title) { nil }
|
||||||
|
let(:text) { 'Preset text' }
|
||||||
|
|
||||||
|
context 'when title is blank' do
|
||||||
|
it { is_expected.to eq('Preset text') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when title is present' do
|
||||||
|
let(:title) { 'Title' }
|
||||||
|
|
||||||
|
it { is_expected.to eq('Title - Preset text') }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when text is longer than limit' do
|
||||||
|
let(:title) { 'Title' }
|
||||||
|
|
||||||
|
before { stub_const('AccountWarningPreset::LABEL_TEXT_LENGTH', 10) }
|
||||||
|
|
||||||
|
it { is_expected.to eq('Title - Preset ...') }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,7 @@ RSpec.describe 'Admin Account Actions' do
|
||||||
|
|
||||||
describe 'Creating a new account action on an account' do
|
describe 'Creating a new account action on an account' do
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
|
let!(:account_warning_preset) { Fabricate :account_warning_preset }
|
||||||
|
|
||||||
it 'creates the action and redirects to the account page' do
|
it 'creates the action and redirects to the account page' do
|
||||||
visit new_admin_account_action_path(account_id: account.id)
|
visit new_admin_account_action_path(account_id: account.id)
|
||||||
|
@ -23,6 +24,7 @@ RSpec.describe 'Admin Account Actions' do
|
||||||
|
|
||||||
# Valid submission
|
# Valid submission
|
||||||
choose(option: 'silence')
|
choose(option: 'silence')
|
||||||
|
select account_warning_preset.to_label, from: 'admin_account_action_warning_preset_id'
|
||||||
expect { submit_form }
|
expect { submit_form }
|
||||||
.to change { account.strikes.count }.by(1)
|
.to change { account.strikes.count }.by(1)
|
||||||
expect(page)
|
expect(page)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user