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

work_package -> entity in some places

Klaus Zandersd29aa6a0a189
diff --git a/modules/costs/app/contracts/time_entries/base_contract.rb b/modules/costs/app/contracts/time_entries/base_contract.rb
index a778a8422fe..6bb5e6b6d1b 100644
--- a/modules/costs/app/contracts/time_entries/base_contract.rb
+++ b/modules/costs/app/contracts/time_entries/base_contract.rb
@@ -45,7 +45,7 @@ module TimeEntries
validate :validate_hours_are_in_range
validate :validate_project_is_set
- validate :validate_work_package
+ validate :validate_entity
validate :validate_user
validates :spent_on,
@@ -90,12 +90,16 @@ module TimeEntries
private
- def validate_work_package
- return unless model.work_package || model.work_package_id_changed?
+ def validate_entity
+ return unless model.entity || model.entity_changed?
- if work_package_invisible? ||
- work_package_not_in_project?
- errors.add :work_package_id, :invalid
+ if model.entity.is_a?(WorkPackage)
+ if work_package_invisible? || work_package_not_in_project?
+ errors.add :entity, :invalid
+ end
+ elsif model.entity.is_a?(TimeEntry)
+ # TODO: Add validation for time entry
+ true
end
end
@@ -121,11 +125,11 @@ module TimeEntries
end
def work_package_invisible?
- model.work_package.nil? || !model.work_package.visible?(user)
+ model.entity.nil? || !model.entity.visible?(user)
end
def work_package_not_in_project?
- model.work_package && model.project != model.work_package.project
+ model.entity && model.project != model.entity.project
end
def user_invisible?
diff --git a/modules/costs/app/services/time_entries/set_attributes_service.rb b/modules/costs/app/services/time_entries/set_attributes_service.rb
index 2da2362665e..a5a5600db51 100644
--- a/modules/costs/app/services/time_entries/set_attributes_service.rb
+++ b/modules/costs/app/services/time_entries/set_attributes_service.rb
@@ -78,7 +78,7 @@ module TimeEntries
def no_project_or_context_changed?
!model.project ||
- (model.work_package && model.work_package_id_changed? && !model.project_id_changed?)
+ (model.entity && model.entity_changed? && !model.project_id_changed?)
end
def ensure_start_time_for_onging_entries
diff --git a/modules/costs/app/views/costlog/edit.html.erb b/modules/costs/app/views/costlog/edit.html.erb
index 3fe2059fa27..cd78f17c244 100644
--- a/modules/costs/app/views/costlog/edit.html.erb
+++ b/modules/costs/app/views/costlog/edit.html.erb
@@ -54,9 +54,9 @@ See COPYRIGHT and LICENSE files for more details.
autofocus: true,
container_class: "-xslim" %>
- <% if @cost_entry.work_package %>
+ <% if @cost_entry.entity %>
<div class="form--field-instructions">
- <%= h(@cost_entry.work_package.to_s) %>
+ <%= h(@cost_entry.entity.to_s) %>
</div>
<% end %>
</div>