Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/timelogs/delete_service.rb')
-rw-r--r--app/services/timelogs/delete_service.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/services/timelogs/delete_service.rb b/app/services/timelogs/delete_service.rb
new file mode 100644
index 00000000000..0df888a3706
--- /dev/null
+++ b/app/services/timelogs/delete_service.rb
@@ -0,0 +1,26 @@
+# frozen_string_literal: true
+
+module Timelogs
+ class DeleteService < Timelogs::BaseService
+ def execute
+ unless can?(current_user, :admin_timelog, timelog)
+ return ServiceResponse.error(
+ message: "Timelog doesn't exist or you don't have permission to delete it",
+ http_status: 404)
+ end
+
+ if timelog.destroy
+ issuable = timelog.issuable
+
+ if issuable
+ # Add a system note for the timelog removal
+ SystemNoteService.remove_timelog(issuable, issuable.project, current_user, timelog)
+ end
+
+ ServiceResponse.success(payload: timelog)
+ else
+ ServiceResponse.error(message: 'Failed to remove timelog', http_status: 400)
+ end
+ end
+ end
+end