diff --git a/app/controllers/template_sharings_testing_controller.rb b/app/controllers/template_sharings_testing_controller.rb
index c8f646962..7c642f7d9 100644
--- a/app/controllers/template_sharings_testing_controller.rb
+++ b/app/controllers/template_sharings_testing_controller.rb
@@ -8,7 +8,9 @@ class TemplateSharingsTestingController < ApplicationController
end
def create
- testing_account = Accounts.find_or_create_testing_user(true_user.account).account
+ account = can?(:manage, :tenants_test) ? current_account : true_user.account
+
+ testing_account = Accounts.find_or_create_testing_user(account).account
if params[:value] == '1'
TemplateSharing.create!(ability: :manage, account: testing_account, template: @template)
diff --git a/app/views/templates_code_modal/show.html.erb b/app/views/templates_code_modal/show.html.erb
index c7bce02fd..0c72d6dd2 100644
--- a/app/views/templates_code_modal/show.html.erb
+++ b/app/views/templates_code_modal/show.html.erb
@@ -26,7 +26,7 @@
<%= t('share_template_with_test_mode') %>
- <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: true_user.account.testing_accounts) %>
+ <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: (can?(:manage, :tenants_test) ? current_account : true_user.account).testing_accounts) %>
<% end %>
diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb
index 91b0512b2..f6df9d583 100644
--- a/app/views/templates_preferences/show.html.erb
+++ b/app/views/templates_preferences/show.html.erb
@@ -194,7 +194,7 @@
<%= t('share_template_with_test_mode') %>
- <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: true_user.account.testing_accounts) %>
+ <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: (can?(:manage, :tenants_test) ? current_account : true_user.account).testing_accounts) %>
<% end %>