about summary refs log tree commit diff
path: root/app/controllers/settings
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/settings')
-rw-r--r--app/controllers/settings/applications_controller.rb9
-rw-r--r--app/controllers/settings/base_controller.rb17
-rw-r--r--app/controllers/settings/deletes_controller.rb11
-rw-r--r--app/controllers/settings/exports_controller.rb13
-rw-r--r--app/controllers/settings/flavours_controller.rb32
-rw-r--r--app/controllers/settings/follower_domains_controller.rb11
-rw-r--r--app/controllers/settings/imports_controller.rb10
-rw-r--r--app/controllers/settings/migrations_controller.rb11
-rw-r--r--app/controllers/settings/notifications_controller.rb11
-rw-r--r--app/controllers/settings/preferences_controller.rb13
-rw-r--r--app/controllers/settings/profiles_controller.rb10
-rw-r--r--app/controllers/settings/sessions_controller.rb1
-rw-r--r--app/controllers/settings/two_factor_authentication/confirmations_controller.rb10
-rw-r--r--app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb13
-rw-r--r--app/controllers/settings/two_factor_authentications_controller.rb10
15 files changed, 64 insertions, 118 deletions
diff --git a/app/controllers/settings/applications_controller.rb b/app/controllers/settings/applications_controller.rb
index a1a2c57fa..03c890a50 100644
--- a/app/controllers/settings/applications_controller.rb
+++ b/app/controllers/settings/applications_controller.rb
@@ -1,12 +1,9 @@
 # frozen_string_literal: true
 
-class Settings::ApplicationsController < ApplicationController
-  layout 'admin'
+class Settings::ApplicationsController < Settings::BaseController
 
-  before_action :authenticate_user!
   before_action :set_application, only: [:show, :update, :destroy, :regenerate]
   before_action :prepare_scopes, only: [:create, :update]
-  before_action :set_body_classes
 
   def index
     @applications = current_user.applications.order(id: :desc).page(params[:page])
@@ -70,8 +67,4 @@ class Settings::ApplicationsController < ApplicationController
     scopes = params.fetch(:doorkeeper_application, {}).fetch(:scopes, nil)
     params[:doorkeeper_application][:scopes] = scopes.join(' ') if scopes.is_a? Array
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/base_controller.rb b/app/controllers/settings/base_controller.rb
new file mode 100644
index 000000000..34ef16568
--- /dev/null
+++ b/app/controllers/settings/base_controller.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class Settings::BaseController < ApplicationController
+  layout 'admin'
+
+  before_action :authenticate_user!
+  before_action :set_pack
+  before_action :set_body_classes
+
+  def set_pack
+    use_pack 'settings'
+  end
+
+  def set_body_classes
+    @body_classes = 'admin'
+  end
+end
diff --git a/app/controllers/settings/deletes_controller.rb b/app/controllers/settings/deletes_controller.rb
index 97f3946c8..4c1121471 100644
--- a/app/controllers/settings/deletes_controller.rb
+++ b/app/controllers/settings/deletes_controller.rb
@@ -1,11 +1,8 @@
 # frozen_string_literal: true
 
-class Settings::DeletesController < ApplicationController
-  layout 'admin'
+class Settings::DeletesController < Settings::BaseController
 
-  before_action :check_enabled_deletion
-  before_action :authenticate_user!
-  before_action :set_body_classes
+  prepend_before_action :check_enabled_deletion
 
   def show
     @confirmation = Form::DeleteConfirmation.new
@@ -30,8 +27,4 @@ class Settings::DeletesController < ApplicationController
   def delete_params
     params.require(:form_delete_confirmation).permit(:password)
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/exports_controller.rb b/app/controllers/settings/exports_controller.rb
index 3a2334ef0..cf8745576 100644
--- a/app/controllers/settings/exports_controller.rb
+++ b/app/controllers/settings/exports_controller.rb
@@ -1,13 +1,8 @@
 # frozen_string_literal: true
 
-class Settings::ExportsController < ApplicationController
+class Settings::ExportsController < Settings::BaseController
   include Authorization
 
-  layout 'admin'
-
-  before_action :authenticate_user!
-  before_action :set_body_classes
-
   def show
     @export  = Export.new(current_account)
     @backups = current_user.backups
@@ -21,10 +16,4 @@ class Settings::ExportsController < ApplicationController
 
     redirect_to settings_export_path
   end
