Add before_action for team switch

This commit is contained in:
Urban Rotnik 2020-04-23 16:02:36 +02:00
parent 38c198705c
commit de4e4ca967
8 changed files with 20 additions and 12 deletions

View file

@ -23,6 +23,7 @@ class ProtocolsController < ApplicationController
linked_children linked_children
linked_children_datatable linked_children_datatable
) )
before_action :switch_team_with_param, only: :index
before_action :check_view_all_permissions, only: %i( before_action :check_view_all_permissions, only: %i(
index index
datatable datatable

View file

@ -31,6 +31,7 @@ class ReportsController < ApplicationController
only: %i(new edit available_repositories) only: %i(new edit available_repositories)
before_action :check_manage_permissions, only: BEFORE_ACTION_METHODS before_action :check_manage_permissions, only: BEFORE_ACTION_METHODS
before_action :switch_team_with_param, only: :index
# Index showing all reports of a single project # Index showing all reports of a single project
def index; end def index; end

View file

@ -5,7 +5,9 @@ class RepositoriesController < ApplicationController
include ActionView::Helpers::TagHelper include ActionView::Helpers::TagHelper
include ActionView::Context include ActionView::Context
include IconsHelper include IconsHelper
include TeamsHelper
before_action :switch_team_with_param, only: :show
before_action :load_vars, before_action :load_vars,
except: %i(index create create_modal parse_sheet) except: %i(index create create_modal parse_sheet)
before_action :load_parent_vars, except: before_action :load_parent_vars, except:

View file

@ -44,15 +44,15 @@ module GlobalActivitiesHelper
when Team when Team
path = projects_path(team: obj.id) path = projects_path(team: obj.id)
when Repository when Repository
path = repository_path(obj) path = repository_path(obj, team: obj.team.id)
when RepositoryRow when RepositoryRow
return current_value unless obj.repository return current_value unless obj.repository
path = repository_path(obj.repository) path = repository_path(obj.repository, team: obj.repository.team.id)
when RepositoryColumn when RepositoryColumn
return current_value unless obj.repository return current_value unless obj.repository
path = repository_path(obj.repository) path = repository_path(obj.repository, team: obj.repository.team.id)
when Project when Project
path = obj.archived? ? projects_path : project_path(obj) path = obj.archived? ? projects_path : project_path(obj)
when Experiment when Experiment
@ -73,11 +73,11 @@ module GlobalActivitiesHelper
end end
when Protocol when Protocol
if obj.in_repository_public? if obj.in_repository_public?
path = protocols_path(type: :public) path = protocols_path(type: :public, team: obj.team.id)
elsif obj.in_repository_private? elsif obj.in_repository_private?
path = protocols_path(type: :private) path = protocols_path(type: :private, team: obj.team.id)
elsif obj.in_repository_archived? elsif obj.in_repository_archived?
path = protocols_path(type: :archive) path = protocols_path(type: :archive, team: obj.team.id)
elsif obj.my_module.navigable? elsif obj.my_module.navigable?
path = protocols_my_module_path(obj.my_module) path = protocols_my_module_path(obj.my_module)
else else
@ -90,7 +90,7 @@ module GlobalActivitiesHelper
when Step when Step
return current_value return current_value
when Report when Report
path = reports_path path = reports_path(team: obj.team.id)
else else
return current_value return current_value
end end

View file

@ -20,4 +20,8 @@ module TeamsHelper
def team_created_by(team) def team_created_by(team)
User.find_by_id(team.created_by_id) User.find_by_id(team.created_by_id)
end end
def switch_team_with_param
current_team_switch(Team.find_by(id: params[:team])) if params[:team]
end
end end

View file

@ -3,7 +3,7 @@
<div class="ga-breadcrumb"> <div class="ga-breadcrumb">
<span class="fas fa-clipboard-check"></span> <span class="fas fa-clipboard-check"></span>
<% if subject %> <% if subject %>
<%= route_to_other_team(reports_path(subject), <%= route_to_other_team(reports_path(subject, team: subject.team.id),
team, team,
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH), subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
title: subject.name) %> title: subject.name) %>

View file

@ -3,7 +3,7 @@
<div class="ga-breadcrumb"> <div class="ga-breadcrumb">
<span class="fas fa-list-alt"></span> <span class="fas fa-list-alt"></span>
<% if subject %> <% if subject %>
<%= route_to_other_team(repository_path(subject.id), <%= route_to_other_team(repository_path(subject.id, team: subject.team.id),
team, team,
subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH), subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH),
title: subject.name) %> title: subject.name) %>

View file

@ -45,9 +45,9 @@ en:
add_comment_to_project_html: "%{user} commented on project %{project}." add_comment_to_project_html: "%{user} commented on project %{project}."
edit_project_comment_html: "%{user} edited comment on project %{project}." edit_project_comment_html: "%{user} edited comment on project %{project}."
delete_project_comment_html: "%{user} deleted comment on project %{project}." delete_project_comment_html: "%{user} deleted comment on project %{project}."
create_report_html: "%{user} created report <strong>%{report}</strong>." create_report_html: "%{user} created report %{report}."
edit_report_html: "%{user} edited report <strong>%{report}</strong>." edit_report_html: "%{user} edited report %{report}."
delete_report_html: "%{user} deleted report <strong>%{report}</strong>." delete_report_html: "%{user} deleted report %{report}."
add_result_html: "%{user} added %{type_of_result} result %{result}." add_result_html: "%{user} added %{type_of_result} result %{result}."
edit_result_html: "%{user} edited %{type_of_result} result %{result}." edit_result_html: "%{user} edited %{type_of_result} result %{result}."
add_comment_to_result_html: "%{user} commented on result %{result}." add_comment_to_result_html: "%{user} commented on result %{result}."