Protocol permissions - button display [SCI-8058]

This commit is contained in:
Giga Chubinidze 2023-03-14 12:12:54 +04:00
parent 2cef3bde31
commit 67539b15de
11 changed files with 50 additions and 36 deletions

View file

@ -1074,7 +1074,7 @@ class ProtocolsController < ApplicationController
def set_inline_name_editing
return unless @protocol.initial_draft?
return unless can_manage_protocol_in_repository?(@protocol)
return unless can_manage_protocol_draft_in_repository?(@protocol)
@inline_editable_title_config = {
name: 'title',

View file

@ -295,7 +295,7 @@ class StepsController < ApplicationController
end
def check_protocol_manage_permissions
render_403 unless can_manage_protocol_in_module?(@protocol) || can_manage_protocol_in_repository?(@protocol)
render_403 unless can_manage_protocol_in_module?(@protocol) || can_manage_protocol_draft_in_repository?(@protocol)
end
def check_manage_permissions
@ -306,7 +306,7 @@ class StepsController < ApplicationController
if @my_module
render_403 unless can_manage_my_module_steps?(@my_module)
else
render_403 unless can_manage_protocol_in_repository?(@protocol)
render_403 unless can_manage_protocol_draft_in_repository?(@protocol)
end
end

View file

@ -133,7 +133,7 @@ class TinyMceAssetsController < ApplicationController
return render_403 unless can_manage_step?(@assoc.step)
when Protocol
return render_403 unless can_manage_protocol_in_module?(@protocol) ||
can_manage_protocol_in_repository?(@protocol)
can_manage_protocol_draft_in_repository?(@protocol)
when ResultText, MyModule
return render_403 unless can_manage_my_module?(@my_module)
else

View file

@ -19,6 +19,7 @@
<button class="btn btn-light" @click="openVersionsModal">{{ i18n.t("protocols.header.versions") }}</button>
<button v-if="protocol.attributes.urls.publish_url" @click="$emit('publish')" class="btn btn-primary">{{ i18n.t("protocols.header.publish") }}</button>
<button v-if="protocol.attributes.urls.save_as_draft_url" @click="saveAsdraft" class="btn btn-secondary">{{ i18n.t("protocols.header.save_as_draft") }}</button>
<button v-bind:disabled="protocol.attributes.disabled_drafting" v-if="protocol.attributes.disabled_drafting" @click="saveAsdraft" class="btn btn-secondary">{{ i18n.t("protocols.header.save_as_draft") }}</button>
</div>
</div>
<div id="details-container" class="protocol-details collapse in">

View file

@ -5,7 +5,7 @@ Canaid::Permissions.register_for(Step) do
if step.my_module
can_manage_my_module_steps?(user, step.my_module)
else
can_manage_protocol_in_repository?(user, step.protocol)
can_manage_protocol_draft_in_repository?(user, step.protocol)
end
end
end

View file

@ -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, :archived
:published, :version_comment, :archived, :disabled_drafting
def updated_at
object.updated_at.to_i
@ -84,6 +84,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
@ -123,13 +131,13 @@ class ProtocolSerializer < ActiveModel::Serializer
end
def reorder_steps_url
return unless can_manage_protocol_in_module?(object) || can_manage_protocol_in_repository?(object)
return unless can_manage_protocol_in_module?(object) || can_manage_protocol_draft_in_repository?(object)
reorder_protocol_steps_url(protocol_id: object.id)
end
def add_step_url
return unless can_manage_protocol_in_module?(object) || can_manage_protocol_in_repository?(object)
return unless can_manage_protocol_in_module?(object) || can_manage_protocol_draft_in_repository?(object)
protocol_steps_path(protocol_id: object.id)
end
@ -153,7 +161,7 @@ class ProtocolSerializer < ActiveModel::Serializer
end
def update_protocol_name_url
if in_repository && can_manage_protocol_in_repository?(object)
if in_repository && can_manage_protocol_draft_in_repository?(object)
name_protocol_path(object)
elsif can_manage_protocol_in_module?(object)
protocol_my_module_path(object.my_module)
@ -161,7 +169,7 @@ class ProtocolSerializer < ActiveModel::Serializer
end
def update_protocol_description_url
if in_repository && can_manage_protocol_in_repository?(object)
if in_repository && can_manage_protocol_draft_in_repository?(object)
description_protocol_path(object)
elsif can_manage_protocol_in_module?(object)
protocol_my_module_path(object.my_module)
@ -169,15 +177,15 @@ class ProtocolSerializer < ActiveModel::Serializer
end
def update_protocol_authors_url
authors_protocol_path(object) if in_repository && can_manage_protocol_in_repository?(object)
authors_protocol_path(object) if in_repository && can_manage_protocol_draft_in_repository?(object)
end
def update_protocol_keywords_url
keywords_protocol_path(object) if in_repository && can_manage_protocol_in_repository?(object)
keywords_protocol_path(object) if in_repository && can_manage_protocol_draft_in_repository?(object)
end
def delete_steps_url
return unless can_manage_protocol_in_module?(object) || can_manage_protocol_in_repository?(object)
return unless can_manage_protocol_in_module?(object) || can_manage_protocol_draft_in_repository?(object)
delete_steps_protocol_path(object)
end

View file

@ -79,7 +79,7 @@ class StepSerializer < ActiveModel::Serializer
urls_list[:state_url] = toggle_step_state_step_path(object)
end
if can_manage_protocol_in_module?(object.protocol) || can_manage_protocol_in_repository?(object.protocol)
if can_manage_protocol_in_module?(object.protocol) || can_manage_protocol_draft_in_repository?(object.protocol)
urls_list[:duplicate_step_url] = duplicate_step_path(object)
end

View file

@ -1,36 +1,35 @@
<template id="protocolGeneralToolbar">
<div class="left-general-toolbar">
<button data-toggle="modal"
data-target="#newProtocolModal"
<%= 'disabled' if !can_create_protocols_in_repository?(@current_team) %>
class="btn btn-primary only-active"
>
<span class="fas fa-plus"></span>
<span class="hidden-xs"><%= t("protocols.index.create_new") %></span>
</button>
<div id="protocol-import-group" class="sci-btn-group only-active" role="group">
<button class="btn btn-light btn-open-file <%= 'disabled' unless can_create_protocols_in_repository?(@current_team) %>"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">
<span class="fas fa-upload"></span><span class="hidden-xs"><%= t("protocols.index.import") %></span>
<% if can_create_protocols_in_repository?(@current_team) %>
<button data-toggle="modal"
data-target="#newProtocolModal"
class="btn btn-primary only-active"
>
<span class="fas fa-plus"></span>
<span class="hidden-xs"><%= t("protocols.index.create_new") %></span>
</button>
<% if can_create_protocols_in_repository?(@current_team) %>
<div id="protocol-import-group" class="sci-btn-group only-active" role="group">
<button class="btn btn-light btn-open-file"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false">
<span class="fas fa-upload"></span><span class="hidden-xs"><%= t("protocols.index.import") %></span>
</button>
<ul class="dropdown-menu">
<li>
<a class="btn-link-alt btn-default-link btn-open-file" <%= can_create_protocols_in_repository?(@current_team) ? 'data-action="import"' : 'disabled="disabled"' %>>
<span><%= t("protocols.index.import_alt") %></span>
<input type="file" value="" accept=".eln" data-role="import-file-input"
data-team-id="<%= @current_team.id %>" data-import-url="<%= import_protocols_path %>"
<%= 'disabled="disabled"' unless can_create_protocols_in_repository?(@current_team) %>>
data-team-id="<%= @current_team.id %>" data-import-url="<%= import_protocols_path %>">
</a>
</li>
<li class="import-protocols-io">
<%= link_to t("protocols.index.import_protocols_io"), '', data: { target: '#protocolsioModal', toggle: 'modal' } %>
</li>
</ul>
<% end %>
</div>
</div>
<% end %>
</div>
</template>

View file

@ -56,7 +56,7 @@
>
<div class="protocol-comment-message">
<div class="view-mode" data-placeholder="<%= t('protocols.index.versions.comment_placeholder') %>"><%= draft.version_comment %></div>
<%= 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' %>
</div>
<div class="edit-buttons">
<span class="cancel-button btn btn-secondary"><%= t('general.cancel') %></span>

View file

@ -11,7 +11,7 @@
</h4>
</div>
<% if !(preview) && (can_manage_protocol_in_module?(@protocol) ||
can_manage_protocol_in_repository?(@protocol)) %>
can_manage_protocol_draft_in_repository?(@protocol)) %>
<div class="actions">
<div class="dropdown sci-dropdown">
<button class="btn btn-light dropdown-toggle" type="button" id="dropdownAttachmentsOptions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">

