Update registration settings
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Râu Cao 2023-02-17 21:36:30 +08:00
parent 084835f06a
commit b7bf957dd2
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
4 changed files with 46 additions and 17 deletions

View File

@ -3,7 +3,36 @@ class Admin::Settings::RegistrationsController < Admin::SettingsController
def index def index
end end
def update def create
@errors = ActiveModel::Errors.new(Setting.new)
setting_params.keys.each do |key|
next if setting_params[key].nil?
setting = Setting.new(var: key)
setting.value = setting_params[key].strip
unless setting.valid?
@errors.merge!(setting.errors)
end
end
if @errors.any?
render :index
end
setting_params.keys.each do |key|
Setting.send("#{key}=", setting_params[key].strip) unless setting_params[key].nil?
end
redirect_to admin_settings_registrations_path, flash: {
success: "Settings saved"
}
end
private
def setting_params
params.require(:setting).permit(:reserved_usernames)
end end
end end

View File

@ -3,13 +3,7 @@ class Setting < RailsSettings::Base
cache_prefix { "v1" } cache_prefix { "v1" }
field :reserved_usernames, type: :array, default: %w[ field :reserved_usernames, type: :array, default: %w[
account account accounts admin donations mail webmaster support
accounts
admin
donations
mail
webmaster
support
] ]
field :lndhub_enabled, default: (ENV["LNDHUB_API_URL"].present?.to_s || "false"), type: :boolean field :lndhub_enabled, default: (ENV["LNDHUB_API_URL"].present?.to_s || "false"), type: :boolean

View File

@ -1,9 +1,9 @@
<%= render HeaderComponent.new(title: "Settings") %> <%= render HeaderComponent.new(title: "Settings") %>
<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/admin_sidenav_settings') do %> <%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/admin_sidenav_settings') do %>
<%= form_for(Setting.new, url: admin_settings_registrations_path) do |f| %>
<section> <section>
<h3>Registrations</h3> <h3>Registrations</h3>
<%= form_for(Setting.new, url: admin_settings_services_path) do |f| %>
<% if @errors && @errors.any? %> <% if @errors && @errors.any? %>
<div> <div>
<ul> <ul>
@ -14,7 +14,7 @@
</div> </div>
<% end %> <% end %>
<label> <label class="block">
<p class="font-bold mb-1">Reserved usernames</p> <p class="font-bold mb-1">Reserved usernames</p>
<p class="text-gray-500"> <p class="text-gray-500">
These usernames cannot be registered as accounts: These usernames cannot be registered as accounts:
@ -22,10 +22,16 @@
<%= f.text_area :reserved_usernames, <%= f.text_area :reserved_usernames,
value: Setting.reserved_usernames.join("\n"), value: Setting.reserved_usernames.join("\n"),
class: "h-44 mb-2" %> class: "h-44 mb-2" %>
<p class="text-sm text-gray-500"> <p class="mb-0 text-sm text-gray-500">
One username per line One username per line
</p> </p>
</label> </label>
<% end %> </section>
<section>
<p class="mb-0 pt-6 border-t border-gray-200">
<%= f.submit 'Save', class: "btn-md btn-blue w-full md:w-auto" %>
</p>
</section> </section>
<% end %> <% end %>
<% end %>

View File

@ -45,8 +45,8 @@ Rails.application.routes.draw do
get 'lightning', to: 'lightning#index' get 'lightning', to: 'lightning#index'
namespace :settings do namespace :settings do
resources 'registrations', only: ['index', 'update'] resources 'registrations', only: ['index', 'create']
resources 'services', only: ['index', 'update'] resources 'services', only: ['index', 'create']
end end
end end