From 084835f06a6f139667d9f6bb445659df512f080a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Fri, 17 Feb 2023 20:32:29 +0800 Subject: [PATCH] WIP Add admin settings pages, reserved username config Prototyping settings forms --- app/assets/stylesheets/components/forms.css | 2 +- .../settings/registrations_controller.rb | 9 +++++ .../admin/settings/services_controller.rb | 9 +++++ app/controllers/admin/settings_controller.rb | 12 ++++++ app/models/setting.rb | 10 +++++ .../settings/registrations/index.html.erb | 31 +++++++++++++++ .../admin/settings/services/index.html.erb | 39 +++++++++++++++++++ app/views/icons/_grid.html.erb | 2 +- app/views/shared/_admin_nav.html.erb | 2 + .../shared/_admin_sidenav_settings.html.erb | 11 ++++++ config/routes.rb | 5 +++ 11 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/settings/registrations_controller.rb create mode 100644 app/controllers/admin/settings/services_controller.rb create mode 100644 app/controllers/admin/settings_controller.rb create mode 100644 app/views/admin/settings/registrations/index.html.erb create mode 100644 app/views/admin/settings/services/index.html.erb create mode 100644 app/views/shared/_admin_sidenav_settings.html.erb diff --git a/app/assets/stylesheets/components/forms.css b/app/assets/stylesheets/components/forms.css index 6c68083..61c7b1e 100644 --- a/app/assets/stylesheets/components/forms.css +++ b/app/assets/stylesheets/components/forms.css @@ -1,6 +1,6 @@ @layer components { input[type=text], input[type=email], input[type=password], - input[type=number], select { + input[type=number], select, textarea { @apply mt-1 rounded-md bg-gray-100 focus:bg-white border-transparent focus:border-transparent focus:ring-2 focus:ring-blue-600 focus:ring-opacity-75; diff --git a/app/controllers/admin/settings/registrations_controller.rb b/app/controllers/admin/settings/registrations_controller.rb new file mode 100644 index 0000000..1abca45 --- /dev/null +++ b/app/controllers/admin/settings/registrations_controller.rb @@ -0,0 +1,9 @@ +class Admin::Settings::RegistrationsController < Admin::SettingsController + + def index + end + + def update + end + +end diff --git a/app/controllers/admin/settings/services_controller.rb b/app/controllers/admin/settings/services_controller.rb new file mode 100644 index 0000000..ebdad4e --- /dev/null +++ b/app/controllers/admin/settings/services_controller.rb @@ -0,0 +1,9 @@ +class Admin::Settings::ServicesController < Admin::SettingsController + + def index + end + + def update + end + +end diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb new file mode 100644 index 0000000..8353f9b --- /dev/null +++ b/app/controllers/admin/settings_controller.rb @@ -0,0 +1,12 @@ +class Admin::SettingsController < Admin::BaseController + before_action :set_current_section + + def index + end + + private + + def set_current_section + @current_section = :settings + end +end diff --git a/app/models/setting.rb b/app/models/setting.rb index 2a80940..16a8590 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -2,6 +2,16 @@ class Setting < RailsSettings::Base cache_prefix { "v1" } + field :reserved_usernames, type: :array, default: %w[ + account + accounts + admin + donations + mail + webmaster + support + ] + field :lndhub_enabled, default: (ENV["LNDHUB_API_URL"].present?.to_s || "false"), type: :boolean field :lndhub_admin_enabled, default: (ENV["LNDHUB_ADMIN_UI"] || "false"), type: :boolean end diff --git a/app/views/admin/settings/registrations/index.html.erb b/app/views/admin/settings/registrations/index.html.erb new file mode 100644 index 0000000..2a327e1 --- /dev/null +++ b/app/views/admin/settings/registrations/index.html.erb @@ -0,0 +1,31 @@ +<%= render HeaderComponent.new(title: "Settings") %> + +<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/admin_sidenav_settings') do %> +
+

Registrations

+ <%= form_for(Setting.new, url: admin_settings_services_path) do |f| %> + <% if @errors && @errors.any? %> +
+
    + <% @errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + + + <% end %> +
+<% end %> diff --git a/app/views/admin/settings/services/index.html.erb b/app/views/admin/settings/services/index.html.erb new file mode 100644 index 0000000..c0dad64 --- /dev/null +++ b/app/views/admin/settings/services/index.html.erb @@ -0,0 +1,39 @@ +<%= render HeaderComponent.new(title: "Settings") %> + +<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/admin_sidenav_settings') do %> +
+

Lightning Network

+ <%= form_for(Setting.new, url: admin_settings_services_path) do |f| %> + <% if @errors && @errors.any? %> +
+
    + <% @errors.full_messages.each do |msg| %> +
  • <%= msg %>
  • + <% end %> +
+
+ <% end %> + + + <% end %> +
+<% end %> diff --git a/app/views/icons/_grid.html.erb b/app/views/icons/_grid.html.erb index 8ef2e9d..57f9632 100644 --- a/app/views/icons/_grid.html.erb +++ b/app/views/icons/_grid.html.erb @@ -1 +1 @@ - \ No newline at end of file + diff --git a/app/views/shared/_admin_nav.html.erb b/app/views/shared/_admin_nav.html.erb index dfba699..dd8c8b8 100644 --- a/app/views/shared/_admin_nav.html.erb +++ b/app/views/shared/_admin_nav.html.erb @@ -10,3 +10,5 @@ <%= link_to "Lightning", admin_lightning_path, class: main_nav_class(@current_section, :lightning) %> <% end %> +<%= link_to "Settings", admin_settings_registrations_path, + class: main_nav_class(@current_section, :settings) %> diff --git a/app/views/shared/_admin_sidenav_settings.html.erb b/app/views/shared/_admin_sidenav_settings.html.erb new file mode 100644 index 0000000..d675242 --- /dev/null +++ b/app/views/shared/_admin_sidenav_settings.html.erb @@ -0,0 +1,11 @@ +<%= render SidenavLinkComponent.new( + name: "Registrations", path: admin_settings_registrations_path, icon: "user", + active: current_page?(admin_settings_registrations_path) +) %> +<%= render SidenavLinkComponent.new( + name: "Services", path: admin_settings_services_path, icon: "grid", + active: current_page?(admin_settings_services_path) +) %> +<%= render SidenavLinkComponent.new( + name: "Security", path: "#", icon: "shield", disabled: true +) %> diff --git a/config/routes.rb b/config/routes.rb index 00475c5..eb118cf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,6 +43,11 @@ Rails.application.routes.draw do get 'invitations', to: 'invitations#index' resources :donations get 'lightning', to: 'lightning#index' + + namespace :settings do + resources 'registrations', only: ['index', 'update'] + resources 'services', only: ['index', 'update'] + end end authenticate :user, ->(user) { user.is_admin? } do