Class: Timelogs::CreateService
- Inherits:
-
BaseService
- Object
- BaseService
- Timelogs::CreateService
- Defined in:
- app/services/timelogs/create_service.rb
Instance Attribute Summary collapse
-
#issuable ⇒ Object
Returns the value of attribute issuable.
-
#spent_at ⇒ Object
Returns the value of attribute spent_at.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#time_spent ⇒ Object
Returns the value of attribute time_spent.
Attributes inherited from BaseService
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(issuable, time_spent, spent_at, summary, user) ⇒ CreateService
constructor
A new instance of CreateService.
Methods inherited from BaseService
#error, #error_in_save, #success
Methods included from BaseServiceUtility
#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level
Methods included from Gitlab::Allowable
Constructor Details
#initialize(issuable, time_spent, spent_at, summary, user) ⇒ CreateService
Returns a new instance of CreateService.
7 8 9 10 11 12 13 14 |
# File 'app/services/timelogs/create_service.rb', line 7 def initialize(issuable, time_spent, spent_at, summary, user) super(user) @issuable = issuable @time_spent = time_spent @spent_at = spent_at @summary = summary end |
Instance Attribute Details
#issuable ⇒ Object
Returns the value of attribute issuable.
5 6 7 |
# File 'app/services/timelogs/create_service.rb', line 5 def issuable @issuable end |
#spent_at ⇒ Object
Returns the value of attribute spent_at.
5 6 7 |
# File 'app/services/timelogs/create_service.rb', line 5 def spent_at @spent_at end |
#summary ⇒ Object
Returns the value of attribute summary.
5 6 7 |
# File 'app/services/timelogs/create_service.rb', line 5 def summary @summary end |
#time_spent ⇒ Object
Returns the value of attribute time_spent.
5 6 7 |
# File 'app/services/timelogs/create_service.rb', line 5 def time_spent @time_spent end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/services/timelogs/create_service.rb', line 16 def execute unless can?(current_user, :create_timelog, issuable) return error( _("%{issuable_class_name} doesn't exist or you don't have permission to add timelog to it.") % { issuable_class_name: issuable.nil? ? 'Issuable' : issuable.base_class_name }, 404) end return error(_("Spent at can't be a future date and time."), 404) if spent_at.future? return error(_("Time spent can't be zero."), 404) if time_spent == 0 issue = issuable if issuable.is_a?(Issue) merge_request = issuable if issuable.is_a?(MergeRequest) timelog = Timelog.new( time_spent: time_spent, spent_at: spent_at, summary: summary, user: current_user, issue: issue, merge_request: merge_request, note: nil ) old_associations = { total_time_spent: issuable.total_time_spent } if !timelog.save error_in_save(timelog) else issuable.reset SystemNoteService.created_timelog(issuable, issuable.project, current_user, timelog) issuable_base_service.execute_hooks(issuable, 'update', old_associations: old_associations) success(timelog) end end |