Show error message for protocols templates with same name [SCI-8247] (#5266)

This commit is contained in:
ajugo 2023-04-13 15:34:36 +02:00 committed by GitHub
parent 19c98653a5
commit e85f1f8bbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 53 additions and 34 deletions

View file

@ -1,4 +1,4 @@
/* global HelperModule */
/* global HelperModule I18n */
(function() {
'use strict';
@ -47,6 +47,11 @@
HelperModule.flashAlertMsg(data.flash, 'success');
});
$(document).on('ajax:error', 'form#new-user-assignment-form', function(_e, data) {
HelperModule.flashAlertMsg(data.responseJSON.flash
? data.responseJSON.flash : I18n.t('errors.general'), 'danger');
});
$(document).on('ajax:error', 'form.member-item', function(_e, data) {
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
});

View file

@ -489,12 +489,8 @@ var ProtocolsIndex = (function() {
$.post(url, { protocol_ids: ids }, (data) => {
HelperModule.flashAlertMsg(data.message, 'success');
reloadTable();
}).error((error) => {
if (error.status === 401) {
HelperModule.flashAlertMsg(I18n.t('protocols.index.restore_unauthorized'), 'danger');
} else {
HelperModule.flashAlertMsg(I18n.t('protocols.index.restore_error'), 'danger');
}
}).error((data) => {
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
});
}

View file

@ -98,11 +98,11 @@ module AccessPermissions
end
format.json { render :edit }
end
rescue ActiveRecord::RecordInvalid
respond_to do |format|
@message = t('access_permissions.create.failure')
format.json { render :new }
end
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error e.message
errors = @project.errors ? @project.errors&.map(&:message)&.join(',') : e.message
render json: { flash: errors }, status: :unprocessable_entity
raise ActiveRecord::Rollback
end
end
@ -152,6 +152,10 @@ module AccessPermissions
log_activity(:project_access_changed_all_team_members,
{ team: @project.team.id, role: @project.default_public_user_role&.name })
end
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error e.message
render json: { flash: @project.errors&.map(&:message)&.join(',') }, status: :unprocessable_entity
raise ActiveRecord::Rollback
end
end

View file

@ -94,11 +94,11 @@ module AccessPermissions
format.json { render :edit }
end
rescue ActiveRecord::RecordInvalid
respond_to do |format|
@message = t('access_permissions.create.failure')
format.json { render :new }
end
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error e.message
errors = @protocol.errors ? @protocol.errors&.map(&:message)&.join(',') : e.message
render json: { flash: errors }, status: :unprocessable_entity
raise ActiveRecord::Rollback
end
end
@ -132,18 +132,24 @@ module AccessPermissions
end
def update_default_public_user_role
current_role = @protocol.default_public_user_role.name
@protocol.update!(permitted_default_public_user_role_params)
ActiveRecord::Base.transaction do
current_role = @protocol.default_public_user_role.name
@protocol.update!(permitted_default_public_user_role_params)
# revoke all team members access
if permitted_default_public_user_role_params[:default_public_user_role_id].blank?
log_activity(:protocol_template_access_revoked_all_team_members,
{ team: @protocol.team.id, role: current_role })
render json: { flash: t('access_permissions.update.revoke_all_team_members') }, status: :ok
else
# update all team members access
log_activity(:protocol_template_access_changed_all_team_members,
{ team: @protocol.team.id, role: @protocol.default_public_user_role&.name })
# revoke all team members access
if permitted_default_public_user_role_params[:default_public_user_role_id].blank?
log_activity(:protocol_template_access_revoked_all_team_members,
{ team: @protocol.team.id, role: current_role })
render json: { flash: t('access_permissions.update.revoke_all_team_members') }, status: :ok
else
# update all team members access
log_activity(:protocol_template_access_changed_all_team_members,
{ team: @protocol.team.id, role: @protocol.default_public_user_role&.name })
end
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error e.message
render json: { flash: @protocol&.errors&.map(&:message)&.join(',') }, status: :unprocessable_entity
raise ActiveRecord::Rollback
end
end

View file

@ -142,7 +142,7 @@ class ProtocolsController < ApplicationController
protocol: @protocol.id,
version_number: @protocol.version_number)
rescue ActiveRecord::RecordInvalid => e
flash[:error] = e.message
flash[:error] = @protocol.errors&.map(&:message)&.join(',')
Rails.logger.error e.message
raise ActiveRecord::Rollback
rescue StandardError => e

View file

@ -85,6 +85,10 @@ class StepsController < ApplicationController
)
@step = @protocol.insert_step(@step, params[:position])
if @protocol.in_repository? && @protocol.errors
return render json: { error: @protocol.errors }, status: :unprocessable_entity
end
# Generate activity
if @protocol.in_module?
log_activity(:create_step, @my_module.experiment.project, { my_module: @my_module.id }.merge(step_message_items))

View file

@ -274,6 +274,8 @@
this.$nextTick(() => this.scrollToBottom());
}
this.refreshProtocolStatus();
}).error((data) => {
HelperModule.flashAlertMsg(data.responseJSON.error ? Object.values(data.responseJSON.error).join(', ') : I18n.t('errors.general'), 'danger');
})
},
updateStepsPosition(step, action = 'add') {

View file

@ -112,6 +112,9 @@
data: { protocol: { authors: authors } },
success: (result) => {
this.$emit('update', result.data.attributes)
},
error: (data) => {
HelperModule.flashAlertMsg(data.responseJSON ? Object.values(data.responseJSON).join(', ') : I18n.t('errors.general'), 'danger');
}
});
},

View file

@ -76,7 +76,7 @@ class Protocol < ApplicationRecord
validate :ensure_single_draft
validate :versions_same_name_constraint
end
with_options if: -> { in_repository? && !parent } do |protocol|
with_options if: -> { in_repository? && !parent && !archived_changed?(from: false) } do |protocol|
# Active protocol must have unique name inside its team
protocol
.validates_uniqueness_of :name, case_sensitive: false,
@ -230,6 +230,9 @@ class Protocol < ApplicationRecord
step.position = position
step.protocol = self
step.save!
rescue ActiveRecord::RecordInvalid => e
Rails.logger.error e.message
raise ActiveRecord::Rollback
end
step
end

View file

@ -2807,10 +2807,6 @@ en:
make_private_error: "Error occurred while moving selected protocols to My protocols."
publish_unauthorized: "You do not have permission to move selected protocols to Team protocols."
publish_error: "Error occurred while moving selected protocols to Team protocols."
archive_unauthorized: "You do not have permission to archive selected protocols."
archive_error: "Error occurred while archiving selected protocols."
restore_unauthorized: "You do not have permission to restore selected protocols."
restore_error: "Error occurred while restoring selected protocols."
row_renamed_html: "%{old_name}<i> to </i>%{new_name}"
no_protocol_name: "(no name)"
create: