Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Rubocop optimization

Jan Sandbrink66def0cbf581
diff --git a/modules/auth_saml/app/controllers/saml/providers_controller.rb b/modules/auth_saml/app/controllers/saml/providers_controller.rb
index c4ffaa36093..2c52d37e8fc 100644
--- a/modules/auth_saml/app/controllers/saml/providers_controller.rb
+++ b/modules/auth_saml/app/controllers/saml/providers_controller.rb
@@ -20,11 +20,7 @@ module Saml
def edit
respond_to do |format|
format.turbo_stream do
- component = Saml::Providers::ViewComponent.new(@provider,
- view_mode: :edit,
- new_mode: @new_mode,
- edit_state: @edit_state)
- update_via_turbo_stream(component:)
+ update_view_component(view_mode: :edit, new_mode: @new_mode, edit_state: @edit_state)
scroll_into_view_via_turbo_stream("saml-providers-edit-form", behavior: :instant)
render turbo_stream: turbo_streams
end
@@ -114,14 +110,7 @@ module Saml
respond_to do |format|
format.turbo_stream do
- update_via_turbo_stream(
- component: Saml::Providers::ViewComponent.new(
- @provider,
- new_mode: @new_mode,
- edit_state: @next_edit_state,
- view_mode: :show
- )
- )
+ update_view_component(new_mode: @new_mode, edit_state: @next_edit_state, view_mode: :show)
render turbo_stream: turbo_streams
end
format.html do
@@ -137,6 +126,10 @@ module Saml
end
end
+ def update_view_component(new_mode:, edit_state:, view_mode:)
+ update_via_turbo_stream(component: Saml::Providers::ViewComponent.new(@provider, new_mode:, edit_state:, view_mode:))
+ end
+
def check_ee
redirect_to action: :index unless EnterpriseToken.allows_to?(:sso_auth_providers)
end
diff --git a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb
index 4ffa5cef1cf..0ea50c86405 100644
--- a/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb
+++ b/modules/openid_connect/app/controllers/openid_connect/providers_controller.rb
@@ -79,11 +79,7 @@ module OpenIDConnect
def edit
respond_to do |format|
format.turbo_stream do
- component = OpenIDConnect::Providers::ViewComponent.new(@provider,
- view_mode: :edit,
- new_mode: @new_mode,
- edit_state: @edit_state)
- update_via_turbo_stream(component:)
+ update_view_component(view_mode: :edit, new_mode: @new_mode, edit_state: @edit_state)
scroll_into_view_via_turbo_stream("openid-connect-providers-edit-form", behavior: :instant)
render turbo_stream: turbo_streams
end
@@ -152,14 +148,7 @@ module OpenIDConnect
respond_to do |format|
format.turbo_stream do
- update_via_turbo_stream(
- component: OpenIDConnect::Providers::ViewComponent.new(
- @provider,
- new_mode: @new_mode,
- edit_state: @next_edit_state,
- view_mode: :show
- )
- )
+ update_view_component(new_mode: @new_mode, edit_state: @next_edit_state, view_mode: :show)
render turbo_stream: turbo_streams
end
format.html do
@@ -179,14 +168,7 @@ module OpenIDConnect
def failed_save_response(action_to_render)
respond_to do |format|
format.turbo_stream do
- update_via_turbo_stream(
- component: OpenIDConnect::Providers::ViewComponent.new(
- @provider,
- new_mode: @new_mode,
- edit_state: @edit_state,
- view_mode: :show
- )
- )
+ update_view_component(new_mode: @new_mode, edit_state: @edit_state, view_mode: :show)
render turbo_stream: turbo_streams
end
format.html do
@@ -195,6 +177,12 @@ module OpenIDConnect
end
end
+ def update_view_component(new_mode:, edit_state:, view_mode:)
+ update_via_turbo_stream(
+ component: OpenIDConnect::Providers::ViewComponent.new(@provider, new_mode:, edit_state:, view_mode:)
+ )
+ end
+
def set_edit_state
@edit_state = params[:edit_state].to_sym if params.key?(:edit_state)
@new_mode = ActiveRecord::Type::Boolean.new.cast(params[:new_mode])