debian-mirror-gitlab/app/services/timelogs/delete_service.rb

33 lines
745 B
Ruby
Raw Normal View History

2022-07-16 23:28:13 +05:30
# frozen_string_literal: true
module Timelogs
class DeleteService < Timelogs::BaseService
2022-08-27 11:52:29 +05:30
attr_accessor :timelog
def initialize(timelog, user)
super(user)
@timelog = timelog
end
2022-07-16 23:28:13 +05:30
def execute
unless can?(current_user, :admin_timelog, timelog)
2022-08-27 11:52:29 +05:30
return error(_("Timelog doesn't exist or you don't have permission to delete it"), 404)
2022-07-16 23:28:13 +05:30
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
2022-08-27 11:52:29 +05:30
success(timelog)
2022-07-16 23:28:13 +05:30
else
2022-08-27 11:52:29 +05:30
error(_('Failed to remove timelog'), 400)
2022-07-16 23:28:13 +05:30
end
end
end
end