From 3a8fc01ff72c176b88b150c77f1e359aececaa8b Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Wed, 5 Aug 2020 15:43:43 +0200 Subject: [PATCH 1/6] Fix inventory card view for snapshots as default view --- app/controllers/repository_rows_controller.rb | 13 ++- .../_repository_row_info_modal.html.erb | 98 +++++++++---------- 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index d7242864e..6289696f9 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -4,9 +4,9 @@ class RepositoryRowsController < ApplicationController include ApplicationHelper include MyModulesHelper - before_action :load_repository - before_action :load_repository_row, only: %i(update show assigned_task_list) - before_action :check_read_permissions, except: %i(create update delete_records copy_records) + before_action :load_repository, except: :show + before_action :load_repository_row, only: %i(update assigned_task_list) + before_action :check_read_permissions, except: %i(show create update delete_records copy_records) before_action :check_snapshotting_status, only: %i(create update delete_records copy_records) before_action :check_create_permissions, only: :create before_action :check_delete_permissions, only: %i(delete_records archive_records restore_records) @@ -51,7 +51,12 @@ class RepositoryRowsController < ApplicationController end def show - @assigned_modules = @repository_row.my_modules.joins(experiment: :project) + @repository_row = RepositoryRow.find_by(id: params[:id]) + render_403 unless can_read_repository?(@repository_row.repository) + + row = RepositoryRow.find_by(id: @repository_row.parent_id) if @repository_row.parent_id + row ||= @repository_row + @assigned_modules = row.my_modules.joins(experiment: :project) @viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams) @private_modules = @assigned_modules - @viewable_modules diff --git a/app/views/repositories/_repository_row_info_modal.html.erb b/app/views/repositories/_repository_row_info_modal.html.erb index ce9ed0173..cd773eaef 100644 --- a/app/views/repositories/_repository_row_info_modal.html.erb +++ b/app/views/repositories/_repository_row_info_modal.html.erb @@ -39,58 +39,56 @@ <% end %>

- <% if @repository_row.repository.is_a?(Repository) %> - <% if @assigned_modules.size.positive? %> -
- <%= t('repository_row.modal_info.title', nr: @assigned_modules.size) %> - <%= t('repository_row.modal_info.private_tasks', nr: @private_modules.size) if @private_modules.size.positive? %> -
- <% if @viewable_modules.size.positive? %> -
- - - <% @viewable_modules.each do |my_module| %> - - - - <% end %> - - - - + <% if @assigned_modules.size.positive? %> +
+ <%= t('repository_row.modal_info.title', nr: @assigned_modules.size) %> + <%= t('repository_row.modal_info.private_tasks', nr: @private_modules.size) if @private_modules.size.positive? %> +
+ <% if @viewable_modules.size.positive? %> +
+
+ + <% @viewable_modules.each do |my_module| %> + + - - -
- <% end %> - <% else %> - <%= t('repository_row.modal_info.no_tasks') %> + <% end %> + + + + + + + + <% end %> + <% else %> + <%= t('repository_row.modal_info.no_tasks') %> <% end %> From 04c294adb1677c3fb324f9c37a31ec6859f84bf1 Mon Sep 17 00:00:00 2001 From: Miha Mencin Date: Thu, 6 Aug 2020 13:23:40 +0200 Subject: [PATCH 2/6] Fix the failing test: repository row should be in correct repository --- app/controllers/repository_rows_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 6289696f9..a2dfeb280 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -53,10 +53,9 @@ class RepositoryRowsController < ApplicationController def show @repository_row = RepositoryRow.find_by(id: params[:id]) render_403 unless can_read_repository?(@repository_row.repository) - - row = RepositoryRow.find_by(id: @repository_row.parent_id) if @repository_row.parent_id - row ||= @repository_row - @assigned_modules = row.my_modules.joins(experiment: :project) + render_403 unless @repository_row.repository_id == params[:repository_id] + + @assigned_modules = @repository_row.my_modules.joins(experiment: :project) @viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams) @private_modules = @assigned_modules - @viewable_modules From ae013b6fa8c5ede01d3a52215c5060b91decb75f Mon Sep 17 00:00:00 2001 From: Miha Mencin Date: Thu, 6 Aug 2020 14:06:23 +0200 Subject: [PATCH 3/6] join two renders --- app/controllers/repository_rows_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index a2dfeb280..688fdea53 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -52,8 +52,7 @@ class RepositoryRowsController < ApplicationController def show @repository_row = RepositoryRow.find_by(id: params[:id]) - render_403 unless can_read_repository?(@repository_row.repository) - render_403 unless @repository_row.repository_id == params[:repository_id] + render_403 if !can_read_repository?(@repository_row.repository) || @repository_row.repository_id != params[:repository_id] @assigned_modules = @repository_row.my_modules.joins(experiment: :project) @viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams) From 94e6b554f1d3b119819de734af52a18b4ed7384a Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Mon, 10 Aug 2020 17:29:29 +0200 Subject: [PATCH 4/6] Revert back the view --- .../_repository_row_info_modal.html.erb | 98 ++++++++++--------- 1 file changed, 50 insertions(+), 48 deletions(-) diff --git a/app/views/repositories/_repository_row_info_modal.html.erb b/app/views/repositories/_repository_row_info_modal.html.erb index cd773eaef..ce9ed0173 100644 --- a/app/views/repositories/_repository_row_info_modal.html.erb +++ b/app/views/repositories/_repository_row_info_modal.html.erb @@ -39,56 +39,58 @@ <% end %>