-
-  private
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/flavours_controller.rb b/app/controllers/settings/flavours_controller.rb
new file mode 100644
index 000000000..634387715
--- /dev/null
+++ b/app/controllers/settings/flavours_controller.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+class Settings::FlavoursController < Settings::BaseController
+  def index
+    redirect_to action: 'show', flavour: current_flavour
+  end
+
+  def show
+    unless Themes.instance.flavours.include?(params[:flavour]) || (params[:flavour] == current_flavour)
+      redirect_to action: 'show', flavour: current_flavour
+    end
+
+    @listing = Themes.instance.flavours
+    @selected = params[:flavour]
+  end
+
+  def update
+    user_settings.update(user_settings_params)
+    redirect_to action: 'show', flavour: params[:flavour]
+  end
+
+  private
+
+  def user_settings
+    UserSettingsDecorator.new(current_user)
+  end
+
+  def user_settings_params
+    { setting_flavour: params.require(:flavour),
+      setting_skin: params.dig(:user, :setting_skin) }.with_indifferent_access
+  end
+end
diff --git a/app/controllers/settings/follower_domains_controller.rb b/app/controllers/settings/follower_domains_controller.rb
index 9c39e66bb..8aae379aa 100644
--- a/app/controllers/settings/follower_domains_controller.rb
+++ b/app/controllers/settings/follower_domains_controller.rb
@@ -1,11 +1,6 @@
 # frozen_string_literal: true
 
-class Settings::FollowerDomainsController < ApplicationController
-  layout 'admin'
-
-  before_action :authenticate_user!
-  before_action :set_body_classes
-
+class Settings::FollowerDomainsController < Settings::BaseController
   def show
     @account = current_account
     @domains = current_account.followers.reorder(Arel.sql('MIN(follows.id) DESC')).group('accounts.domain').select('accounts.domain, count(accounts.id) as accounts_from_domain').page(params[:page]).per(10)
@@ -26,8 +21,4 @@ class Settings::FollowerDomainsController < ApplicationController
   def bulk_params
     params.permit(select: [])
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/imports_controller.rb b/app/controllers/settings/imports_controller.rb
index e9548ce62..dbd136ebe 100644
--- a/app/controllers/settings/imports_controller.rb
+++ b/app/controllers/settings/imports_controller.rb
@@ -1,11 +1,7 @@
 # frozen_string_literal: true
 
-class Settings::ImportsController < ApplicationController
-  layout 'admin'
-
-  before_action :authenticate_user!
+class Settings::ImportsController < Settings::BaseController
   before_action :set_account
-  before_action :set_body_classes
 
   def show
     @import = Import.new
@@ -32,8 +28,4 @@ class Settings::ImportsController < ApplicationController
   def import_params
     params.require(:import).permit(:data, :type)
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/migrations_controller.rb b/app/controllers/settings/migrations_controller.rb
index bd4f9c87a..89b3f7246 100644
--- a/app/controllers/settings/migrations_controller.rb
+++ b/app/controllers/settings/migrations_controller.rb
@@ -1,11 +1,6 @@
 # frozen_string_literal: true
 
-class Settings::MigrationsController < ApplicationController
-  layout 'admin'
-
-  before_action :authenticate_user!
-  before_action :set_body_classes
-
+class Settings::MigrationsController < Settings::BaseController
   def show
     @migration = Form::Migration.new(account: current_account.moved_to_account)
   end
@@ -32,8 +27,4 @@ class Settings::MigrationsController < ApplicationController
     current_account.moved_to_account_id != @migration.account&.id &&
       current_account.id != @migration.account&.id
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/notifications_controller.rb b/app/controllers/settings/notifications_controller.rb
index d0754296c..68ebddfc9 100644
--- a/app/controllers/settings/notifications_controller.rb
+++ b/app/controllers/settings/notifications_controller.rb
@@ -1,11 +1,6 @@
 # frozen_string_literal: true
 
-class Settings::NotificationsController < ApplicationController
-  layout 'admin'
-
-  before_action :authenticate_user!
-  before_action :set_body_classes
-
+class Settings::NotificationsController < Settings::BaseController
   def show; end
 
   def update
@@ -30,8 +25,4 @@ class Settings::NotificationsController < ApplicationController
       interactions: %i(must_be_follower must_be_following must_be_following_dm)
     )
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 7bb5fb112..5c5f31d2b 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -1,11 +1,6 @@
 # frozen_string_literal: true
 
-class Settings::PreferencesController < ApplicationController
-  layout 'admin'
-
-  before_action :authenticate_user!
-  before_action :set_body_classes
-
+class Settings::PreferencesController < Settings::BaseController
   def show; end
 
   def update
@@ -39,6 +34,7 @@ class Settings::PreferencesController < ApplicationController
       :setting_default_language,
       :setting_unfollow_modal,
       :setting_boost_modal,
