Class: Ci::PipelineTriggers::ExpireService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Allowable
Defined in:
app/services/ci/pipeline_triggers/expire_service.rb

Instance Method Summary collapse

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

#initialize(user:, trigger:) ⇒ ExpireService

Returns a new instance of ExpireService.



8
9
10
11
# File 'app/services/ci/pipeline_triggers/expire_service.rb', line 8

def initialize(user:, trigger:)
  @current_user = user
  @trigger = trigger
end

Instance Method Details

#executeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/ci/pipeline_triggers/expire_service.rb', line 13

def execute
  unless can?(current_user, :manage_trigger, trigger)
    return ServiceResponse.error(
      message: _('The current user is not authorized to manage the pipeline trigger token'),
      reason: :forbidden
    ).freeze
  end

  if trigger.update(expires_at: Time.current)
    ServiceResponse.success
  else
    ServiceResponse.error(message: trigger.errors.full_messages.to_sentence)
  end
end