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

Fix custom action current-date

Oliver Günther6dad71fb49d4
diff --git a/app/views/custom_actions/_form.html.erb b/app/views/custom_actions/_form.html.erb
index e8552039d72..2adda82c4dc 100644
--- a/app/views/custom_actions/_form.html.erb
+++ b/app/views/custom_actions/_form.html.erb
@@ -61,7 +61,8 @@
</div>
<% elsif %i(date_property).include?(action.type) %>
<div class="form--field-container">
- <%= tag 'custom-date-action-admin', data: { 'field-value': action.values.first&.iso8601, 'field-name': input_name } %>
+ <% date = action.values.first %>
+ <%= tag 'custom-date-action-admin', data: { 'field-value': date.try(:iso8601) || date, 'field-name': input_name } %>
</div>
<% elsif %i(string_property text_property).include?(action.type) %>
<div class="form--field-container">
diff --git a/spec/features/work_packages/custom_actions_spec.rb b/spec/features/work_packages/custom_actions_spec.rb
index 0e0d549db21..0892defc073 100644
--- a/spec/features/work_packages/custom_actions_spec.rb
+++ b/spec/features/work_packages/custom_actions_spec.rb
@@ -455,4 +455,30 @@ describe 'Custom actions', type: :feature, js: true do
wp_page.expect_notification type: :error, message: I18n.t('api_v3.errors.code_409')
end
+
+ scenario 'editing a current date custom action (Regression #30949)' do
+ # create custom action 'Unassign'
+ index_ca_page.visit!
+
+ new_ca_page = index_ca_page.new
+
+ retry_block do
+ new_ca_page.visit!
+ new_ca_page.set_name('Current date')
+ new_ca_page.set_description('Sets the current date')
+ new_ca_page.add_action('Date', 'Current date')
+ end
+
+ new_ca_page.create
+
+ index_ca_page.expect_current_path
+ index_ca_page.expect_listed('Current date')
+
+ date_action = CustomAction.last
+ expect(date_action.actions.length).to eq(1)
+ expect(date_action.conditions.length).to eq(0)
+
+ edit_page = index_ca_page.edit('Current date')
+ expect(page).to have_select('custom_action_actions_date', selected: 'Current date')
+ end
end