Merge pull request #2885 from okriuchykhin/ok_SCI_5080

Fix team switcher [SCI-5080]
This commit is contained in:
Alex Kriuchykhin 2020-10-02 14:57:29 +02:00 committed by GitHub
commit dc6ee42e1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 14 deletions

View file

@ -37,7 +37,7 @@ class ApplicationController < ActionController::Base
# Sets current team for all controllers
def current_team
@current_team ||= Team.find_by(id: current_user.current_team_id)
@current_team ||= current_user.teams.find_by(id: current_user.current_team_id)
end
def to_user_date_format
@ -83,13 +83,12 @@ class ApplicationController < ActionController::Base
private
def update_current_team
@current_team = Team.find_by_id(current_user.current_team_id)
if (current_team.nil? || !current_user.is_member_of_team?(current_team)) &&
current_user.teams.count.positive?
return if current_team.present? && current_team.id == current_user.current_team_id
current_user.update(
current_team_id: current_user.teams.first.id
)
if current_user.current_team_id
@current_team = current_user.teams.find_by(id: current_user.current_team_id)
elsif current_user.teams.any?
current_user.update(current_team_id: current_user.teams.first.id)
end
end

View file

@ -1,7 +1,7 @@
module TeamsHelper
# resets the current team if needed
def current_team_switch(team)
if team != current_team
if team != current_team && current_user.is_member_of_team?(team)
current_user.current_team_id = team.id
current_user.save
update_current_team
@ -18,11 +18,7 @@ module TeamsHelper
end
end
def team_created_by(team)
User.find_by_id(team.created_by_id)
end
def switch_team_with_param
current_team_switch(Team.find_by(id: params[:team])) if params[:team]
current_team_switch(current_user.teams.find_by(id: params[:team])) if params[:team]
end
end

View file

@ -44,7 +44,9 @@
<div class="created-by grid-block">
<span class="fas fa-user fa-lg"></span>
<span class="hidden-xs hidden-sm"><%= t("users.settings.teams.edit.header_created_by") %></span>
<b><%= t("users.settings.teams.edit.header_created_by_name_email", name: team_created_by(@team).name, email: team_created_by(@team).email) %></b>
<b>
<%= t('users.settings.teams.edit.header_created_by_name_email', name: @team.created_by.full_name, email: @team.created_by.email) if @team.created_by %>
</b>
</div>
<div class="space-usage grid-block">