From 9236756bfe981592c683ca1be5765636f17360fb Mon Sep 17 00:00:00 2001 From: Jan Kessler Date: Wed, 15 May 2024 10:15:04 +0200 Subject: [PATCH 1/3] apply meta_server-tag in default/override create parameters early in the create call, to actually achieve the effect on server selection --- .../bigbluebutton_api_controller.rb | 1 + app/controllers/concerns/api_helper.rb | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/bigbluebutton_api_controller.rb b/app/controllers/bigbluebutton_api_controller.rb index 46837c6a..7b124bb3 100644 --- a/app/controllers/bigbluebutton_api_controller.rb +++ b/app/controllers/bigbluebutton_api_controller.rb @@ -159,6 +159,7 @@ def get_meetings_disabled def create params.require(:meetingID) + apply_config_server_tag(params) begin # Check if meeting is already running meeting = Meeting.find(params[:meetingID], @tenant&.id) diff --git a/app/controllers/concerns/api_helper.rb b/app/controllers/concerns/api_helper.rb index 10f24314..72c58df2 100644 --- a/app/controllers/concerns/api_helper.rb +++ b/app/controllers/concerns/api_helper.rb @@ -196,15 +196,18 @@ def add_additional_params(action, bbb_params) else [{}, {}] end + # Server tag is handled separately in create call + default.delete(:'meta_server-tag') + override.delete(:'meta_server-tag') final_params = default&.merge(final_params) case action when 'create' # Merge with the default (bbb_params takes precedence) - final_params = Rails.configuration.x.default_create_params.merge(final_params) + final_params = Rails.configuration.x.default_create_params.except(:'meta_server-tag').merge(final_params) # Merge with the override (override takes precedence) - final_params.merge!(Rails.configuration.x.override_create_params) + final_params.merge!(Rails.configuration.x.override_create_params.except(:'meta_server-tag')) when 'join' # Merge with the default (bbb_params takes precedence) final_params = Rails.configuration.x.default_join_params.merge(final_params) @@ -216,4 +219,17 @@ def add_additional_params(action, bbb_params) final_params end + + # early handling of server tag in default/override create settings + def apply_config_server_tag(params) + if Rails.configuration.x.multitenancy_enabled + default_tenant, override_tenant = TenantSetting.defaults_and_overrides(@tenant&.id) + params[:'meta_server-tag'] = default_tenant[:'meta_server-tag'] if params[:'meta_server-tag'].nil? && !default_tenant[:'meta_server-tag'].nil? + params[:'meta_server-tag'] = override_tenant[:'meta_server-tag'] unless override_tenant[:'meta_server-tag'].nil? + end + default = Rails.configuration.x.default_create_params + override = Rails.configuration.x.override_create_params + params[:'meta_server-tag'] = default[:'meta_server-tag'] if params[:'meta_server-tag'].nil? && !default[:'meta_server-tag'].nil? + params[:'meta_server-tag'] = override[:'meta_server-tag'] unless override[:'meta_server-tag'].nil? + end end From 8e49cea13c675eb0985ec3dd7d06f417dd74e9a6 Mon Sep 17 00:00:00 2001 From: Jan Kessler Date: Wed, 15 May 2024 20:07:59 +0200 Subject: [PATCH 2/3] change order in apply_config_server_tag to mimic the order of precedence of defaults/override as in add_additional_params --- app/controllers/concerns/api_helper.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/api_helper.rb b/app/controllers/concerns/api_helper.rb index 72c58df2..44e550db 100644 --- a/app/controllers/concerns/api_helper.rb +++ b/app/controllers/concerns/api_helper.rb @@ -222,14 +222,13 @@ def add_additional_params(action, bbb_params) # early handling of server tag in default/override create settings def apply_config_server_tag(params) - if Rails.configuration.x.multitenancy_enabled - default_tenant, override_tenant = TenantSetting.defaults_and_overrides(@tenant&.id) - params[:'meta_server-tag'] = default_tenant[:'meta_server-tag'] if params[:'meta_server-tag'].nil? && !default_tenant[:'meta_server-tag'].nil? - params[:'meta_server-tag'] = override_tenant[:'meta_server-tag'] unless override_tenant[:'meta_server-tag'].nil? - end default = Rails.configuration.x.default_create_params override = Rails.configuration.x.override_create_params + default_tenant, override_tenant = TenantSetting.defaults_and_overrides(@tenant&.id) + + params[:'meta_server-tag'] = default_tenant[:'meta_server-tag'] if params[:'meta_server-tag'].nil? && !default_tenant[:'meta_server-tag'].nil? params[:'meta_server-tag'] = default[:'meta_server-tag'] if params[:'meta_server-tag'].nil? && !default[:'meta_server-tag'].nil? params[:'meta_server-tag'] = override[:'meta_server-tag'] unless override[:'meta_server-tag'].nil? + params[:'meta_server-tag'] = override_tenant[:'meta_server-tag'] unless override_tenant[:'meta_server-tag'].nil? end end From 9c622d0b7cdd2cd86a80e30c3d367dedc334d5ac Mon Sep 17 00:00:00 2001 From: Jan Kessler Date: Tue, 2 Jul 2024 16:35:23 +0200 Subject: [PATCH 3/3] simplify the implementation of order of precedence for meta_server-tag overrides/defaults --- app/controllers/concerns/api_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/api_helper.rb b/app/controllers/concerns/api_helper.rb index 627ea186..e948704d 100644 --- a/app/controllers/concerns/api_helper.rb +++ b/app/controllers/concerns/api_helper.rb @@ -248,9 +248,11 @@ def apply_config_server_tag(params) override = Rails.configuration.x.override_create_params default_tenant, override_tenant = TenantSetting.defaults_and_overrides(@tenant&.id) - params[:'meta_server-tag'] = default_tenant[:'meta_server-tag'] if params[:'meta_server-tag'].nil? && !default_tenant[:'meta_server-tag'].nil? - params[:'meta_server-tag'] = default[:'meta_server-tag'] if params[:'meta_server-tag'].nil? && !default[:'meta_server-tag'].nil? - params[:'meta_server-tag'] = override[:'meta_server-tag'] unless override[:'meta_server-tag'].nil? - params[:'meta_server-tag'] = override_tenant[:'meta_server-tag'] unless override_tenant[:'meta_server-tag'].nil? + params[:'meta_server-tag'] = + override_tenant[:'meta_server-tag'].presence || + override[:'meta_server-tag'].presence || + params[:'meta_server-tag'].presence || + default_tenant[:'meta_server-tag'].presence || + default[:'meta_server-tag'].presence end end