From 553c6448111b5b351ca9d88eb1ded3fa8d7302f2 Mon Sep 17 00:00:00 2001 From: Giga Chubinidze Date: Wed, 8 Mar 2023 21:12:29 +0400 Subject: [PATCH] Protocol permissions - button display [SCI-8058] --- .../vue/protocol/protocolMetadata.vue | 3 +- app/permissions/team.rb | 6 ++-- app/serializers/protocol_serializer.rb | 10 +++++- .../protocols/index/_general_toolbar.html.erb | 36 +++++++++---------- .../index/_protocol_versions_modal.html.erb | 2 +- .../extends/permission_extends.rb | 3 ++ 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/app/javascript/vue/protocol/protocolMetadata.vue b/app/javascript/vue/protocol/protocolMetadata.vue index 6007cecd4..71c2ebf83 100644 --- a/app/javascript/vue/protocol/protocolMetadata.vue +++ b/app/javascript/vue/protocol/protocolMetadata.vue @@ -17,8 +17,9 @@ - + +
diff --git a/app/permissions/team.rb b/app/permissions/team.rb index b827d96e8..1e9733027 100644 --- a/app/permissions/team.rb +++ b/app/permissions/team.rb @@ -105,11 +105,11 @@ Canaid::Permissions.register_for(Protocol) do # protocol in repository: restore can :restore_protocol_in_repository do |user, protocol| - protocol.archived? && protocol.permission_granted?(user, ProtocolPermissions::MANAGE) + protocol.archived? && protocol.permission_granted?(user, ProtocolPermissions::RESTORE) end can :archive_protocol_in_repository do |user, protocol| - protocol.active? && protocol.permission_granted?(user, ProtocolPermissions::MANAGE) + protocol.active? && protocol.permission_granted?(user, ProtocolPermissions::ARCHIVE) end # protocol in repository: copy @@ -119,7 +119,7 @@ Canaid::Permissions.register_for(Protocol) do can :publish_protocol_in_repository do |user, protocol| protocol.in_repository_draft? && - protocol.permission_granted?(user, ProtocolPermissions::MANAGE) + protocol.permission_granted?(user, ProtocolPermissions::PUBLISH) end can :delete_protocol_draft_in_repository do |user, protocol| diff --git a/app/serializers/protocol_serializer.rb b/app/serializers/protocol_serializer.rb index 9d36c3e46..2fc5c9761 100644 --- a/app/serializers/protocol_serializer.rb +++ b/app/serializers/protocol_serializer.rb @@ -8,7 +8,7 @@ class ProtocolSerializer < ActiveModel::Serializer attributes :name, :id, :urls, :description, :description_view, :updated_at, :in_repository, :created_at_formatted, :updated_at_formatted, :added_by, :authors, :keywords, :version, :code, - :published, :version_comment + :published, :version_comment, :disabled_drafting def updated_at object.updated_at.to_i @@ -83,6 +83,14 @@ class ProtocolSerializer < ActiveModel::Serializer !object.in_module? end + def disabled_drafting + protocol_types = Protocol.where(name: object.name).pluck(:protocol_type) + object.protocol_type != 'in_repository_draft' && + !object.archived && + protocol_types.length > 1 && + protocol_types.include?('in_repository_draft') + end + private def load_from_repo_url diff --git a/app/views/protocols/index/_general_toolbar.html.erb b/app/views/protocols/index/_general_toolbar.html.erb index 6fada076b..d5163c840 100644 --- a/app/views/protocols/index/_general_toolbar.html.erb +++ b/app/views/protocols/index/_general_toolbar.html.erb @@ -1,25 +1,25 @@ diff --git a/app/views/protocols/index/_protocol_versions_modal.html.erb b/app/views/protocols/index/_protocol_versions_modal.html.erb index aef8738c8..7ef19f6f8 100644 --- a/app/views/protocols/index/_protocol_versions_modal.html.erb +++ b/app/views/protocols/index/_protocol_versions_modal.html.erb @@ -56,7 +56,7 @@ >
<%= draft.version_comment %>
- <%= text_area_tag 'version_comment', draft.version_comment, disabled: true, class: 'smart-text-area hidden' %> + <%= text_area_tag 'version_comment', draft.version_comment, disabled: can_publish_protocol_in_repository?(@protocol), class: 'smart-text-area hidden' %>
<%= t('general.cancel') %> diff --git a/config/initializers/extends/permission_extends.rb b/config/initializers/extends/permission_extends.rb index 943755476..f21c26707 100644 --- a/config/initializers/extends/permission_extends.rb +++ b/config/initializers/extends/permission_extends.rb @@ -19,6 +19,9 @@ module PermissionExtends %w( READ READ_ARCHIVED + ARCHIVE + RESTORE + PUBLISH MANAGE USERS_MANAGE MANAGE_DRAFT