Add moderation API

Fix #8580
Fix #7143
This commit is contained in:
Eugen Rochko 2018-11-28 21:15:48 +01:00
parent 6fac300ea4
commit 5e8c2baa20
7 changed files with 157 additions and 0 deletions

View 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

View 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

View File

@ -136,6 +136,8 @@ class Account < ApplicationRecord
:current_sign_in_ip,
:current_sign_in_at,
:confirmed?,
:disabled?,
:role,
:admin?,
:moderator?,
:staff?,

View File

@ -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

View 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

View 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

View File

@ -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