Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Commit

Permalink
Improve admin page (mastodon#4121)
Browse files Browse the repository at this point in the history
* Improve admin page

* Fix test

* Add spec

* Improve select style
  • Loading branch information
abcang committed Jul 19, 2017
1 parent 51e5a7a commit c67cad0
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 43 deletions.
5 changes: 2 additions & 3 deletions app/controllers/admin/reported_statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ class ReportedStatusesController < BaseController

def create
@form = Form::StatusBatch.new(form_status_batch_params)
unless @form.save
flash[:alert] = t('admin.statuses.failed_to_execute')
end
flash[:alert] = t('admin.statuses.failed_to_execute') unless @form.save

redirect_to admin_report_path(@report)
end

Expand Down
6 changes: 2 additions & 4 deletions app/controllers/admin/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ def index

def create
@form = Form::StatusBatch.new(form_status_batch_params)
unless @form.save
flash[:alert] = t('admin.statuses.failed_to_execute')
end
flash[:alert] = t('admin.statuses.failed_to_execute') unless @form.save

redirect_to admin_account_statuses_path(@account.id, current_params)
end

Expand Down Expand Up @@ -66,6 +65,5 @@ def current_params
page: page > 1 && page,
}.select { |_, value| value.present? }
end

end
end
21 changes: 18 additions & 3 deletions app/javascript/styles/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@
}
}

.report-status, .account-status {
.report-status,
.account-status {
display: flex;
margin-bottom: 10px;

Expand All @@ -269,7 +270,8 @@
}
}

