blob: 3669bdcf716038f29875a1b406e21f6522ebc0c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
|
# frozen_string_literal: true
module Terraform
module States
class TriggerDestroyService
def initialize(state, current_user:)
@state = state
@current_user = current_user
end
def execute
return unauthorized_response unless can_destroy_state?
return state_locked_response if state.locked?
state.update!(deleted_at: Time.current)
Terraform::States::DestroyWorker.perform_async(state.id)
ServiceResponse.success
end
private
attr_reader :state, :current_user
def can_destroy_state?
current_user.can?(:admin_terraform_state, state.project)
end
def unauthorized_response
error_response(s_('Terraform|You have insufficient permissions to delete this state'))
end
def state_locked_response
error_response(s_('Terraform|Cannot remove a locked state'))
end
def error_response(message)
ServiceResponse.error(message: message)
end
end
end
end
|