Class: Issuable::Callbacks::TimeTracking

Inherits:
Base
  • Object
show all
Defined in:
app/services/issuable/callbacks/time_tracking.rb

Constant Summary collapse

ALLOWED_PARAMS =
%i[time_estimate spend_time timelog].freeze

Constants inherited from Base

Base::Error

Instance Method Summary collapse

Methods inherited from Base

#after_create, #after_save, #after_save_commit, #after_update, #after_update_commit, #before_create, #before_update, execute_without_params?, #initialize

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from Issuable::Callbacks::Base

Instance Method Details

#after_initializeObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/issuable/callbacks/time_tracking.rb', line 8

def after_initialize
  if excluded_in_new_type?
    params.delete(:time_estimate)
    params.delete(:spend_time)
    params.delete(:timelog)
  end

  return unless has_permission?(:"admin_#{issuable.to_ability_name}")

  # below 2 parse_*_data methods, parse the data coming in from `time_tracking_widget` argument, in
  # work item update mutation.
  parse_timelog_data if params.key?(:timelog) && !params[:spend_time]
  parse_time_estimate_data if params.key?(:time_estimate) && params[:time_estimate].is_a?(String)

  # we still need to set the data here, in case when we had no data coming in from the `time_tracking_widget`
  # argument, but data was still set through updating the description and using quick actions.
  issuable.time_estimate = params[:time_estimate] if params.has_key?(:time_estimate)
  issuable.spend_time = params[:spend_time] if params[:spend_time].present?
end