Fix task archiving permissions, archived labels in breadcrumbs [SCI-8586] (#5535)

This commit is contained in:
Alex Kriuchykhin 2023-06-01 11:31:54 +02:00 committed by GitHub
parent 26e4064ac9
commit d4fb499a17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 25 deletions

View file

@ -15,7 +15,8 @@ module Breadcrumbs
@breadcrumbs_items.push({
label: t('projects.index.breadcrumbs_root'),
url: projects_path(view_mode: project&.archived? ? :archived : :active)
url: projects_path(view_mode: project&.archived? ? :archived : :active),
archived: project&.archived? || (!project && params[:view_mode] == 'archived')
})
folders&.each do |project_folder|
@ -31,12 +32,8 @@ module Breadcrumbs
include_my_module(my_module) if my_module
archived_exists = @breadcrumbs_items.any? { |item| item[:archived] == true }
if params[:view_mode] == 'archived' || archived_exists
@breadcrumbs_items.each do |item|
item[:label] = "(A) #{item[:label]}"
end
@breadcrumbs_items.each do |item|
item[:label] = "(A) #{item[:label]}" if item[:archived]
end
@breadcrumbs_items
end
@ -47,7 +44,7 @@ module Breadcrumbs
def include_project(project)
@breadcrumbs_items.push({
label: project.name,
url: project_path(project),
url: project_path(view_mode: project.archived? ? :archived : :active),
archived: project.archived?
})
end
@ -56,7 +53,7 @@ module Breadcrumbs
@breadcrumbs_items.push({
label: experiment.name,
url: my_modules_experiment_path(experiment),
archived: experiment.archived?
archived: experiment.archived_branch?
})
end
@ -64,7 +61,7 @@ module Breadcrumbs
@breadcrumbs_items.push({
label: my_module.name,
url: my_module_path(my_module),
archived: my_module.archived?
archived: my_module.archived_branch?
})
end
end

View file

@ -1163,7 +1163,8 @@ class ProtocolsController < ApplicationController
@breadcrumbs_items.push({
label: t('breadcrumbs.protocols'),
url: protocols_path
url: protocols_path,
archived: params[:type] == 'archived' || @protocol&.archived?
})
if @protocol
@ -1174,12 +1175,8 @@ class ProtocolsController < ApplicationController
})
end
archived_exists = @breadcrumbs_items.any? { |item| item[:archived] == true }
if params[:type] == 'archived' || archived_exists
@breadcrumbs_items.each do |item|
item[:label] = "(A) #{item[:label]}"
end
@breadcrumbs_items.each do |item|
item[:label] = "(A) #{item[:label]}" if item[:archived]
end
end
end

View file

@ -544,7 +544,8 @@ class RepositoriesController < ApplicationController
@breadcrumbs_items.push({
label: t('breadcrumbs.inventories'),
url: repositories_path
url: repositories_path,
archived: params[:archived] == 'true' || @repository&.archived?
})
if @repository
@ -555,12 +556,8 @@ class RepositoriesController < ApplicationController
})
end
archived_exists = @breadcrumbs_items.any? { |item| item[:archived] == true }
if params[:archived] == 'true' || archived_exists
@breadcrumbs_items.each do |item|
item[:label] = "(A) #{item[:label]}"
end
@breadcrumbs_items.each do |item|
item[:label] = "(A) #{item[:label]}" if item[:archived]
end
end
end

View file

@ -4,6 +4,7 @@ Canaid::Permissions.register_for(MyModule) do
# Module, its experiment and its project must be active for all the specified
# permissions
%i(manage_my_module
archive_my_module
manage_my_module_protocol
manage_my_module_users
manage_my_module_designated_users
@ -48,7 +49,7 @@ Canaid::Permissions.register_for(MyModule) do
end
can :archive_my_module do |user, my_module|
!my_module.archived? && my_module.permission_granted?(user, MyModulePermissions::MANAGE)
my_module.permission_granted?(user, MyModulePermissions::MANAGE)
end
can :move_my_module do |user, my_module|