- <% if @assigned_modules.size.positive? %> -
- <%= t('repository_row.modal_info.title', nr: @assigned_modules.size) %> - <%= t('repository_row.modal_info.private_tasks', nr: @private_modules.size) if @private_modules.size.positive? %> -
- <% if @viewable_modules.size.positive? %> -
- - - <% @viewable_modules.each do |my_module| %> - - + <% if @repository_row.repository.is_a?(Repository) %> + <% if @assigned_modules.size.positive? %> +
+ <%= t('repository_row.modal_info.title', nr: @assigned_modules.size) %> + <%= t('repository_row.modal_info.private_tasks', nr: @private_modules.size) if @private_modules.size.positive? %> +
+ <% if @viewable_modules.size.positive? %> +
+
+ + <% @viewable_modules.each do |my_module| %> + + + + <% end %> + + + + - <% end %> - - - - - - - -
+ + + + <% end %> + <% else %> + <%= t('repository_row.modal_info.no_tasks') %> <% end %> - <% else %> - <%= t('repository_row.modal_info.no_tasks') %> <% end %> From 7af9c387cf5f63b303616db8da52ee85de3e0fb0 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Tue, 11 Aug 2020 10:27:23 +0200 Subject: [PATCH 5/6] Fix errors --- app/controllers/repository_rows_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 688fdea53..23e920e6e 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -52,8 +52,10 @@ class RepositoryRowsController < ApplicationController def show @repository_row = RepositoryRow.find_by(id: params[:id]) - render_403 if !can_read_repository?(@repository_row.repository) || @repository_row.repository_id != params[:repository_id] - + if !can_read_repository?(@repository_row.repository) || @repository_row.repository_id != params[:repository_id].to_i + return render_403 + end + @assigned_modules = @repository_row.my_modules.joins(experiment: :project) @viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams) @private_modules = @assigned_modules - @viewable_modules From 5d15e738661944cd5070b4a8cc4f15c1508b2e95 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Tue, 11 Aug 2020 13:33:44 +0200 Subject: [PATCH 6/6] Fix failing tests --- app/controllers/repository_rows_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/repository_rows_controller.rb b/app/controllers/repository_rows_controller.rb index 23e920e6e..eb969ca80 100644 --- a/app/controllers/repository_rows_controller.rb +++ b/app/controllers/repository_rows_controller.rb @@ -52,9 +52,9 @@ class RepositoryRowsController < ApplicationController def show @repository_row = RepositoryRow.find_by(id: params[:id]) - if !can_read_repository?(@repository_row.repository) || @repository_row.repository_id != params[:repository_id].to_i - return render_403 - end + return render_404 unless @repository_row + return render_404 unless @repository_row.repository_id == params[:repository_id].to_i + return render_403 unless can_read_repository?(@repository_row.repository) @assigned_modules = @repository_row.my_modules.joins(experiment: :project) @viewable_modules = @assigned_modules.viewable_by_user(current_user, current_user.teams)