.report-status__actions, .account-status__actions {
.report-status__actions,
.account-status__actions {
flex: 0 0 auto;
display: flex;
flex-direction: column;
Expand All @@ -284,7 +286,20 @@

.batch-form-box {
display: flex;
margin-top: 5px;
margin-bottom: 10px;

#form_status_batch_action {
margin-right: 5px;
font-size: 14px;
}

.media-spoiler-toggle-buttons {
margin-left: auto;

.button {
overflow: visible;
}
}
}

.batch-checkbox,
Expand Down
15 changes: 6 additions & 9 deletions app/views/admin/reports/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@
%hr/

= form_for(@form, url: admin_report_reported_statuses_path(@report.id)) do |f|
.filters
.filter-subset
%strong= t('admin.statuses.batch_action')
.batch-form-box
.batch-checkbox-all
= check_box_tag :batch_checkbox_all, nil, false
= f.select :action, Form::StatusBatch::ACTION_TYPE.map{|action| [t("admin.statuses.batch.#{action}"), action]}
= f.submit t('admin.statuses.execute'), data: { confirm: t('admin.reports.are_you_sure') }
.filter-subset
.batch-form-box
.batch-checkbox-all
= check_box_tag :batch_checkbox_all, nil, false
= f.select :action, Form::StatusBatch::ACTION_TYPE.map{|action| [t("admin.statuses.batch.#{action}"), action]}
= f.submit t('admin.statuses.execute'), data: { confirm: t('admin.reports.are_you_sure') }, class: 'button'
.media-spoiler-toggle-buttons
.media-spoiler-show-button.button= t('admin.statuses.media.show')
.media-spoiler-hide-button.button= t('admin.statuses.media.hide')
- @report.statuses.each do |status|
Expand Down
27 changes: 13 additions & 14 deletions app/views/admin/statuses/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,26 @@
%i.fa.fa-chevron-left.fa-fw
= t('admin.statuses.back_to_account')

.filters
.filter-subset
%strong= t('admin.statuses.media.title')
%ul
%li= link_to t('admin.statuses.no_media'), admin_account_statuses_path(@account.id, current_params.merge(media: nil)), class: !params[:media] && 'selected'
%li= link_to t('admin.statuses.with_media'), admin_account_statuses_path(@account.id, current_params.merge(media: true)), class: params[:media] && 'selected'

- if @statuses.empty?
.accounts-grid
= render 'accounts/nothing_here'
- else
= form_for(@form, url: admin_account_statuses_path(@account.id)) do |f|
= hidden_field_tag :page, params[:page]
= hidden_field_tag :media, params[:media]
.filters
.filter-subset
%strong= t('admin.statuses.batch_action')
.batch-form-box
.batch-checkbox-all
= check_box_tag :batch_checkbox_all, nil, false
= f.select :action, Form::StatusBatch::ACTION_TYPE.map{|action| [t("admin.statuses.batch.#{action}"), action]}
= f.submit t('admin.statuses.execute'), data: { confirm: t('admin.reports.are_you_sure') }
.filter-subset
%strong= t('admin.statuses.media.title')
%ul
%li= link_to t('admin.statuses.no_media'), admin_account_statuses_path(@account.id, current_params.merge(media: nil)), class: !params[:media] && 'selected'
%li= link_to t('admin.statuses.with_media'), admin_account_statuses_path(@account.id, current_params.merge(media: true)), class: params[:media] && 'selected'
.filter-subset
.batch-form-box
.batch-checkbox-all
= check_box_tag :batch_checkbox_all, nil, false
= f.select :action, Form::StatusBatch::ACTION_TYPE.map{|action| [t("admin.statuses.batch.#{action}"), action]}
= f.submit t('admin.statuses.execute'), data: { confirm: t('admin.reports.are_you_sure') }, class: 'button'
.media-spoiler-toggle-buttons
.media-spoiler-show-button.button= t('admin.statuses.media.show')
.media-spoiler-hide-button.button= t('admin.statuses.media.hide')
- @statuses.each do |status|
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ en:
delete: Delete
nsfw_off: NSFW OFF
nsfw_on: NSFW ON
batch_action: Batch processing
execute: Execute
failed_to_execute: Failed to execute
media:
Expand All @@ -208,6 +207,7 @@ en:
title: Media
no_media: No media
with_media: With media
title: Account statuses
subscriptions:
callback_url: Callback URL
confirmed: Confirmed
Expand Down
10 changes: 8 additions & 2 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ ja:
delete: 削除
nsfw_off: NSFW オフ
nsfw_on: NSFW オン
batch_action: 一括操作
execute: 実行
failed_to_execute: 実行に失敗しました
media:
Expand All @@ -211,11 +210,18 @@ ja:
no_media: メディアなし
with_media: メディアあり
title: トゥート一覧
subscriptions:
callback_url: コールバックURL
confirmed: 確認済み
expires_in: 期限
last_delivery: 最終配送
title: PubSubHubbub
topic: トピック
suggestion:
title: 運営タグ
title: 管理
trend_ng_word:
title: NGワード
title: 管理
admin_mailer:
new_report:
body: "%{reporter} が %{target} を通報しました"
Expand Down
38 changes: 37 additions & 1 deletion spec/controllers/admin/reported_statuses_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@
sign_in user, scope: :user
end

describe 'POST #create' do
subject do
-> { post :create, params: { report_id: report, form_status_batch: { action: action, status_ids: status_ids } } }
end

let(:action) { 'nsfw_on' }
let(:status_ids) { [status.id] }
let(:status) { Fabricate(:status, sensitive: !sensitive) }
let(:sensitive) { true }
let!(:media_attachment) { Fabricate(:media_attachment, status: status) }

context 'updates sensitive column to true' do
it 'updates sensitive column' do
is_expected.to change {
status.reload.sensitive
}.from(false).to(true)
end
end

context 'updates sensitive column to false' do
let(:action) { 'nsfw_off' }
let(:sensitive) { false }

it 'updates sensitive column' do
is_expected.to change {
status.reload.sensitive
}.from(true).to(false)
end
end

it 'redirects to report page' do
subject.call
expect(response).to redirect_to(admin_report_path(report))
end
end

describe 'PATCH #update' do
subject do
-> { patch :update, params: { report_id: report, id: status, status: { sensitive: sensitive } } }
Expand Down Expand Up @@ -48,7 +84,7 @@
allow(RemovalWorker).to receive(:perform_async)

delete :destroy, params: { report_id: report, id: status }
expect(response).to redirect_to(admin_report_path(report))
expect(response).to have_http_status(:success)
expect(RemovalWorker).
to have_received(:perform_async).with(status.id)
end
Expand Down
107 changes: 107 additions & 0 deletions spec/controllers/admin/statuses_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
require 'rails_helper'

describe Admin::StatusesController do
render_views

let(:user) { Fabricate(:user, admin: true) }
let(:account) { Fabricate(:account) }
let!(:status) { Fabricate(:status, account: account) }
let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: media_attached_status) }
let(:sensitive) { true }

