2022-06-23 14:12:01 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Api::V1::Admin::DomainAllowsController < Api::BaseController
|
|
|
|
include Authorization
|
|
|
|
include AccountableConcern
|
|
|
|
|
|
|
|
LIMIT = 100
|
|
|
|
|
|
|
|
before_action -> { authorize_if_got_token! :'admin:read', :'admin:read:domain_allows' }, only: [:index, :show]
|
|
|
|
before_action -> { authorize_if_got_token! :'admin:write', :'admin:write:domain_allows' }, except: [:index, :show]
|
|
|
|
before_action :set_domain_allows, only: :index
|
|
|
|
before_action :set_domain_allow, only: [:show, :destroy]
|
|
|
|
|
2022-07-04 17:41:40 -07:00
|
|
|
after_action :verify_authorized
|
2022-06-23 14:12:01 -07:00
|
|
|
after_action :insert_pagination_headers, only: :index
|
|
|
|
|
2023-04-29 21:46:39 -07:00
|
|
|
def index
|
|
|
|
authorize :domain_allow, :index?
|
|
|
|
render json: @domain_allows, each_serializer: REST::Admin::DomainAllowSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
authorize @domain_allow, :show?
|
|
|
|
render json: @domain_allow, serializer: REST::Admin::DomainAllowSerializer
|
|
|
|
end
|
|
|
|
|
2022-06-23 14:12:01 -07:00
|
|
|
def create
|
|
|
|
authorize :domain_allow, :create?
|
|
|
|
|
2023-05-22 04:44:49 -07:00
|
|
|
@domain_allow = DomainAllow.find_by(domain: resource_params[:domain])
|
2022-06-23 14:12:01 -07:00
|
|
|
|
|
|
|
if @domain_allow.nil?
|
|
|
|
@domain_allow = DomainAllow.create!(resource_params)
|
|
|
|
log_action :create, @domain_allow
|
|
|
|
end
|
|
|
|
|
|
|
|
render json: @domain_allow, serializer: REST::Admin::DomainAllowSerializer
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize @domain_allow, :destroy?
|
|
|
|
UnallowDomainService.new.call(@domain_allow)
|
|
|
|
log_action :destroy, @domain_allow
|
2022-10-29 17:43:57 -07:00
|
|
|
render_empty
|
2022-06-23 14:12:01 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_domain_allows
|
|
|
|
@domain_allows = filtered_domain_allows.order(id: :desc).to_a_paginated_by_id(limit_param(LIMIT), params_slice(:max_id, :since_id, :min_id))
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_domain_allow
|
|
|
|
@domain_allow = DomainAllow.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def filtered_domain_allows
|
|
|
|
# TODO: no filtering yet
|
|
|
|
DomainAllow.all
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_path
|
|
|
|
api_v1_admin_domain_allows_url(pagination_params(max_id: pagination_max_id)) if records_continue?
|
|
|
|
end
|
|
|
|
|
|
|
|
def prev_path
|
|
|
|
api_v1_admin_domain_allows_url(pagination_params(min_id: pagination_since_id)) unless @domain_allows.empty?
|
|
|
|
end
|
|
|
|
|
2024-03-13 01:51:44 -07:00
|
|
|
def pagination_collection
|
|
|
|
@domain_allows
|
2022-06-23 14:12:01 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def records_continue?
|
|
|
|
@domain_allows.size == limit_param(LIMIT)
|
|
|
|
end
|
|
|
|
|
|
|
|
def resource_params
|
|
|
|
params.permit(:domain)
|
|
|
|
end
|
|
|
|
end
|