2025-02-21 11:57:59 -05:00
|
|
|
class Settings::HostingsController < ApplicationController
|
|
|
|
layout "settings"
|
|
|
|
|
2024-10-02 12:07:56 -04:00
|
|
|
before_action :raise_if_not_self_hosted
|
2025-02-28 13:49:12 +01:00
|
|
|
before_action :ensure_admin, only: :clear_cache
|
2024-04-18 07:56:51 -04:00
|
|
|
|
|
|
|
def show
|
2025-03-17 11:54:53 -04:00
|
|
|
@synth_usage = Providers.synth&.usage
|
2024-04-18 07:56:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2024-10-02 12:07:56 -04:00
|
|
|
if hosting_params[:upgrades_setting].present?
|
|
|
|
mode = hosting_params[:upgrades_setting] == "manual" ? "manual" : "auto"
|
|
|
|
target = hosting_params[:upgrades_setting] == "commit" ? "commit" : "release"
|
2024-04-18 07:56:51 -04:00
|
|
|
|
2024-10-02 12:07:56 -04:00
|
|
|
Setting.upgrades_mode = mode
|
|
|
|
Setting.upgrades_target = target
|
|
|
|
end
|
|
|
|
|
|
|
|
if hosting_params.key?(:render_deploy_hook)
|
|
|
|
Setting.render_deploy_hook = hosting_params[:render_deploy_hook]
|
2024-04-18 07:56:51 -04:00
|
|
|
end
|
|
|
|
|
2024-10-02 12:07:56 -04:00
|
|
|
if hosting_params.key?(:require_invite_for_signup)
|
|
|
|
Setting.require_invite_for_signup = hosting_params[:require_invite_for_signup]
|
2024-04-29 22:44:24 +02:00
|
|
|
end
|
|
|
|
|
2025-01-31 11:29:49 -06:00
|
|
|
if hosting_params.key?(:require_email_confirmation)
|
|
|
|
Setting.require_email_confirmation = hosting_params[:require_email_confirmation]
|
|
|
|
end
|
|
|
|
|
2024-10-02 12:07:56 -04:00
|
|
|
if hosting_params.key?(:synth_api_key)
|
|
|
|
Setting.synth_api_key = hosting_params[:synth_api_key]
|
2024-04-29 22:44:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to settings_hosting_path, notice: t(".success")
|
2024-10-02 12:07:56 -04:00
|
|
|
rescue ActiveRecord::RecordInvalid => error
|
|
|
|
flash.now[:alert] = t(".failure")
|
|
|
|
render :show, status: :unprocessable_entity
|
2024-04-29 22:44:24 +02:00
|
|
|
end
|
|
|
|
|
2025-02-28 13:49:12 +01:00
|
|
|
def clear_cache
|
|
|
|
DataCacheClearJob.perform_later(Current.family)
|
|
|
|
redirect_to settings_hosting_path, notice: t(".cache_cleared")
|
|
|
|
end
|
|
|
|
|
2024-04-18 07:56:51 -04:00
|
|
|
private
|
|
|
|
def hosting_params
|
2025-01-31 11:29:49 -06:00
|
|
|
params.require(:setting).permit(:render_deploy_hook, :upgrades_setting, :require_invite_for_signup, :require_email_confirmation, :synth_api_key)
|
2024-04-18 07:56:51 -04:00
|
|
|
end
|
|
|
|
|
2024-10-02 12:07:56 -04:00
|
|
|
def raise_if_not_self_hosted
|
|
|
|
raise "Settings not available on non-self-hosted instance" unless self_hosted?
|
2024-04-18 07:56:51 -04:00
|
|
|
end
|
2025-02-28 13:49:12 +01:00
|
|
|
|
|
|
|
def ensure_admin
|
|
|
|
redirect_to settings_hosting_path, alert: t(".not_authorized") unless Current.user.admin?
|
|
|
|
end
|
2024-04-18 07:56:51 -04:00
|
|
|
end
|