Skip to content

BE: Set Status automatically for open/close/duplicate/move actions

When one of the open/close/duplicate/move actions happen, automatically set the status to the default status of the state (open/closed) or action (duplicated). Context here - #477863 (closed)

These action happen inside the UpdateService of the work item. We have ee/app/services/work_items/callbacks/status.rb to set status and can use this callback to transition to another status based on state changes.

I think we can ignore move for now.

The lifecycle of the work item type has default_open_status, default_closed_status and default_duplicated_status.

We need to take the system defined lifecycle that is assigned to the work item type of the WI and find the status that is the default for the given action. We can then apply the status change.

Keep in mind that work items might not have current_status yet, so we might want to use build_current_status if it's not present.

Note: We also need to set an initial status when a work item is created. We can do this in the callback, too if we want to. The problem: callbacks are only executed if params for the widget are present. But because all callbacks are usually guarded with checks for the params we might want to remove app/services/concerns/work_items/widgetable_service.rb:24 so they are always executed. That way we could set an initial status in the after_initialize method if none is set explicitly.

Heads up: We'll perform a data migration to backfill status data for (open) work items of type task. We might want to set the default open/closed statuses regardless of the feature flag and license check to ensure status is always there and correct.

Edited by Marc Saleiko