before do
sign_in user, scope: :user
end

describe 'GET #index' do
it 'returns http success with no media' do
get :index, params: { account_id: account.id }

statuses = assigns(:statuses).to_a
expect(statuses.size).to eq 2
expect(response).to have_http_status(:success)
end

it 'returns http success with media' do
get :index, params: { account_id: account.id , media: true }

statuses = assigns(:statuses).to_a
expect(statuses.size).to eq 1
expect(response).to have_http_status(:success)
end
end

describe 'POST #create' do
subject do
-> { post :create, params: { account_id: account.id, form_status_batch: { action: action, status_ids: status_ids } } }
end

let(:action) { 'nsfw_on' }
let(:status_ids) { [media_attached_status.id] }

context 'updates sensitive column to true' do
it 'updates sensitive column' do
is_expected.to change {
media_attached_status.reload.sensitive
}.from(false).to(true)
end
end

context 'updates sensitive column to false' do
let(:action) { 'nsfw_off' }
let(:sensitive) { false }

it 'updates sensitive column' do
is_expected.to change {
media_attached_status.reload.sensitive
}.from(true).to(false)
end
end

it 'redirects to account statuses page' do
subject.call
expect(response).to redirect_to(admin_account_statuses_path(account.id))
end
end

describe 'PATCH #update' do
subject do
-> { patch :update, params: { account_id: account.id, id: media_attached_status, status: { sensitive: sensitive } } }
end

context 'updates sensitive column to true' do
it 'updates sensitive column' do
is_expected.to change {
media_attached_status.reload.sensitive
}.from(false).to(true)
end
end

context 'updates sensitive column to false' do
let(:sensitive) { false }

it 'updates sensitive column' do
is_expected.to change {
media_attached_status.reload.sensitive
}.from(true).to(false)
end
end

it 'redirects to account statuses page' do
subject.call
expect(response).to redirect_to(admin_account_statuses_path(account.id))
end
end

describe 'DELETE #destroy' do
it 'removes a status' do
allow(RemovalWorker).to receive(:perform_async)

delete :destroy, params: { account_id: account.id, id: status }
expect(response).to have_http_status(:success)
expect(RemovalWorker).
to have_received(:perform_async).with(status.id)
end
end
end
12 changes: 6 additions & 6 deletions spec/models/form/status_batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
let(:action) { 'nsfw_on' }

it { expect(form.save).to be true }
it { expect { form.save }.to change { Status.find(nonsensitive_status.id).sensitive }.from(false).to(true) }
it { expect { form.save }.not_to change { Status.find(sensitive_status.id).sensitive } }
it { expect { form.save }.not_to change { Status.find(status.id).sensitive } }
it { expect { form.save }.to change { nonsensitive_status.reload.sensitive }.from(false).to(true) }
it { expect { form.save }.not_to change { sensitive_status.reload.sensitive } }
it { expect { form.save }.not_to change { status.reload.sensitive } }
end

context 'nsfw_off' do
let(:action) { 'nsfw_off' }

it { expect(form.save).to be true }
it { expect { form.save }.to change { Status.find(sensitive_status.id).sensitive }.from(true).to(false) }
it { expect { form.save }.not_to change { Status.find(nonsensitive_status.id).sensitive } }
it { expect { form.save }.not_to change { Status.find(status.id).sensitive } }
it { expect { form.save }.to change { sensitive_status.reload.sensitive }.from(true).to(false) }
it { expect { form.save }.not_to change { nonsensitive_status.reload.sensitive } }
it { expect { form.save }.not_to change { status.reload.sensitive } }
end
end

Expand Down

0 comments on commit c67cad0

Please sign in to comment.