mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
parent
6fac300ea4
commit
5e8c2baa20
46
app/controllers/api/v1/admin/accounts_controller.rb
Normal file
46
app/controllers/api/v1/admin/accounts_controller.rb
Normal file
@ -0,0 +1,46 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::Admin::AccountsController < Api::BaseController
|
||||
before_action -> { doorkeeper_authorize! :'admin:read', :'admin:read:accounts' }
|
||||
before_action :require_staff!
|
||||
before_action :set_accounts, only: :index
|
||||
before_action :set_account, only: :show
|
||||
|
||||
def index
|
||||
render json: @accounts, each_serializer: REST::Admin::AccountSerializer
|
||||
end
|
||||
|
||||
def show
|
||||
render json: @account, serializer: REST::Admin::AccountSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_accounts
|
||||
@accounts = filtered_accounts
|
||||
end
|
||||
|
||||
def set_account
|
||||
@account = Account.find(params[:id])
|
||||
end
|
||||
|
||||
def filtered_accounts
|
||||
AccountFilter.new(filter_params).results
|
||||
end
|
||||
|
||||
def filter_params
|
||||
params.permit(
|
||||
:local,
|
||||
:remote,
|
||||
:by_domain,
|
||||
:active,
|
||||
:silenced,
|
||||
:suspended,
|
||||
:username,
|
||||
:display_name,
|
||||
:email,
|
||||
:ip,
|
||||
:staff
|
||||
)
|
||||
end
|
||||
end
|
38
app/controllers/api/v1/admin/reports_controller.rb
Normal file
38
app/controllers/api/v1/admin/reports_controller.rb
Normal file
@ -0,0 +1,38 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Api::V1::Admin::ReportsController < Api::BaseController
|
||||
before_action -> { doorkeeper_authorize! :'admin:read', :'admin:read:reports' }
|
||||
before_action :require_staff!
|
||||
before_action :set_reports, only: :index
|
||||
before_action :set_report, only: :show
|
||||
|
||||
def index
|
||||
render json: @reports, each_serializer: REST::Admin::ReportSerializer
|
||||
end
|
||||
|
||||
def show
|
||||
render json: @report, serializer: REST::Admin::ReportSerializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_reports
|
||||
@reports = filtered_reports.order(id: :desc)
|
||||
end
|
||||
|
||||
def set_report
|
||||
@report = Report.find(params[:id])
|
||||
end
|
||||
|
||||
def filtered_reports
|
||||
ReportFilter.new(filter_params).results
|
||||
end
|
||||
|
||||
def filter_params
|
||||
params.permit(
|
||||
:resolved,
|
||||
:account_id,
|
||||
:target_account_id
|
||||
)
|
||||
end
|
||||
end
|
@ -136,6 +136,8 @@ class Account < ApplicationRecord
|
||||
:current_sign_in_ip,
|
||||
:current_sign_in_at,
|
||||
:confirmed?,
|
||||
:disabled?,
|
||||
:role,
|
||||
:admin?,
|
||||
:moderator?,
|
||||
:staff?,
|
||||
|
@ -9,9 +9,11 @@ class ReportFilter
|
||||
|
||||
def results
|
||||
scope = Report.unresolved
|
||||
|
||||
params.each do |key, value|
|
||||
scope = scope.merge scope_for(key, value)
|
||||
end
|
||||
|
||||
scope
|
||||
end
|
||||
|
||||
|
35
app/serializers/rest/admin/account_serializer.rb
Normal file
35
app/serializers/rest/admin/account_serializer.rb
Normal file
@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::Admin::AccountSerializer < ActiveModel::Serializer
|
||||
attributes :id, :username, :domain, :url, :created_at,
|
||||
:email, :ip, :role, :confirmed, :suspended,
|
||||
:silenced, :disabled
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def url
|
||||
ActivityPub::TagManager.instance.url_for(object)
|
||||
end
|
||||
|
||||
def email
|
||||
object.user_email
|
||||
end
|
||||
|
||||
def ip
|
||||
object.user_current_sign_in_ip.to_s.presence
|
||||
end
|
||||
|
||||
def role
|
||||
object.user_role
|
||||
end
|
||||
|
||||
def confirmed
|
||||
object.user_confirmed?
|
||||
end
|
||||
|
||||
def disabled
|
||||
object.user_disabled?
|
||||
end
|
||||
end
|
29
app/serializers/rest/admin/report_serializer.rb
Normal file
29
app/serializers/rest/admin/report_serializer.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::Admin::ReportSerializer < ActiveModel::Serializer
|
||||
attributes :id, :action_taken, :comment, :created_at, :updated_at,
|
||||
:account_id, :target_account_id, :assigned_account_id,
|
||||
:action_taken_by_account_id
|
||||
|
||||
has_many :statuses, serializer: REST::StatusSerializer
|
||||
|
||||
def id
|
||||
object.id.to_s
|
||||
end
|
||||
|
||||
def account_id
|
||||
object.account_id.to_s.presence
|
||||
end
|
||||
|
||||
def target_account_id
|
||||
object.target_account_id.to_s.presence
|
||||
end
|
||||
|
||||
def assigned_account_id
|
||||
object.assigned_account_id.to_s.presence
|
||||
end
|
||||
|
||||
def action_taken_by_account_id
|
||||
object.action_taken_by_account_id.to_s.presence
|
||||
end
|
||||
end
|
@ -343,6 +343,11 @@ Rails.application.routes.draw do
|
||||
namespace :push do
|
||||
resource :subscription, only: [:create, :show, :update, :destroy]
|
||||
end
|
||||
|
||||
namespace :admin do
|
||||
resources :accounts, only: [:index, :show]
|
||||
resources :reports, only: [:index, :show]
|
||||
end
|
||||
end
|
||||
|
||||
namespace :v2 do
|
||||
|
Loading…
Reference in New Issue
Block a user