Add /api/v1/admin/domain_blocks (#18247)

* Add /api/v1/admin/domain_blocks

Fixes #18140

- `GET /api/v1/admin/domain_blocks` lists domain blocks
- `GET /api/v1/admin/domain_blocks/:id` shows one by ID
- `DELETE /api/v1/admin/domain_blocks/:id` deletes a given domain block
- `POST /api/v1/admin/domain_blocks` to create a new domain block:
  if it conflicts with an existing one, returns an error with
  an attribute `existing_domain_block` with the rendered domain block

* Simplify conflict handling as suggested in review
This commit is contained in:
Claire 2022-06-01 17:31:36 +02:00 committed by GitHub
parent f5783182c3
commit 28329ba62f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 271 additions and 0 deletions

View file

@ -0,0 +1,11 @@
# frozen_string_literal: true
class REST::Admin::DomainBlockSerializer < ActiveModel::Serializer
attributes :id, :domain, :created_at, :severity,
:reject_media, :reject_reports,
:private_comment, :public_comment, :obfuscate
def id
object.id.to_s
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class REST::Admin::ExistingDomainBlockErrorSerializer < ActiveModel::Serializer
attributes :error
has_one :existing_domain_block, serializer: REST::Admin::DomainBlockSerializer
def error
I18n.t('admin.domain_blocks.existing_domain_block', name: existing_domain_block.domain)
end
def existing_domain_block
object
end
end