mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-14 17:14:54 +08:00
Fix access modal for protocol [SCI-8063] (#5128)
This commit is contained in:
parent
917269a8e9
commit
9a3b056d32
4 changed files with 26 additions and 41 deletions
|
@ -144,28 +144,9 @@ var ProtocolsIndex = (function() {
|
|||
|
||||
function initManageAccess() {
|
||||
let protocolsContainer = '.protocols-container';
|
||||
let manageAccessModal = '.protocol-assignments-modal';
|
||||
|
||||
function loadManageAccessModal(href) {
|
||||
$.get(href, function(data) {
|
||||
$(protocolsContainer).append($.parseHTML(data.html));
|
||||
$(manageAccessModal).modal('show');
|
||||
|
||||
// Remove modal when it gets closed
|
||||
$(manageAccessModal).on('hidden.bs.modal', function() {
|
||||
$(manageAccessModal).remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protocolsTableEl.on('click', '.protocol-users-link', function(e) {
|
||||
loadManageAccessModal(this.href);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$(protocolsContainer).on('click', '#manageProtocolAccess', function() {
|
||||
loadManageAccessModal($(`tr[data-row-id=${rowsSelected[0]}] .protocol-users-link`).attr('href'));
|
||||
$(`tr[data-row-id=${rowsSelected[0]}] .protocol-users-link`).click();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ module AccessPermissions
|
|||
next unless user_assignment_params[:assign] == '1'
|
||||
|
||||
if user_assignment_params[:user_id] == 'all'
|
||||
@protocol.update!(visibility: :visible, default_public_user_role_id: user_assignment_params[:user_role_id])
|
||||
@protocol.update!(default_public_user_role_id: user_assignment_params[:user_role_id])
|
||||
else
|
||||
user_assignment = UserAssignment.find_or_initialize_by(
|
||||
assignable: @protocol,
|
||||
|
@ -87,31 +87,28 @@ module AccessPermissions
|
|||
def destroy
|
||||
user = @protocol.assigned_users.find(params[:user_id])
|
||||
user_assignment = @protocol.user_assignments.find_by(user: user, team: current_team)
|
||||
respond_to do |format|
|
||||
if user_assignment.destroy
|
||||
|
||||
log_activity(:protocol_template_access_revoked, user_assignment)
|
||||
format.json do
|
||||
render json: { flash: t('access_permissions.destroy.success', member_name: user.full_name) },
|
||||
status: :ok
|
||||
end
|
||||
Protocol.transaction do
|
||||
if @protocol.visible?
|
||||
user_assignment.update!(
|
||||
user_role: @protocol.default_public_user_role,
|
||||
assigned: :automatically
|
||||
)
|
||||
else
|
||||
format.json do
|
||||
render json: { flash: t('access_permissions.destroy.failure') },
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
user_assignment.destroy!
|
||||
end
|
||||
log_activity(:protocol_template_access_revoked, user_assignment)
|
||||
end
|
||||
|
||||
render json: { flash: t('access_permissions.destroy.success', member_name: user.full_name) }
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
Rails.logger.error e.message
|
||||
render json: { flash: t('access_permissions.destroy.failure') }, status: :unprocessable_entity
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
||||
def update_default_public_user_role
|
||||
Protocol.transaction do
|
||||
@protocol.visibility = :hidden if permitted_default_public_user_role_params[:default_public_user_role_id].blank?
|
||||
@protocol.assign_attributes(permitted_default_public_user_role_params)
|
||||
@protocol.save!
|
||||
|
||||
UserAssignments::ProtocolGroupAssignmentJob.perform_later(current_team, @protocol, current_user)
|
||||
end
|
||||
@protocol.update!(permitted_default_public_user_role_params)
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -134,6 +131,8 @@ module AccessPermissions
|
|||
@protocol = current_team.protocols.includes(user_assignments: %i(user user_role)).find_by(id: params[:id])
|
||||
|
||||
render_404 unless @protocol
|
||||
|
||||
@protocol = @protocol.parent if @protocol.parent_id
|
||||
end
|
||||
|
||||
def check_manage_permissions
|
||||
|
|
|
@ -21,7 +21,8 @@ class Protocol < ApplicationRecord
|
|||
after_save :update_user_assignments, if: -> { saved_change_to_visibility? && in_repository? }
|
||||
after_save :update_linked_children
|
||||
skip_callback :create, :after, :create_users_assignments, if: -> { in_module? }
|
||||
before_update :sync_protocol_assignments, if: :visibility_changed?
|
||||
before_update :change_visibility, if: :default_public_user_role_id_changed?
|
||||
after_update :sync_protocol_assignments, if: :visibility_changed?
|
||||
|
||||
enum visibility: { hidden: 0, visible: 1 }
|
||||
enum protocol_type: {
|
||||
|
@ -803,6 +804,10 @@ class Protocol < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def change_visibility
|
||||
self.visibility = default_public_user_role_id.present? ? :visible : :hidden
|
||||
end
|
||||
|
||||
def sync_protocol_assignments
|
||||
if visible?
|
||||
auto_assign_protocol_members
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<% if assignable.top_level_assignable? %>
|
||||
<li role="separator" class="divider" data-hook="support-dropdown-separator"></li>
|
||||
<li>
|
||||
<a href="#" data-turbolinks="false" class="user-role-selector" data-role-id="">
|
||||
<a href="#" data-turbolinks="false" class="user-role-selector" data-role-id="" data-action='remote-destroy' data-target="#">
|
||||
<%= t('access_permissions.remove_access') %>
|
||||
</a>
|
||||
</li>
|
||||
|
|
Loading…
Add table
Reference in a new issue