Skip to content

Commit d46545e

Browse files
committed
Merge branch 'release/16.6' into implementation/68700-rename-to-weighted-item-list
2 parents d9a8aef + fa4fd6c commit d46545e

File tree

32 files changed

+1082
-582
lines changed

32 files changed

+1082
-582
lines changed

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,6 @@ gemfiles.each do |file|
418418
send(:eval_gemfile, file) if File.readable?(file)
419419
end
420420

421-
gem "openproject-octicons", "~>19.29.0"
422-
gem "openproject-octicons_helper", "~>19.29.0"
423-
gem "openproject-primer_view_components", "~>0.75.2"
421+
gem "openproject-octicons", "~>19.30.1"
422+
gem "openproject-octicons_helper", "~>19.30.1"
423+
gem "openproject-primer_view_components", "~>0.76.0"

Gemfile.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -860,15 +860,15 @@ GEM
860860
validate_email
861861
validate_url
862862
webfinger (~> 2.0)
863-
openproject-octicons (19.29.0)
864-
openproject-octicons_helper (19.29.0)
863+
openproject-octicons (19.30.1)
864+
openproject-octicons_helper (19.30.1)
865865
actionview
866-
openproject-octicons (= 19.29.0)
866+
openproject-octicons (= 19.30.1)
867867
railties
868-
openproject-primer_view_components (0.75.2)
868+
openproject-primer_view_components (0.76.0)
869869
actionview (>= 7.2.0)
870870
activesupport (>= 7.2.0)
871-
openproject-octicons (>= 19.29.0)
871+
openproject-octicons (>= 19.30.1)
872872
view_component (>= 3.1, < 5.0)
873873
openproject-token (8.1.0)
874874
activemodel
@@ -1630,10 +1630,10 @@ DEPENDENCIES
16301630
openproject-job_status!
16311631
openproject-ldap_groups!
16321632
openproject-meeting!
1633-
openproject-octicons (~> 19.29.0)
1634-
openproject-octicons_helper (~> 19.29.0)
1633+
openproject-octicons (~> 19.30.1)
1634+
openproject-octicons_helper (~> 19.30.1)
16351635
openproject-openid_connect!
1636-
openproject-primer_view_components (~> 0.75.2)
1636+
openproject-primer_view_components (~> 0.76.0)
16371637
openproject-recaptcha!
16381638
openproject-reporting!
16391639
openproject-storages!
@@ -2007,10 +2007,10 @@ CHECKSUMS
20072007
openproject-job_status (1.0.0)
20082008
openproject-ldap_groups (1.0.0)
20092009
openproject-meeting (1.0.0)
2010-
openproject-octicons (19.29.0) sha256=9d9106a276d140a2ba975052688b0c92e404af0df5db87d322265ac5c15e8815
2011-
openproject-octicons_helper (19.29.0) sha256=d093d91163b27d1624841590a8e6b202186d165ad7d006ceadc8bdc3b09830e6
2010+
openproject-octicons (19.30.1) sha256=36ac6e91721ddddc918fba9d51ea3b9d11759d9ad76ff15c0c19c7117c76387b
2011+
openproject-octicons_helper (19.30.1) sha256=c1cc1cf337fa656de04b3ec58a3410cfb0e88f7c221dbda7a0b647b678398841
20122012
openproject-openid_connect (1.0.0)
2013-
openproject-primer_view_components (0.75.2) sha256=7ad3d7eb15a163f67fdde42b41a0e4f08a33bb26d8aeaafd5eaf5e1bf3646915
2013+
openproject-primer_view_components (0.76.0) sha256=d0506243998afd6a71de73050876bc196249901635ea8d885578513081262aa2
20142014
openproject-recaptcha (1.0.0)
20152015
openproject-reporting (1.0.0)
20162016
openproject-storages (1.0.0)

app/models/acts_as_customizable/calculated_value.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,23 @@ def calculated_value_fields_to_compute(custom_fields:, enabled_ids:)
9898
end
9999

100100
def handle_calculation_errors!(given_cfs, enabled_ids, calculated_fields, result, errors)
101+
# Skip creating error objects if the project is not persisted, because the error objects
102+
# require the customized object (project) to be saved in the database.
103+
return unless is_a?(Project) && persisted?
104+
101105
remove_calculated_value_errors!(calculated_fields.map(&:id))
102106

103-
return unless is_a?(Project) && errors.any?
107+
create_calculated_value_errors(given_cfs, enabled_ids, calculated_fields, result, errors)
108+
end
109+
110+
def remove_calculated_value_errors!(custom_field_ids)
111+
return if custom_field_ids.empty?
112+
113+
CalculatedValueError.where(customized: self, custom_field_id: custom_field_ids).delete_all
114+
end
115+
116+
def create_calculated_value_errors(given_cfs, enabled_ids, calculated_fields, result, errors)
117+
return if errors.empty?
104118

