Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

mimick id on non existent model

ulfertsae2bebb6e2f0
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb
index 92903fc3da2..bfab917c040 100644
--- a/app/contracts/work_packages/base_contract.rb
+++ b/app/contracts/work_packages/base_contract.rb
@@ -320,7 +320,7 @@ module WorkPackages
def validate_people_visible(attribute, id_attribute, list)
id = model[id_attribute]
- return if id.nil? || model.changed.exclude?(id_attribute)
+ return if id.nil? || id == 0 || model.changed.exclude?(id_attribute)
unless principal_visible?(id, list)
errors.add attribute,
diff --git a/app/models/concerns/inexistent_model.rb b/app/models/concerns/inexistent_model.rb
new file mode 100644
index 00000000000..cceba9103f3
--- /dev/null
+++ b/app/models/concerns/inexistent_model.rb
@@ -0,0 +1,41 @@
+# --copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program 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 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+# ++
+
+module InexistentModel
+ extend ActiveSupport::Concern
+
+ included do
+ # Set an id so that e.g. change detection (dirty) on associations
+ # is picked up whenever such a model is assigned.
+ after_initialize do
+ self.id = 0
+ end
+
+ _validators.clear
+ end
+end
diff --git a/app/models/priority/inexistent_priority.rb b/app/models/priority/inexistent_priority.rb
index f07068ddc8e..c89660ed330 100644
--- a/app/models/priority/inexistent_priority.rb
+++ b/app/models/priority/inexistent_priority.rb
@@ -26,4 +26,6 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Priority::InexistentPriority < IssuePriority; end
+class Priority::InexistentPriority < IssuePriority
+ include InexistentModel
+end
diff --git a/app/models/status/inexistent_status.rb b/app/models/status/inexistent_status.rb
index aba2e592ea8..83f0ed034cb 100644
--- a/app/models/status/inexistent_status.rb
+++ b/app/models/status/inexistent_status.rb
@@ -26,4 +26,6 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Status::InexistentStatus < Status; end
+class Status::InexistentStatus < Status
+ include InexistentModel
+end
diff --git a/app/models/type/inexistent_type.rb b/app/models/type/inexistent_type.rb
index de73d14de99..7fbea83089e 100644
--- a/app/models/type/inexistent_type.rb
+++ b/app/models/type/inexistent_type.rb
@@ -27,4 +27,5 @@
#++
class Type::InexistentType < Type
+ include InexistentModel
end
diff --git a/app/models/users/inexistent_user.rb b/app/models/users/inexistent_user.rb
index aa5141fc625..4ff0a366e53 100644
--- a/app/models/users/inexistent_user.rb
+++ b/app/models/users/inexistent_user.rb
@@ -27,6 +27,8 @@
#++
class Users::InexistentUser < User
+ include InexistentModel
+
def self.sti_name
nil
end
diff --git a/app/models/work_package/inexistent_work_package.rb b/app/models/work_package/inexistent_work_package.rb
index e4b67e8bad6..4c110bf1a9d 100644
--- a/app/models/work_package/inexistent_work_package.rb
+++ b/app/models/work_package/inexistent_work_package.rb
@@ -27,7 +27,7 @@
#++
class WorkPackage::InexistentWorkPackage < WorkPackage
- _validators.clear
+ include InexistentModel
def does_not_exist
errors.add :base, :does_not_exist
diff --git a/modules/storages/app/models/storages/storage/inexistent_storage.rb b/modules/storages/app/models/storages/storage/inexistent_storage.rb
index 0e7f229064c..797b35fd134 100644
--- a/modules/storages/app/models/storages/storage/inexistent_storage.rb
+++ b/modules/storages/app/models/storages/storage/inexistent_storage.rb
@@ -27,5 +27,5 @@
#++
class Storages::Storage::InexistentStorage < Storages::Storage
- _validators.clear
+ include InexistentModel
end