From cac94bf86a99fcbfbda9bd3521910b1f26c92cef Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Mon, 21 Oct 2024 10:43:19 +0200 Subject: [PATCH 1/5] Extract params --- .../communication/extranets_controller.rb | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index a85d0378b..204baa96f 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -65,33 +65,40 @@ def do_confirm_localization protected + PERMITTED_PARAMS = [ + :color + ] + PERMITTED_PARAMS_FOR_LOCALIZATIONS = [ + :id, :language_id, + :name, :published, + :registration_contact, + :logo, :logo_delete, + :favicon, :favicon_delete, + :home_sentence, + :terms, :privacy_policy, :cookies_policy + ] + EXTENDED_PERMITTED_PARAMS = [ + :host, :about_id, :about_type, :sass, + :feature_alumni, :feature_documents, :feature_contacts, :feature_jobs, :feature_posts, + :has_sso, :sso_target_url, :sso_cert, :sso_name_identifier_format, :sso_mapping + ] + EXTENDED_PERMITTED_PARAMS_FOR_LOCALIZATIONS = [ + :sso_button_label + ] + def extranet_params - allowed_params = [ - :color - ] - localizations_attributes = [ - :id, :language_id, - :name, :published, - :registration_contact, - :logo, :logo_delete, - :favicon, :favicon_delete, - :home_sentence, - :terms, :privacy_policy, :cookies_policy - ] + permitted_params = PERMITTED_PARAMS + localizations_attributes = PERMITTED_PARAMS_FOR_LOCALIZATIONS if can?(:create, Communication::Extranet) - allowed_params += [ - :host, :about_id, :about_type, :sass, - :feature_alumni, :feature_documents, :feature_contacts, :feature_jobs, :feature_posts, - :has_sso, :sso_target_url, :sso_cert, :sso_name_identifier_format, :sso_mapping - ] - localizations_attributes += [ - :sso_button_label - ] + permitted_params += EXTENDED_PERMITTED_PARAMS + localizations_attributes += EXTENDED_PERMITTED_PARAMS_FOR_LOCALIZATIONS end - allowed_params << :default_language_id if @extranet&.persisted? - allowed_params << { localizations_attributes: localizations_attributes } + permitted_params << :default_language_id if @extranet&.persisted? + permitted_params << { + localizations_attributes: localizations_attributes + } params.require(:communication_extranet) - .permit(allowed_params) + .permit(permitted_params) .merge( university_id: current_university.id ) From c9b3357169b426fc0e972811da5c3cc91cd82aec Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Tue, 29 Oct 2024 06:58:10 +0100 Subject: [PATCH 2/5] clean --- .../communication/extranets_controller.rb | 49 +++++++++++++------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index 204baa96f..72e2c20ed 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -69,24 +69,49 @@ def do_confirm_localization :color ] PERMITTED_PARAMS_FOR_LOCALIZATIONS = [ - :id, :language_id, - :name, :published, - :registration_contact, - :logo, :logo_delete, - :favicon, :favicon_delete, + :cookies_policy, + :favicon, + :favicon_delete, :home_sentence, - :terms, :privacy_policy, :cookies_policy + :id, + :language_id, + :logo, + :logo_delete, + :name, + :privacy_policy, + :published, + :registration_contact, + :terms ] EXTENDED_PERMITTED_PARAMS = [ - :host, :about_id, :about_type, :sass, - :feature_alumni, :feature_documents, :feature_contacts, :feature_jobs, :feature_posts, - :has_sso, :sso_target_url, :sso_cert, :sso_name_identifier_format, :sso_mapping + :about_id, + :about_type, + :feature_alumni, + :feature_contacts, + :feature_documents, + :feature_jobs, + :feature_posts, + :has_sso, + :host, + :sass, + :sso_cert, + :sso_mapping, + :sso_name_identifier_format, + :sso_target_url ] EXTENDED_PERMITTED_PARAMS_FOR_LOCALIZATIONS = [ :sso_button_label ] def extranet_params + params.require(:communication_extranet) + .permit(permitted_params) + .merge( + university_id: current_university.id + ) + end + + def permitted_params permitted_params = PERMITTED_PARAMS localizations_attributes = PERMITTED_PARAMS_FOR_LOCALIZATIONS if can?(:create, Communication::Extranet) @@ -97,10 +122,6 @@ def extranet_params permitted_params << { localizations_attributes: localizations_attributes } - params.require(:communication_extranet) - .permit(permitted_params) - .merge( - university_id: current_university.id - ) + permitted_params end end From 88c9dcdb628c7d244add8752d4b1c7d6edbe482f Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 31 Oct 2024 09:46:47 +0100 Subject: [PATCH 3/5] better --- .../communication/extranets_controller.rb | 95 +++++++++++-------- 1 file changed, 53 insertions(+), 42 deletions(-) diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index 72e2c20ed..f9eecf627 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -65,44 +65,6 @@ def do_confirm_localization protected - PERMITTED_PARAMS = [ - :color - ] - PERMITTED_PARAMS_FOR_LOCALIZATIONS = [ - :cookies_policy, - :favicon, - :favicon_delete, - :home_sentence, - :id, - :language_id, - :logo, - :logo_delete, - :name, - :privacy_policy, - :published, - :registration_contact, - :terms - ] - EXTENDED_PERMITTED_PARAMS = [ - :about_id, - :about_type, - :feature_alumni, - :feature_contacts, - :feature_documents, - :feature_jobs, - :feature_posts, - :has_sso, - :host, - :sass, - :sso_cert, - :sso_mapping, - :sso_name_identifier_format, - :sso_target_url - ] - EXTENDED_PERMITTED_PARAMS_FOR_LOCALIZATIONS = [ - :sso_button_label - ] - def extranet_params params.require(:communication_extranet) .permit(permitted_params) @@ -112,11 +74,11 @@ def extranet_params end def permitted_params - permitted_params = PERMITTED_PARAMS - localizations_attributes = PERMITTED_PARAMS_FOR_LOCALIZATIONS + permitted_params = params_base + localizations_attributes = localization_params_base if can?(:create, Communication::Extranet) - permitted_params += EXTENDED_PERMITTED_PARAMS - localizations_attributes += EXTENDED_PERMITTED_PARAMS_FOR_LOCALIZATIONS + permitted_params += params_extended + localizations_attributes += localization_params_extended end permitted_params << :default_language_id if @extranet&.persisted? permitted_params << { @@ -124,4 +86,53 @@ def permitted_params } permitted_params end + + def params_base + [ + :color + ] + end + + def params_extended + [ + :about_id, + :about_type, + :feature_alumni, + :feature_contacts, + :feature_documents, + :feature_jobs, + :feature_posts, + :has_sso, + :host, + :sass, + :sso_cert, + :sso_mapping, + :sso_name_identifier_format, + :sso_target_url + ] + end + + def localization_params_base + [ + :cookies_policy, + :favicon, + :favicon_delete, + :home_sentence, + :id, + :language_id, + :logo, + :logo_delete, + :name, + :privacy_policy, + :published, + :registration_contact, + :terms + ] + end + + def localization_params_extended + [ + :sso_button_label + ] + end end From 3d25fecb37b6df0e3c56492dc28f5ff45163dba8 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 31 Oct 2024 09:48:15 +0100 Subject: [PATCH 4/5] better --- .../admin/communication/extranets_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index f9eecf627..0c60a1fc0 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -74,10 +74,10 @@ def extranet_params end def permitted_params - permitted_params = params_base - localizations_attributes = localization_params_base + permitted_params = base_params + localizations_attributes = base_localization_params if can?(:create, Communication::Extranet) - permitted_params += params_extended + permitted_params += extended_params localizations_attributes += localization_params_extended end permitted_params << :default_language_id if @extranet&.persisted? @@ -87,13 +87,13 @@ def permitted_params permitted_params end - def params_base + def base_params [ :color ] end - def params_extended + def extended_params [ :about_id, :about_type, @@ -112,7 +112,7 @@ def params_extended ] end - def localization_params_base + def base_localization_params [ :cookies_policy, :favicon, @@ -130,7 +130,7 @@ def localization_params_base ] end - def localization_params_extended + def extended_localization_params [ :sso_button_label ] From 36cd3bf27da3ce0df7dbb7c999e9880be516f12b Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 31 Oct 2024 09:48:56 +0100 Subject: [PATCH 5/5] fix --- .../communication/extranets_controller.rb | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index 0c60a1fc0..9756c0cc3 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -78,7 +78,7 @@ def permitted_params localizations_attributes = base_localization_params if can?(:create, Communication::Extranet) permitted_params += extended_params - localizations_attributes += localization_params_extended + localizations_attributes += extended_localization_params end permitted_params << :default_language_id if @extranet&.persisted? permitted_params << { @@ -93,6 +93,24 @@ def base_params ] end + def base_localization_params + [ + :cookies_policy, + :favicon, + :favicon_delete, + :home_sentence, + :id, + :language_id, + :logo, + :logo_delete, + :name, + :privacy_policy, + :published, + :registration_contact, + :terms + ] + end + def extended_params [ :about_id, @@ -112,24 +130,6 @@ def extended_params ] end - def base_localization_params - [ - :cookies_policy, - :favicon, - :favicon_delete, - :home_sentence, - :id, - :language_id, - :logo, - :logo_delete, - :name, - :privacy_policy, - :published, - :registration_contact, - :terms - ] - end - def extended_localization_params [ :sso_button_label