mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 15:14:33 +08:00
Merge pull request #7900 from aignatov-bio/ai-sci-11116-add-grid-and-size-validation-to-storage-locations
Fix validation for storage locations metadata [SCI-11116]
This commit is contained in:
commit
37174b5e3e
3 changed files with 29 additions and 2 deletions
|
@ -186,8 +186,23 @@ export default {
|
|||
// Smart annotation fix
|
||||
this.object.description = $(this.$refs.description).val();
|
||||
|
||||
const params = {
|
||||
name: this.object.name,
|
||||
description: this.object.description,
|
||||
signed_blob_id: this.object.signed_blob_id,
|
||||
container: this.object.container
|
||||
};
|
||||
|
||||
if (this.object.container) {
|
||||
params.metadata = this.object.metadata;
|
||||
|
||||
if (params.metadata.display_type === 'no_grid') {
|
||||
delete params.metadata.dimensions;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.object.code) {
|
||||
axios.put(this.object.urls.update, this.object)
|
||||
axios.put(this.object.urls.update, params)
|
||||
.then(() => {
|
||||
this.$emit('tableReloaded');
|
||||
HelperModule.flashAlertMsg(this.i18n.t(`storage_locations.index.edit_modal.success_message.edit_${this.editModalMode}`, { name: this.object.name }), 'success');
|
||||
|
@ -196,7 +211,7 @@ export default {
|
|||
HelperModule.flashAlertMsg(error.response.data.error, 'danger');
|
||||
});
|
||||
} else {
|
||||
axios.post(this.createUrl, this.object)
|
||||
axios.post(this.createUrl, params)
|
||||
.then(() => {
|
||||
this.$emit('tableReloaded');
|
||||
HelperModule.flashAlertMsg(this.i18n.t(`storage_locations.index.edit_modal.success_message.create_${this.editModalMode}`, { name: this.object.name }), 'success');
|
||||
|
|
|
@ -21,6 +21,8 @@ class StorageLocation < ApplicationRecord
|
|||
|
||||
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||
validate :parent_validation, if: -> { parent.present? }
|
||||
validate :no_grid_options, if: -> { !container }
|
||||
validate :no_dimensions, if: -> { !with_grid? }
|
||||
|
||||
scope :readable_by_user, (lambda do |user, team = user.current_team|
|
||||
next StorageLocation.none unless team.permission_granted?(user, TeamPermissions::STORAGE_LOCATIONS_READ)
|
||||
|
@ -193,4 +195,12 @@ class StorageLocation < ApplicationRecord
|
|||
errors.add(:parent, I18n.t('activerecord.errors.models.project_folder.attributes.parent_storage_location_child'))
|
||||
end
|
||||
end
|
||||
|
||||
def no_grid_options
|
||||
errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if metadata['display_type'] || metadata['dimensions']
|
||||
end
|
||||
|
||||
def no_dimensions
|
||||
errors.add(:metadata, I18n.t('activerecord.errors.models.storage_location.attributes.metadata.invalid')) if !with_grid? && metadata['dimensions']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -268,6 +268,8 @@ en:
|
|||
attributes:
|
||||
parent_storage_location: "Storage location cannot be parent to itself"
|
||||
parent_storage_location_child: "Storage location cannot be moved to it's child"
|
||||
metadata:
|
||||
invalid: 'Invalid metadata'
|
||||
storage:
|
||||
limit_reached: "Storage limit has been reached."
|
||||
helpers:
|
||||
|
|
Loading…
Add table
Reference in a new issue