From 173e3b09cd3cdf07a903892d8603e186ccefdc16 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Thu, 6 Oct 2022 17:55:51 +0200 Subject: [PATCH] Fix user invitation modal [SCI-7308] --- app/helpers/user_roles_helper.rb | 8 +++++--- app/models/user_role.rb | 4 ++++ app/views/shared/_invite_users_modal.html.erb | 10 ++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/helpers/user_roles_helper.rb b/app/helpers/user_roles_helper.rb index 9ebc9b252..a8a16828a 100644 --- a/app/helpers/user_roles_helper.rb +++ b/app/helpers/user_roles_helper.rb @@ -2,9 +2,7 @@ module UserRolesHelper def user_roles_collection - Rails.cache.fetch([current_user, 'available_user_roles']) do - @user_roles_collection ||= UserRole.order(id: :asc).pluck(:name, :id) - end + UserRole.order(id: :asc).pluck(:name, :id) end def team_user_roles_collection @@ -17,6 +15,10 @@ module UserRolesHelper .reverse! end + def team_user_roles_for_select + team_user_roles_collection.pluck(:name, :id) + end + def managing_team_user_roles_collection UserRole.where('permissions && ARRAY[?]::varchar[]', [TeamPermissions::USERS_MANAGE]) end diff --git a/app/models/user_role.rb b/app/models/user_role.rb index a443de076..b8ec61394 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -53,6 +53,10 @@ class UserRole < ApplicationRecord predefined.find_by(name: UserRole.public_send('owner_role').name) end + def self.find_predefined_normal_user_role + predefined.find_by(name: UserRole.public_send('normal_user_role').name) + end + def owner? name == I18n.t('user_roles.predefined.owner') end diff --git a/app/views/shared/_invite_users_modal.html.erb b/app/views/shared/_invite_users_modal.html.erb index 80959c47e..4c94e2ed9 100644 --- a/app/views/shared/_invite_users_modal.html.erb +++ b/app/views/shared/_invite_users_modal.html.erb @@ -113,11 +113,13 @@ invite_with_team_selector = type.in?(%w(invite_new_members invite_with_team_sele <%= t('invite_users.select_team_role') %>
+ <% normal_user_role = UserRole.find_predefined_normal_user_role %> <%= select_tag "role", - options_for_select(UserTeam.roles.keys - .map { |k| [k.humanize + (k == 'normal_user' ? " (#{t('invite_users.default')})" : ''), k] }, 'normal_user'), - disabled: true, class: "role-input from-control" - %> + options_for_select( + team_user_roles_for_select + .map { |name, id| [id == normal_user_role.id ? "#{name} (#{t('invite_users.default')})" : name, id] }, + normal_user_role.id + ), disabled: true, class: "role-input from-control" %>