mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 16:31:22 +08:00
Merge pull request #2885 from okriuchykhin/ok_SCI_5080
Fix team switcher [SCI-5080]
This commit is contained in:
commit
dc6ee42e1d
3 changed files with 11 additions and 14 deletions
|
|
@ -37,7 +37,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# Sets current team for all controllers
|
# Sets current team for all controllers
|
||||||
def current_team
|
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
|
end
|
||||||
|
|
||||||
def to_user_date_format
|
def to_user_date_format
|
||||||
|
|
@ -83,13 +83,12 @@ class ApplicationController < ActionController::Base
|
||||||
private
|
private
|
||||||
|
|
||||||
def update_current_team
|
def update_current_team
|
||||||
@current_team = Team.find_by_id(current_user.current_team_id)
|
return if current_team.present? && current_team.id == current_user.current_team_id
|
||||||
if (current_team.nil? || !current_user.is_member_of_team?(current_team)) &&
|
|
||||||
current_user.teams.count.positive?
|
|
||||||
|
|
||||||
current_user.update(
|
if current_user.current_team_id
|
||||||
current_team_id: current_user.teams.first.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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
module TeamsHelper
|
module TeamsHelper
|
||||||
# resets the current team if needed
|
# resets the current team if needed
|
||||||
def current_team_switch(team)
|
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.current_team_id = team.id
|
||||||
current_user.save
|
current_user.save
|
||||||
update_current_team
|
update_current_team
|
||||||
|
|
@ -18,11 +18,7 @@ module TeamsHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def team_created_by(team)
|
|
||||||
User.find_by_id(team.created_by_id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def switch_team_with_param
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,9 @@
|
||||||
<div class="created-by grid-block">
|
<div class="created-by grid-block">
|
||||||
<span class="fas fa-user fa-lg"></span>
|
<span class="fas fa-user fa-lg"></span>
|
||||||
<span class="hidden-xs hidden-sm"><%= t("users.settings.teams.edit.header_created_by") %></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>
|
||||||
|
|
||||||
<div class="space-usage grid-block">
|
<div class="space-usage grid-block">
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue