summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-23 11:00:02 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-10-23 11:00:02 +0000
commitf94711ea8c9998a6a6af74370fdc02c9c25208cb (patch)
treef044eb85f6543787b3786ae9d5eaded412f5915e /lib
parent311ca416d75403b5f963bf740910542682f10c36 (diff)
downloadredmine-f94711ea8c9998a6a6af74370fdc02c9c25208cb.tar.gz
redmine-f94711ea8c9998a6a6af74370fdc02c9c25208cb.zip
Option to specify allowed extensions for a file custom field (#6719).
git-svn-id: http://svn.redmine.org/redmine/trunk@15921 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine/field_format.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb
index c2a02d06d..7d6502b2c 100644
--- a/lib/redmine/field_format.rb
+++ b/lib/redmine/field_format.rb
@@ -861,6 +861,7 @@ module Redmine
self.form_partial = 'custom_fields/formats/attachment'
self.is_filter_supported = false
self.change_no_details = true
+ field_attributes :extensions_allowed
def set_custom_field_value(custom_field, custom_field_value, value)
attachment_present = false
@@ -917,8 +918,18 @@ module Redmine
def validate_custom_value(custom_value)
errors = []
- if custom_value.instance_variable_get("@attachment_present") && custom_value.value.blank?
- errors << ::I18n.t('activerecord.errors.messages.invalid')
+ if custom_value.value.blank?
+ if custom_value.instance_variable_get("@attachment_present")
+ errors << ::I18n.t('activerecord.errors.messages.invalid')
+ end
+ else
+ if custom_value.value.present?
+ attachment = Attachment.where(:id => custom_value.value.to_s).first
+ extensions = custom_value.custom_field.extensions_allowed
+ if attachment && extensions.present? && !attachment.extension_in?(extensions)
+ errors << "#{::I18n.t('activerecord.errors.messages.invalid')} (#{l(:setting_attachment_extensions_allowed)}: #{extensions})"
+ end
+ end
end
errors.uniq