#9 Active Storage - Litmus
This commit is contained in:
parent
27435704f6
commit
576cddf297
@ -92,7 +92,12 @@ class DmsfFileRevision < ApplicationRecord
|
||||
|
||||
validates :title, presence: true, length: { maximum: 255 }, dmsf_file_name: true
|
||||
validates :major_version, presence: true
|
||||
validates :name, presence: true, dmsf_file_name: true, length: { maximum: 255 }, dmsf_file_extension: true
|
||||
validates :name,
|
||||
presence: true,
|
||||
dmsf_file_name: true,
|
||||
length: { maximum: 255 },
|
||||
dmsf_file_extension: true,
|
||||
dmsf_file_revision_name: true
|
||||
validates :description, length: { maximum: 1.kilobyte }
|
||||
validates :size, dmsf_max_file_size: true
|
||||
|
||||
|
||||
@ -22,11 +22,10 @@ class DmsfFileExtensionValidator < ActiveModel::EachValidator
|
||||
include Redmine::I18n
|
||||
|
||||
def validate_each(record, attribute, value)
|
||||
return unless attribute.to_s == 'name'
|
||||
|
||||
extension = File.extname(value)
|
||||
|
||||
return if Attachment.valid_extension?(extension)
|
||||
|
||||
record.errors.add(:base, l(:error_attachment_extension_not_allowed, extension: extension))
|
||||
record.errors.add attribute, l(:error_attachment_extension_not_allowed, extension: extension)
|
||||
end
|
||||
end
|
||||
|
||||
35
app/validators/dmsf_file_revision_name_validator.rb
Normal file
35
app/validators/dmsf_file_revision_name_validator.rb
Normal file
@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Redmine plugin for Document Management System "Features"
|
||||
#
|
||||
# Vít Jonáš <vit.jonas@gmail.com>, Karel Pičman <karel.picman@kontron.com>
|
||||
#
|
||||
# This file is part of Redmine DMSF plugin.
|
||||
#
|
||||
# Redmine DMSF plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General
|
||||
# Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
|
||||
# later version.
|
||||
#
|
||||
# Redmine DMSF plugin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with Redmine DMSF plugin. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
|
||||
# File name validator
|
||||
class DmsfFileRevisionNameValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
# Check name/title uniqueness
|
||||
DmsfFile
|
||||
.visible
|
||||
.where(project_id: record.dmsf_file.project_id, dmsf_folder_id: record.dmsf_file.dmsf_folder_id)
|
||||
.where.not(id: record.dmsf_file_id)
|
||||
.find_each do |dmsf_file|
|
||||
if dmsf_file.name == value
|
||||
record.errors.add attribute, :taken
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user