From c6f52190436f09d0de9d1e3e1a350dafd9c1c105 Mon Sep 17 00:00:00 2001 From: ajugo Date: Tue, 16 May 2023 10:29:00 +0200 Subject: [PATCH] Display all protocol templates for team admin [SCI-8379] (#5391) --- app/assets/javascripts/protocols/index.js | 2 +- app/assets/stylesheets/protocols/index.scss | 4 +++ app/controllers/protocols_controller.rb | 6 ++-- app/datatables/protocols_datatable.rb | 12 +++++-- .../protocols/index/_action_toolbar.html.erb | 4 +-- .../index/_protocol_versions.html.erb | 33 +++++++++++++------ 6 files changed, 44 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 9a78d5d74..d538b4a4e 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -6,7 +6,7 @@ // Global variables var ProtocolsIndex = (function() { const ALL_VERSIONS_VALUE = 'All'; - var PERMISSIONS = ['archivable', 'restorable', 'copyable']; + var PERMISSIONS = ['archivable', 'restorable', 'copyable', 'readable']; var rowsSelected = []; var protocolsTableEl = null; var protocolsDatatable = null; diff --git a/app/assets/stylesheets/protocols/index.scss b/app/assets/stylesheets/protocols/index.scss index 8ab373011..13a317f2f 100644 --- a/app/assets/stylesheets/protocols/index.scss +++ b/app/assets/stylesheets/protocols/index.scss @@ -151,6 +151,10 @@ border: 2px solid $color-concrete; } } + + .not-clickable-record { + color: $color-alto; + } } .protocol-filters { diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 409ce35f7..cff328d6d 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -915,7 +915,8 @@ class ProtocolsController < ApplicationController render json: { copyable: can_clone_protocol_in_repository?(@protocol), archivable: can_archive_protocol_in_repository?(@protocol), - restorable: can_restore_protocol_in_repository?(@protocol) + restorable: can_restore_protocol_in_repository?(@protocol), + readable: can_read_protocol_in_repository?(@protocol) } end end @@ -984,7 +985,8 @@ class ProtocolsController < ApplicationController current_team_switch(@protocol.team) if current_team != @protocol.team unless @protocol.present? && (can_read_protocol_in_module?(@protocol) || - can_read_protocol_in_repository?(@protocol)) + can_read_protocol_in_repository?(@protocol) || + (@protocol.in_repository? && can_manage_team?(@protocol.team))) render_403 end end diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index e9a3b02e3..0cf418dbf 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -5,6 +5,7 @@ class ProtocolsDatatable < CustomDatatable include ActiveRecord::Sanitization::ClassMethods include InputSanitizeHelper include Rails.application.routes.url_helpers + include Canaid::Helpers::PermissionsHelper PREFIXED_ID_SQL = "('#{Protocol::ID_PREFIX}' || COALESCE(\"protocols\".\"parent_id\", \"protocols\".\"id\"))" @@ -208,7 +209,13 @@ class ProtocolsDatatable < CustomDatatable else protocol_path(record) end - "#{escape_input(record.name)}" + + if can_read_protocol_in_repository?(@user, record) + "#{escape_input(record.name)}" + else + # team admin can only see recod name + "#{escape_input(record.name)}" + end end def keywords_html(record) @@ -233,7 +240,8 @@ class ProtocolsDatatable < CustomDatatable def versions_html(record) @view.controller - .render_to_string(partial: 'protocols/index/protocol_versions.html.erb', locals: { protocol: record }) + .render_to_string(partial: 'protocols/index/protocol_versions.html.erb', + locals: { protocol: record, readable: can_read_protocol_in_repository?(@user, record) }) end def access_html(record) diff --git a/app/views/protocols/index/_action_toolbar.html.erb b/app/views/protocols/index/_action_toolbar.html.erb index b990c8920..d99a83c54 100644 --- a/app/views/protocols/index/_action_toolbar.html.erb +++ b/app/views/protocols/index/_action_toolbar.html.erb @@ -1,5 +1,5 @@