diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-06-27 09:02:24 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-06-27 09:02:24 +0000 |
commit | bc9ca5fcfd74ea699ea816aaf9e38edadd37b784 (patch) | |
tree | 34714c20aeeb5b6e252909f06b18e111a3ae209f /app/models/version.rb | |
parent | 5b1fb525b81583c874991991ba00ed946719974f (diff) | |
download | redmine-bc9ca5fcfd74ea699ea816aaf9e38edadd37b784.tar.gz redmine-bc9ca5fcfd74ea699ea816aaf9e38edadd37b784.zip |
Disallow users to delete a version referenced by a custom field (#20159).
git-svn-id: http://svn.redmine.org/redmine/trunk@14376 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/version.rb')
-rw-r--r-- | app/models/version.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/version.rb b/app/models/version.rb index b8c7b6f60..9910700f2 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -227,6 +227,10 @@ class Version < ActiveRecord::Base sharing != 'none' end + def deletable? + fixed_issues.empty? && !referenced_by_a_custom_field? + end + private def load_issue_counts @@ -288,4 +292,9 @@ class Version < ActiveRecord::Base progress end end + + def referenced_by_a_custom_field? + CustomValue.joins(:custom_field). + where(:value => id.to_s, :custom_fields => {:field_format => 'version'}).any? + end end |