* Add config post route for admin api * Fix params * Extract config_params to concern * Remove print statement * Some changes * A couple changes * Change controller method name and refactor upsert * Fix tests and method names * Fix routes and class stuff * Fix styles * Fix config params * Fix styles * Move regex to constant * Remove single-use after action callbacks * Expose success? method * Fix syntax error * Fix success? return * Switch to guard clause * Final clean ups?
29 lines
830 B
Ruby
29 lines
830 B
Ruby
module Api
|
|
module V0
|
|
module Admin
|
|
class ConfigsController < ApiController
|
|
include SiteConfigParams
|
|
|
|
before_action :authenticate_with_api_key_or_current_user!
|
|
before_action :authorize_super_admin
|
|
skip_before_action :verify_authenticity_token, only: %i[update]
|
|
|
|
def show
|
|
@site_configs = SiteConfig.all
|
|
end
|
|
|
|
def update
|
|
result = SiteConfigs::Upsert.call(site_config_params)
|
|
if result.success?
|
|
@site_configs = SiteConfig.all
|
|
Audit::Logger.log(:internal, @user, params.dup)
|
|
bust_content_change_caches
|
|
render "show"
|
|
else
|
|
render json: { error: result.errors.to_sentence, status: 422 }, status: :unprocessable_entity
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|