mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-18 15:48:22 +00:00
Add audit logs to Admin::InstancesController (#27386)
This commit is contained in:
parent
1b839d2cba
commit
bb2e5a4b58
|
@ -13,6 +13,7 @@ module Admin
|
||||||
def show
|
def show
|
||||||
authorize :instance, :show?
|
authorize :instance, :show?
|
||||||
@time_period = (6.days.ago.to_date...Time.now.utc.to_date)
|
@time_period = (6.days.ago.to_date...Time.now.utc.to_date)
|
||||||
|
@action_logs = Admin::ActionLogFilter.new(target_domain: @instance.domain).results.limit(5)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
|
@ -5,6 +5,14 @@ class Admin::ActionLogFilter
|
||||||
action_type
|
action_type
|
||||||
account_id
|
account_id
|
||||||
target_account_id
|
target_account_id
|
||||||
|
target_domain
|
||||||
|
).freeze
|
||||||
|
|
||||||
|
INSTANCE_TARGET_TYPES = %w(
|
||||||
|
DomainBlock
|
||||||
|
DomainAllow
|
||||||
|
Instance
|
||||||
|
UnavailableDomain
|
||||||
).freeze
|
).freeze
|
||||||
|
|
||||||
ACTION_TYPE_MAP = {
|
ACTION_TYPE_MAP = {
|
||||||
|
@ -95,6 +103,9 @@ class Admin::ActionLogFilter
|
||||||
when 'target_account_id'
|
when 'target_account_id'
|
||||||
account = Account.find_or_initialize_by(id: value)
|
account = Account.find_or_initialize_by(id: value)
|
||||||
latest_action_logs.where(target: [account, account.user].compact)
|
latest_action_logs.where(target: [account, account.user].compact)
|
||||||
|
when 'target_domain'
|
||||||
|
normalized_domain = TagManager.instance.normalize_domain(value)
|
||||||
|
latest_action_logs.where(human_identifier: normalized_domain, target_type: INSTANCE_TARGET_TYPES)
|
||||||
else
|
else
|
||||||
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
|
raise Mastodon::InvalidParameterError, "Unknown filter: #{key}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -114,6 +114,16 @@
|
||||||
- if @instance.persisted?
|
- if @instance.persisted?
|
||||||
%hr.spacer/
|
%hr.spacer/
|
||||||
|
|
||||||
|
%h3= t('admin.instances.audit_log.title')
|
||||||
|
- if @action_logs.empty?
|
||||||
|
%p= t('accounts.nothing_here')
|
||||||
|
- else
|
||||||
|
.report-notes
|
||||||
|
= render partial: 'admin/action_logs/action_log', collection: @action_logs
|
||||||
|
= link_to t('admin.instances.audit_log.view_all'), admin_action_logs_path(target_domain: @instance.domain), class: 'button'
|
||||||
|
|
||||||
|
%hr.spacer/
|
||||||
|
|
||||||
%h3= t('admin.instances.availability.title')
|
%h3= t('admin.instances.availability.title')
|
||||||
|
|
||||||
%p
|
%p
|
||||||
|
|
|
@ -471,6 +471,9 @@ en:
|
||||||
title: Follow recommendations
|
title: Follow recommendations
|
||||||
unsuppress: Restore follow recommendation
|
unsuppress: Restore follow recommendation
|
||||||
instances:
|
instances:
|
||||||
|
audit_log:
|
||||||
|
title: Recent Audit Logs
|
||||||
|
view_all: View full audit logs
|
||||||
availability:
|
availability:
|
||||||
description_html:
|
description_html:
|
||||||
one: If delivering to the domain fails <strong>%{count} day</strong> without succeeding, no further delivery attempts will be made unless a delivery <em>from</em> the domain is received.
|
one: If delivering to the domain fails <strong>%{count} day</strong> without succeeding, no further delivery attempts will be made unless a delivery <em>from</em> the domain is received.
|
||||||
|
|
|
@ -37,10 +37,32 @@ RSpec.describe Admin::InstancesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
|
before do
|
||||||
|
allow(Admin::ActionLogFilter).to receive(:new).and_call_original
|
||||||
|
end
|
||||||
|
|
||||||
it 'shows an instance page' do
|
it 'shows an instance page' do
|
||||||
get :show, params: { id: account_popular_main.domain }
|
get :show, params: { id: account_popular_main.domain }
|
||||||
|
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
instance = assigns(:instance)
|
||||||
|
expect(instance).to_not be_new_record
|
||||||
|
|
||||||
|
expect(Admin::ActionLogFilter).to have_received(:new).with(target_domain: account_popular_main.domain)
|
||||||
|
|
||||||
|
action_logs = assigns(:action_logs).to_a
|
||||||
|
expect(action_logs.size).to eq 0
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with an unknown domain' do
|
||||||
|
it 'returns http success' do
|
||||||
|
get :show, params: { id: 'unknown.example' }
|
||||||
|
expect(response).to have_http_status(200)
|
||||||
|
|
||||||
|
instance = assigns(:instance)
|
||||||
|
expect(instance).to be_new_record
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue