From 38c198705c886bb8c4128fdf07ca0fc3ca3bfeef Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Thu, 23 Apr 2020 12:40:43 +0200 Subject: [PATCH 1/2] Change current_team to target team, add id param to link --- app/controllers/users/invitations_controller.rb | 6 +++--- app/helpers/global_activities_helper.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/users/invitations_controller.rb b/app/controllers/users/invitations_controller.rb index 259dd2ce3..44042ac48 100644 --- a/app/controllers/users/invitations_controller.rb +++ b/app/controllers/users/invitations_controller.rb @@ -122,10 +122,10 @@ module Users Activities::CreateActivityService .call(activity_type: :invite_user_to_team, owner: current_user, - subject: current_team, - team: current_team, + subject: @team, + team: @team, message_items: { - team: current_team.id, + team: @team.id, user_invited: user.id, role: user_team.role_str }) diff --git a/app/helpers/global_activities_helper.rb b/app/helpers/global_activities_helper.rb index decc6a13c..46762a846 100644 --- a/app/helpers/global_activities_helper.rb +++ b/app/helpers/global_activities_helper.rb @@ -42,7 +42,7 @@ module GlobalActivitiesHelper # Not link for now return current_value when Team - path = projects_path + path = projects_path(team: obj.id) when Repository path = repository_path(obj) when RepositoryRow From de4e4ca967e940fc5addb5cc8564e07b3a048073 Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Thu, 23 Apr 2020 16:02:36 +0200 Subject: [PATCH 2/2] Add before_action for team switch --- app/controllers/protocols_controller.rb | 1 + app/controllers/reports_controller.rb | 1 + app/controllers/repositories_controller.rb | 2 ++ app/helpers/global_activities_helper.rb | 14 +++++++------- app/helpers/teams_helper.rb | 4 ++++ .../global_activities/references/_report.html.erb | 2 +- .../references/_repository.html.erb | 2 +- config/locales/global_activities/en.yml | 6 +++--- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 7bd814a51..fcd326646 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -23,6 +23,7 @@ class ProtocolsController < ApplicationController linked_children linked_children_datatable ) + before_action :switch_team_with_param, only: :index before_action :check_view_all_permissions, only: %i( index datatable diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 6658c8aba..9a372166b 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -31,6 +31,7 @@ class ReportsController < ApplicationController only: %i(new edit available_repositories) 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 def index; end diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 943737507..3c7fbfc16 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -5,7 +5,9 @@ class RepositoriesController < ApplicationController include ActionView::Helpers::TagHelper include ActionView::Context include IconsHelper + include TeamsHelper + before_action :switch_team_with_param, only: :show before_action :load_vars, except: %i(index create create_modal parse_sheet) before_action :load_parent_vars, except: diff --git a/app/helpers/global_activities_helper.rb b/app/helpers/global_activities_helper.rb index 46762a846..42d8dee4f 100644 --- a/app/helpers/global_activities_helper.rb +++ b/app/helpers/global_activities_helper.rb @@ -44,15 +44,15 @@ module GlobalActivitiesHelper when Team path = projects_path(team: obj.id) when Repository - path = repository_path(obj) + path = repository_path(obj, team: obj.team.id) when RepositoryRow return current_value unless obj.repository - path = repository_path(obj.repository) + path = repository_path(obj.repository, team: obj.repository.team.id) when RepositoryColumn return current_value unless obj.repository - path = repository_path(obj.repository) + path = repository_path(obj.repository, team: obj.repository.team.id) when Project path = obj.archived? ? projects_path : project_path(obj) when Experiment @@ -73,11 +73,11 @@ module GlobalActivitiesHelper end when Protocol if obj.in_repository_public? - path = protocols_path(type: :public) + path = protocols_path(type: :public, team: obj.team.id) elsif obj.in_repository_private? - path = protocols_path(type: :private) + path = protocols_path(type: :private, team: obj.team.id) elsif obj.in_repository_archived? - path = protocols_path(type: :archive) + path = protocols_path(type: :archive, team: obj.team.id) elsif obj.my_module.navigable? path = protocols_my_module_path(obj.my_module) else @@ -90,7 +90,7 @@ module GlobalActivitiesHelper when Step return current_value when Report - path = reports_path + path = reports_path(team: obj.team.id) else return current_value end diff --git a/app/helpers/teams_helper.rb b/app/helpers/teams_helper.rb index 7fa0070a8..9c5d116bb 100644 --- a/app/helpers/teams_helper.rb +++ b/app/helpers/teams_helper.rb @@ -20,4 +20,8 @@ module TeamsHelper 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] + end end diff --git a/app/views/global_activities/references/_report.html.erb b/app/views/global_activities/references/_report.html.erb index ede016a46..0abdcf90c 100644 --- a/app/views/global_activities/references/_report.html.erb +++ b/app/views/global_activities/references/_report.html.erb @@ -3,7 +3,7 @@
<% if subject %> - <%= route_to_other_team(reports_path(subject), + <%= route_to_other_team(reports_path(subject, team: subject.team.id), team, subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH), title: subject.name) %> diff --git a/app/views/global_activities/references/_repository.html.erb b/app/views/global_activities/references/_repository.html.erb index 13580ce4d..8c43fab04 100644 --- a/app/views/global_activities/references/_repository.html.erb +++ b/app/views/global_activities/references/_repository.html.erb @@ -3,7 +3,7 @@
<% if subject %> - <%= route_to_other_team(repository_path(subject.id), + <%= route_to_other_team(repository_path(subject.id, team: subject.team.id), team, subject.name&.truncate(Constants::NAME_TRUNCATION_LENGTH), title: subject.name) %> diff --git a/config/locales/global_activities/en.yml b/config/locales/global_activities/en.yml index 818a96bd1..bb8eb10ac 100644 --- a/config/locales/global_activities/en.yml +++ b/config/locales/global_activities/en.yml @@ -45,9 +45,9 @@ en: add_comment_to_project_html: "%{user} commented on project %{project}." edit_project_comment_html: "%{user} edited comment on project %{project}." delete_project_comment_html: "%{user} deleted comment on project %{project}." - create_report_html: "%{user} created report %{report}." - edit_report_html: "%{user} edited report %{report}." - delete_report_html: "%{user} deleted report %{report}." + create_report_html: "%{user} created report %{report}." + edit_report_html: "%{user} edited report %{report}." + delete_report_html: "%{user} deleted report %{report}." add_result_html: "%{user} added %{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}."