From bc9ca5fcfd74ea699ea816aaf9e38edadd37b784 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 27 Jun 2015 09:02:24 +0000 Subject: 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 --- app/models/version.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'app/models/version.rb') 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 -- cgit v1.2.3