105119
enabled_calculated_fields = calculated_fields.filter { it.id.in?(enabled_ids) }
106120

@@ -112,11 +126,5 @@ def handle_calculation_errors!(given_cfs, enabled_ids, calculated_fields, result
112126
calculated_fields: enabled_calculated_fields
113127
)
114128
end
115-
116-
def remove_calculated_value_errors!(custom_field_ids)
117-
return if custom_field_ids.empty?
118-
119-
CalculatedValueError.where(customized: self, custom_field_id: custom_field_ids).delete_all
120-
end
121129
end
122130
end

app/models/custom_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CustomField < ApplicationRecord
5454
has_many :calculated_value_errors, dependent: :delete_all, inverse_of: "custom_field"
5555

5656
scope :hierarchy_root_and_children, -> { includes(hierarchy_root: { children: :children }) }
57-
scope :required, -> { where(is_required: true) }
57+
scope :required, -> { where(is_required: true).where.not(field_format: "calculated_value") }
5858

5959
scope :field_format_calculated_value, -> { where(field_format: "calculated_value") }
6060

app/models/custom_value.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CustomValue < ApplicationRecord
4848
:required?,
4949
:max_length,
5050
:min_length,
51+
:calculated_value?,
5152
to: :custom_field
5253

5354
delegate :to_s, to: :value

app/models/projects/custom_fields.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ module Projects::CustomFields
4040
has_many :project_custom_fields, through: :project_custom_field_project_mappings,
4141
class_name: "ProjectCustomField"
4242

43-
def enabled_custom_field_ids = project_custom_field_ids
43+
def enabled_custom_field_ids
44+
project_custom_field_project_mappings.map(&:custom_field_id)
45+
end
4446

4547
def available_custom_fields
4648
return all_visible_custom_fields if new_record?

app/services/projects/concerns/new_project_service.rb

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module Projects::Concerns
3232
module NewProjectService
3333
private
3434

35-
def after_validate(service_call)
35+
def before_perform(service_call)
3636
super.tap do |super_call|
3737
build_missing_project_custom_field_project_mappings(super_call.result)
3838
end
@@ -98,10 +98,11 @@ def disable_custom_fields_with_empty_values(new_project)
9898
end
9999

100100
def build_missing_project_custom_field_project_mappings(project)
101-
# Activate custom fields for this project (via mapping table) if values have been provided
102-
# for custom_fields, but no mapping exists.
101+
# Activate all custom fields (via mapping table) that are required or
102+
# have a value provided by the user, but no mapping exists.
103+
103104
custom_field_ids = project.custom_values
104-
.select { |cv| cv.value.present? }
105+
.select { |cv| cv.value? || cv.required? }
105106
.pluck(:custom_field_id).uniq
106107
activated_custom_field_ids = project.project_custom_field_project_mappings.pluck(:custom_field_id).uniq
107108

@@ -110,5 +111,25 @@ def build_missing_project_custom_field_project_mappings(project)
110111

111112
project.project_custom_field_project_mappings.build(mappings)
112113
end
114+
115+
def update_calculated_value_custom_fields(model)
116+
changed_cf_ids = model.custom_values.map(&:custom_field_id)
117+
118+
# Using unscope(where: :admin_only) to fix an issue when non admin user
119+
# edits a custom field which is used by an admin only calculated value
120+
# field. Without this unscoping, admin only value and all fields
121+
# referencing it (recursively) will not be recalculated and there will
122+
# even be no place for that recalculatin to be triggered unless an admin
123+
# edits same value again.
124+
#
125+
# This may need to be handled differently to make it work for other custom
126+
# field containers, like WorkPackage. User custom fields also has
127+
# admin_only check.
128+
affected_cfs = model.available_custom_fields.unscope(where: :admin_only).affected_calculated_fields(changed_cf_ids)
129+
130+
model.calculate_custom_fields(affected_cfs)
131+
132+
model.save if model.persisted? && model.changed_for_autosave?
133+
end
113134
end
114135
end

app/services/projects/concerns/set_calculated_custom_field_values.rb

Lines changed: 0 additions & 71 deletions
This file was deleted.

app/services/projects/copy_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def before_perform(service_call)
100100
def after_perform(call)
101101
super.tap do |super_call|
102102
copy_activated_custom_fields(super_call)
103+
update_calculated_value_custom_fields(super_call.result)
103104
end
104105
end
105106

app/services/projects/create_service.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@
3131
module Projects
3232
class CreateService < ::BaseServices::Create
3333
include Projects::Concerns::NewProjectService
34+
35+
def after_perform(service_call)
36+
super.tap do |call|
37+
update_calculated_value_custom_fields(call.result)
38+
end
39+
end
3440
end
3541
end

0 commit comments

Comments
 (0)