]> cat aescling's git repositories - mastodon.git/commitdiff
Create Settings::BaseController (#9507)
authorysksn <bluewhale1982@gmail.com>
Wed, 12 Dec 2018 21:32:13 +0000 (06:32 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 12 Dec 2018 21:32:13 +0000 (22:32 +0100)
Define `Settings::BaseController#set_body_classes` so that sub classes
inherit `Settings::BaseController` don't need to define
`#set_body_classes` agein.

14 files changed:
app/controllers/settings/applications_controller.rb
app/controllers/settings/base_controller.rb [new file with mode: 0644]
app/controllers/settings/deletes_controller.rb
app/controllers/settings/exports_controller.rb
app/controllers/settings/follower_domains_controller.rb
app/controllers/settings/imports_controller.rb
app/controllers/settings/migrations_controller.rb
app/controllers/settings/notifications_controller.rb
app/controllers/settings/preferences_controller.rb
app/controllers/settings/profiles_controller.rb
app/controllers/settings/sessions_controller.rb
app/controllers/settings/two_factor_authentication/confirmations_controller.rb
app/controllers/settings/two_factor_authentication/recovery_codes_controller.rb
app/controllers/settings/two_factor_authentications_controller.rb

index a1a2c57fa05bfa9a5b859d24dcb900e8e1c3de1e..ed3f82a8e06e693e8107c0fbdf2211d7ec48a3a0 100644 (file)
@@ -1,12 +1,11 @@
 # frozen_string_literal: true
 
-class Settings::ApplicationsController < ApplicationController
+class Settings::ApplicationsController < Settings::BaseController
   layout 'admin'
 
   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 +69,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 (file)
index 0000000..9bb14af
--- /dev/null
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Settings::BaseController < ApplicationController
+  before_action :set_body_classes
+
+  private
+
+  def set_body_classes
+    @body_classes = 'admin'
+  end
+end
index 97f3946c87afd60e53c22ec54894270b7b8b168c..dd19aadf636b6fd35541efdc4552ccf0e6b66bd9 100644 (file)
@@ -1,11 +1,10 @@
 # frozen_string_literal: true
 
-class Settings::DeletesController < ApplicationController
+class Settings::DeletesController < Settings::BaseController
   layout 'admin'
 
   before_action :check_enabled_deletion
   before_action :authenticate_user!
-  before_action :set_body_classes
 
   def show
     @confirmation = Form::DeleteConfirmation.new
@@ -30,8 +29,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
index 3a2334ef0031941db7f30c7b7c95d28dec97bab4..0135f21890dd0e81bd0bbd9290b669603e1388f1 100644 (file)
@@ -1,12 +1,11 @@
 # 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)
@@ -21,10 +20,4 @@ class Settings::ExportsController < ApplicationController
 
     redirect_to settings_export_path
   end
-
-  private
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
index 9c39e66bbb1c04e175eb356cce67b73fd0284325..ce8ec985d62b5772a09f0ce3ee058b4b1606fd35 100644 (file)
@@ -1,10 +1,9 @@
 # frozen_string_literal: true
 
-class Settings::FollowerDomainsController < ApplicationController
+class Settings::FollowerDomainsController < Settings::BaseController
   layout 'admin'
 
   before_action :authenticate_user!
-  before_action :set_body_classes
 
   def show
     @account = current_account
@@ -26,8 +25,4 @@ class Settings::FollowerDomainsController < ApplicationController
   def bulk_params
     params.permit(select: [])
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
index e9548ce62921a723d3d2171218721ace62904029..38f2e39c1d179ceb3c357d29f0f313c8bb43e646 100644 (file)
@@ -1,11 +1,10 @@
 # frozen_string_literal: true
 
-class Settings::ImportsController < ApplicationController
+class Settings::ImportsController < Settings::BaseController
   layout 'admin'
 
   before_action :authenticate_user!
   before_action :set_account
-  before_action :set_body_classes
 
   def show
     @import = Import.new
@@ -32,8 +31,4 @@ class Settings::ImportsController < ApplicationController
   def import_params
     params.require(:import).permit(:data, :type)
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
index bd4f9c87afa3abe78023b29e453755206001a8ab..59eb48779c142bd274d138be83936661b74042e7 100644 (file)
@@ -1,10 +1,9 @@
 # frozen_string_literal: true
 
-class Settings::MigrationsController < ApplicationController
+class Settings::MigrationsController < Settings::BaseController
   layout 'admin'
 
   before_action :authenticate_user!
-  before_action :set_body_classes
 
   def show
     @migration = Form::Migration.new(account: current_account.moved_to_account)
@@ -32,8 +31,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
index d0754296ccc7dc62ef511a136606d2bee27e1a88..da8a03d96491d815c2844ed4fb8ef74c8dda2f94 100644 (file)
@@ -1,10 +1,9 @@
 # frozen_string_literal: true
 
-class Settings::NotificationsController < ApplicationController
+class Settings::NotificationsController < Settings::BaseController
   layout 'admin'
 
   before_action :authenticate_user!
-  before_action :set_body_classes
 
   def show; end
 
@@ -30,8 +29,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
index 70e71b4a2451b4648fefbb95315132865c22bd7d..41df3bde2fcda328a4ef003543aca4ba602486c3 100644 (file)
@@ -1,10 +1,9 @@
 # frozen_string_literal: true
 
-class Settings::PreferencesController < ApplicationController
+class Settings::PreferencesController < Settings::BaseController
   layout 'admin'
 
   before_action :authenticate_user!
-  before_action :set_body_classes
 
   def show; end
 
@@ -53,8 +52,4 @@ class Settings::PreferencesController < ApplicationController
       interactions: %i(must_be_follower must_be_following)
     )
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
index 20a55785c51ba3c2738c30f6820b764bb3f4e8a9..db9081fdf012a7029456c5c51ff3b1e072ad3ea1 100644 (file)
@@ -1,13 +1,12 @@
 # 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 +34,4 @@ class Settings::ProfilesController < ApplicationController
   def set_account
     @account = current_user.account
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
index 74cebc07b6a6b0b2c6d27729a953dd3804a484fa..11b150ffd3ae0f5da9038e717eb9353f15740824 100644 (file)
@@ -1,8 +1,7 @@
 # frozen_string_literal: true
 
-class Settings::SessionsController < ApplicationController
+class Settings::SessionsController < Settings::BaseController
   before_action :set_session, only: :destroy
-  before_action :set_body_classes
 
   def destroy
     @session.destroy!
@@ -15,8 +14,4 @@ class Settings::SessionsController < ApplicationController
   def set_session
     @session = current_user.session_activations.find(params[:id])
   end
-
-  def set_body_classes
-    @body_classes = 'admin'
-  end
 end
index ee567c2a7ce9856fcdf6396015bffb5de19e61ad..d87117a50a846c3a31023db36c2ef47cc63020a4 100644 (file)
@@ -2,12 +2,11 @@
 
 module Settings
   module TwoFactorAuthentication
-    class ConfirmationsController < ApplicationController
+    class ConfirmationsController < BaseController
       layout 'admin'
 
       before_action :authenticate_user!
       before_action :ensure_otp_secret
-      before_action :set_body_classes
 
       def new
         prepare_two_factor_form
@@ -44,10 +43,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
index bfb103620bb58babe6fe6117dd78bade754b7d91..c78166c6542e722b09091f2338c272f62145cb10 100644 (file)
@@ -2,11 +2,10 @@
 
 module Settings
   module TwoFactorAuthentication
-    class RecoveryCodesController < ApplicationController
+    class RecoveryCodesController < BaseController
       layout 'admin'
 
       before_action :authenticate_user!
-      before_action :set_body_classes
 
       def create
         @recovery_codes = current_user.generate_otp_backup_codes!
@@ -14,12 +13,6 @@ module Settings
         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
index e4d8aed41314ca180f53fa28d5d40bba0c1c6737..e12c4307468653c19c5a0c5e8c7cd5dc6d2792f5 100644 (file)
@@ -1,12 +1,11 @@
 # frozen_string_literal: true
 
 module Settings
-  class TwoFactorAuthenticationsController < ApplicationController
+  class TwoFactorAuthenticationsController < BaseController
     layout 'admin'
 
     before_action :authenticate_user!
     before_action :verify_otp_required, only: [:create]
-    before_action :set_body_classes
 
     def show
       @confirmation = Form::TwoFactorConfirmation.new
@@ -44,9 +43,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