+      :setting_favourite_modal,
       :setting_delete_modal,
       :setting_auto_play_gif,
       :setting_display_media,
@@ -46,14 +42,9 @@ class Settings::PreferencesController < ApplicationController
       :setting_reduce_motion,
       :setting_system_font_ui,
       :setting_noindex,
-      :setting_theme,
       :setting_hide_network,
       notification_emails: %i(follow follow_request reblog favourite mention digest report),
       interactions: %i(must_be_follower must_be_following)
     )
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/profiles_controller.rb b/app/controllers/settings/profiles_controller.rb
index 5b3bfd71f..918dbc6c6 100644
--- a/app/controllers/settings/profiles_controller.rb
+++ b/app/controllers/settings/profiles_controller.rb
@@ -1,13 +1,9 @@
 # frozen_string_literal: true
 
-class Settings::ProfilesController < ApplicationController
+class Settings::ProfilesController < Settings::BaseController
   include ObfuscateFilename
 
-  layout 'admin'
-
-  before_action :authenticate_user!
   before_action :set_account
-  before_action :set_body_classes
 
   obfuscate_filename [:account, :avatar]
   obfuscate_filename [:account, :header]
@@ -35,8 +31,4 @@ class Settings::ProfilesController < ApplicationController
   def set_account
     @account = current_user.account
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
diff --git a/app/controllers/settings/sessions_controller.rb b/app/controllers/settings/sessions_controller.rb
index 74cebc07b..f235dd477 100644
--- a/app/controllers/settings/sessions_controller.rb
+++ b/app/controllers/settings/sessions_controller.rb
@@ -1,5 +1,6 @@
 # frozen_string_literal: true
 
+#  Intentionally does not inherit from BaseController
 class Settings::SessionsController < ApplicationController
   before_action :set_session, only: :destroy
   before_action :set_body_classes
diff --git a/app/controllers/settings/two_factor_authentication/confirmations_controller.rb b/app/controllers/settings/two_factor_authentication/confirmations_controller.rb
index ee567c2a7..8518c61ee 100644
--- a/app/controllers/settings/two_factor_authentication/confirmations_controller.rb
+++ b/app/controllers/settings/two_factor_authentication/confirmations_controller.rb
@@ -2,12 +2,8 @@
 
 module Settings
   module TwoFactorAuthentication
-    class ConfirmationsController < ApplicationController
-      layout 'admin'
-
-      before_action :authenticate_user!
+    class ConfirmationsController < BaseController
       before_action :ensure_otp_secret
-      before_action :set_body_classes
 
       def new
         prepare_two_factor_form
@@ -44,10 +40,6 @@ module Settings
       def ensure_otp_secret
         redirect_to settings_two_factor_authentication_path unless current_user.otp_secret
       end
-
-      def set_body_classes
-        @body_classes = 'admin'
-      end
     end
   end
 end
diff --git a/app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb b/app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb
index bfb103620..94d1567f3 100644
--- a/app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb
+++ b/app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb
@@ -2,24 +2,13 @@
 
 module Settings
   module TwoFactorAuthentication
-    class RecoveryCodesController < ApplicationController
-      layout 'admin'
-
-      before_action :authenticate_user!
-      before_action :set_body_classes
-
+    class RecoveryCodesController < BaseController
       def create
         @recovery_codes = current_user.generate_otp_backup_codes!
         current_user.save!
         flash[:notice] = I18n.t('two_factor_authentication.recovery_codes_regenerated')
         render :index
       end
-
-      private
-
-      def set_body_classes
-        @body_classes = 'admin'
-      end
     end
   end
 end
diff --git a/app/controllers/settings/two_factor_authentications_controller.rb b/app/controllers/settings/two_factor_authentications_controller.rb
index e4d8aed41..8c7737e9d 100644
--- a/app/controllers/settings/two_factor_authentications_controller.rb
+++ b/app/controllers/settings/two_factor_authentications_controller.rb
@@ -1,12 +1,8 @@
 # frozen_string_literal: true
 
 module Settings
-  class TwoFactorAuthenticationsController < ApplicationController
-    layout 'admin'
-
-    before_action :authenticate_user!
+  class TwoFactorAuthenticationsController < BaseController
     before_action :verify_otp_required, only: [:create]
-    before_action :set_body_classes
 
     def show
       @confirmation = Form::TwoFactorConfirmation.new
@@ -44,9 +40,5 @@ module Settings
       current_user.validate_and_consume_otp!(confirmation_params[:code]) ||
         current_user.invalidate_otp_backup_code!(confirmation_params[:code])
     end
-
-    def set_body_classes
-      @body_classes = 'admin'
-    end
   end
 end