Display all protocol templates for team admin [SCI-8379] (#5391)

This commit is contained in:
ajugo 2023-05-16 10:29:00 +02:00 committed by GitHub
parent d8945cc627
commit c6f5219043
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 17 deletions

View file

@ -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;

View file

@ -151,6 +151,10 @@
border: 2px solid $color-concrete;
}
}
.not-clickable-record {
color: $color-alto;
}
}
.protocol-filters {

View file

@ -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

View file

@ -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
"<a href='#{path}'>#{escape_input(record.name)}</a>"
if can_read_protocol_in_repository?(@user, record)
"<a href='#{path}'>#{escape_input(record.name)}</a>"
else
# team admin can only see recod name
"<span class='not-clickable-record'>#{escape_input(record.name)}</span>"
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)

View file

@ -1,5 +1,5 @@
<template id="protocolActionToolbar">
<button id="protocolVersions" class="btn btn-light single-object-action hidden only-active">
<button id="protocolVersions" class="btn btn-light single-object-action hidden only-active" data-for="readable">
<%= image_tag 'icon/versions.svg' %>
<span class="button-text"><%= t("protocols.index.action_toolbar.versions") %></span>
</button>
@ -11,7 +11,7 @@
<i class="fas fa-copy"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.duplicate") %></span>
</button>
<button id="exportProtocol" class="btn btn-light single-object-action hidden only-active" data-url="<%= export_protocols_path %>">
<button id="exportProtocol" class="btn btn-light single-object-action hidden only-active" data-url="<%= export_protocols_path %>" data-for="readable">
<i class="fas fa-download"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.export") %></span>
</button>

View file

@ -1,16 +1,29 @@
<% if protocol.in_repository_published_original? || protocol.in_repository_published_version? %>
<% parent = protocol.parent || protocol %>
<% parent = protocol.parent || protocol %>
<% if readable %>
<%= link_to versions_modal_protocol_path(parent), class: 'protocol-versions-link', remote: true do %>
<%= protocol.nr_of_versions %>
<%= protocol.nr_of_versions %>
<% end %>
<% if parent.draft.present? %>
/
<%= link_to protocol_path(parent.draft) do %>
<%= t("protocols.index.table.draft") %>
<% end %>
<% end %>
<% elsif protocol.in_repository_draft? %>
<%= link_to protocol_path(protocol) do %>
<% else %>
<span class="not-clickable-record"><%= protocol.nr_of_versions %></span>
<% end %>
<% if parent.draft.present? %>
<% if readable %>
/
<%= link_to protocol_path(parent.draft) do %>
<%= t("protocols.index.table.draft") %>
<% end %>
<% else %>
<span class="not-clickable-record">/</span>
<span class="not-clickable-record"><%= t("protocols.index.table.draft") %></span>
<% end %>
<% end %>
<% elsif protocol.in_repository_draft? %>
<% if readable %>
<%= link_to protocol_path(protocol) do %>
<%= t("protocols.index.table.draft") %>
<% end %>
<% else %>
<span class="not-clickable-record"><%= t("protocols.index.table.draft") %></span>
<% end %>
<% end %>