Fix protocol linked protocol changes tracking [SCI-6986]

This commit is contained in:
Oleksii Kriuchykhin 2022-08-09 14:15:49 +02:00
parent 1ee091aa53
commit d1a46b3fc2
12 changed files with 20 additions and 12 deletions

View file

@ -15,6 +15,7 @@ module Api
@protocol.steps.find(order['id']).update_column(:position, order['position'])
# rubocop:enable Rails/SkipsModelValidations
end
@protocol.touch
rescue StandardError
head :bad_request
end

View file

@ -14,6 +14,7 @@ module Api
@step.step_orderable_elements.find(order['id']).update_column(:position, order['position'])
# rubocop:enable Rails/SkipsModelValidations
end
@step.touch
rescue StandardError
head :bad_request
end

View file

@ -93,10 +93,11 @@ module StepElements
end
def reorder
ActiveRecord::Base.transaction do
@checklist.with_lock do
params[:checklist_item_positions].each do |id, position|
@checklist.checklist_items.find(id).update_column(:position, position)
end
@checklist.touch
end
render json: params[:checklist_item_positions], status: :ok

View file

@ -5,7 +5,7 @@ class StepOrderableElementsController < ApplicationController
before_action :check_manage_permissions
def reorder
ActiveRecord::Base.transaction do
@step.with_lock do
params[:step_orderable_element_positions].each do |id, position|
@step.step_orderable_elements.find(id).update_column(:position, position)
end
@ -15,6 +15,7 @@ class StepOrderableElementsController < ApplicationController
else
log_activity(:protocol_step_content_rearranged, nil, protocol: @protocol.id)
end
@step.touch
end
render json: params[:step_orderable_element_positions], status: :ok

View file

@ -458,7 +458,7 @@ class StepsController < ApplicationController
end
def reorder
ActiveRecord::Base.transaction do
@protocol.with_lock do
params[:step_positions].each do |id, position|
@protocol.steps.find(id).update_column(:position, position)
end
@ -468,6 +468,7 @@ class StepsController < ApplicationController
else
log_activity(:protocol_steps_rearranged, nil, protocol: @protocol.id)
end
@protocol.touch
end
render json: {

View file

@ -267,10 +267,9 @@
data: JSON.stringify(stepPositions),
contentType: "application/json",
dataType: "json",
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger'))
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger')),
success: (() => this.reorderSteps(this.steps))
});
this.reorderSteps(this.steps);
},
startStepReorder() {
this.reordering = true;

View file

@ -369,7 +369,8 @@
data: JSON.stringify(elementPositions),
contentType: "application/json",
dataType: "json",
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger'))
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger')),
success: (() => this.$emit('stepUpdated'))
});
this.reorderElements(this.elements);

View file

@ -231,7 +231,8 @@
data: JSON.stringify(checklistItemPositions),
contentType: "application/json",
dataType: "json",
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger'))
error: (() => HelperModule.flashAlertMsg(this.i18n.t('errors.general'), 'danger')),
success: (() => this.update())
});
},
handleMultilinePaste(data) {

View file

@ -8,7 +8,8 @@ class ChecklistItem < ApplicationRecord
validates :position, uniqueness: { scope: :checklist }, unless: -> { position.nil? }
belongs_to :checklist,
inverse_of: :checklist_items
inverse_of: :checklist_items,
touch: true
belongs_to :created_by,
foreign_key: 'created_by_id',
class_name: 'User',

View file

@ -49,9 +49,10 @@ class Comment < ApplicationRecord
end
end
def self.mark_as_seen_by(user)
def self.mark_as_seen_by(user, commentable)
# rubocop:disable Rails/SkipsModelValidations
all.where('? = ANY (unseen_by)', user.id).update_all("unseen_by = array_remove(unseen_by, #{user.id.to_i}::bigint)")
commentable.touch
# rubocop:enable Rails/SkipsModelValidations
end
end

View file

@ -12,7 +12,7 @@
<% end %>
<div class="comments-list">
<%= render partial: 'shared/comments/list.html.erb', locals: { comments: comments} %>
<% comments.mark_as_seen_by(current_user) %>
<% comments.mark_as_seen_by(current_user, object) %>
</div>
</div>
<% if can_create_comments %>

View file

@ -4,4 +4,4 @@
locals: { comment: comment, skip_header: user == comment.user } %>
<% user = comment.user %>
<% end %>
<% comments.mark_as_seen_by(current_user) && @commentable.touch %>
<% comments.mark_as_seen_by(current_user, @commentable) %>