diff options
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/issues/base_service.rb | 20 | ||||
-rw-r--r-- | app/services/timelogs/create_service.rb | 21 | ||||
-rw-r--r-- | app/services/work_items/callbacks/notes.rb | 14 |
3 files changed, 45 insertions, 10 deletions
diff --git a/app/services/issues/base_service.rb b/app/services/issues/base_service.rb index f564914352b..d87dc013c7f 100644 --- a/app/services/issues/base_service.rb +++ b/app/services/issues/base_service.rb @@ -31,6 +31,16 @@ module Issues Issues::RebalancingWorker.perform_async(nil, *issue.project.self_or_root_group_ids) end + def execute_hooks(issue, action = 'open', old_associations: {}) + issue_data = Gitlab::Lazy.new { hook_data(issue, action, old_associations: old_associations) } + hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks + issue.namespace.execute_hooks(issue_data, hooks_scope) + issue.namespace.execute_integrations(issue_data, hooks_scope) + + execute_incident_hooks(issue, issue_data) if issue.work_item_type&.incident? + execute_group_mention_hooks(issue, issue_data) if action == 'open' + end + private # overriding this because IssuableBaseService#constructor_container_arg returns { project: value } @@ -105,16 +115,6 @@ module Issues issue, issue.project, current_user, old_assignees) end - def execute_hooks(issue, action = 'open', old_associations: {}) - issue_data = Gitlab::Lazy.new { hook_data(issue, action, old_associations: old_associations) } - hooks_scope = issue.confidential? ? :confidential_issue_hooks : :issue_hooks - issue.namespace.execute_hooks(issue_data, hooks_scope) - issue.namespace.execute_integrations(issue_data, hooks_scope) - - execute_incident_hooks(issue, issue_data) if issue.work_item_type&.incident? - execute_group_mention_hooks(issue, issue_data) if action == 'open' - end - # We can remove this code after proposal in # https://gitlab.com/gitlab-org/gitlab/-/issues/367550#proposal is updated. def execute_incident_hooks(issue, issue_data) diff --git a/app/services/timelogs/create_service.rb b/app/services/timelogs/create_service.rb index 19428864fa9..f65f9482d76 100644 --- a/app/services/timelogs/create_service.rb +++ b/app/services/timelogs/create_service.rb @@ -37,12 +37,33 @@ module Timelogs note: nil ) + old_associations = { total_time_spent: issuable.total_time_spent } + if !timelog.save error_in_save(timelog) else SystemNoteService.created_timelog(issuable, issuable.project, current_user, timelog) + + issuable_base_service.execute_hooks(issuable, 'update', old_associations: old_associations) + success(timelog) end end + + private + + def issuable_base_service + if issuable.is_a?(Issue) + Issues::BaseService.new( + container: issuable.project, + current_user: current_user + ) + else + MergeRequests::BaseService.new( + project: issuable.project, + current_user: current_user + ) + end + end end end diff --git a/app/services/work_items/callbacks/notes.rb b/app/services/work_items/callbacks/notes.rb new file mode 100644 index 00000000000..a86e2251e81 --- /dev/null +++ b/app/services/work_items/callbacks/notes.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module WorkItems + module Callbacks + class Notes < Base + def before_update + return unless params.present? && params.key?(:discussion_locked) + return unless has_permission?(:set_work_item_metadata) + + work_item.discussion_locked = params[:discussion_locked] + end + end + end +end |