View file

@ -9,6 +9,10 @@ class AddProtocolVersioningPermissions < ActiveRecord::Migration[6.1]
ProtocolPermissions::MANAGE_DRAFT
].freeze
REMOVED_NORMAL_USER_PERMISSIONS = [
ProtocolPermissions::MANAGE
].freeze
def change
reversible do |dir|
dir.up do
@ -16,6 +20,7 @@ class AddProtocolVersioningPermissions < ActiveRecord::Migration[6.1]
@normal_user_role = UserRole.find_predefined_normal_user_role
@owner_role.permissions = @owner_role.permissions | OWNER_PERMISSIONS
@normal_user_role.permissions = @normal_user_role.permissions | NORMAL_USER_PERMISSIONS
@normal_user_role.permissions = @normal_user_role.permissions - REMOVED_NORMAL_USER_PERMISSIONS
@owner_role.save(validate: false)
@normal_user_role.save(validate: false)
end
@ -25,6 +30,7 @@ class AddProtocolVersioningPermissions < ActiveRecord::Migration[6.1]
@normal_user_role = UserRole.find_predefined_normal_user_role
@owner_role.permissions = @owner_role.permissions - OWNER_PERMISSIONS
@normal_user_role.permissions = @normal_user_role.permissions - NORMAL_USER_PERMISSIONS
@normal_user_role.permissions = @normal_user_role.permissions | REMOVED_NORMAL_USER_PERMISSIONS
@owner_role.save(validate: false)
@normal_user_role.save(validate: false)
end