debian-mirror-gitlab/app/services/ci/pipeline_schedules/take_ownership_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
737 B
Ruby
Raw Normal View History

2023-01-13 00:05:48 +05:30
# frozen_string_literal: true
module Ci
module PipelineSchedules
class TakeOwnershipService
def initialize(schedule, user)
@schedule = schedule
@user = user
end
def execute
return forbidden unless allowed?
if schedule.update(owner: user)
ServiceResponse.success(payload: schedule)
else
ServiceResponse.error(message: schedule.errors.full_messages)
end
end
private
attr_reader :schedule, :user
def allowed?
2023-05-27 22:25:52 +05:30
user.can?(:admin_pipeline_schedule, schedule)
2023-01-13 00:05:48 +05:30
end
def forbidden
ServiceResponse.error(message: _('Failed to change the owner'), reason: :access_denied)
end
end
end
end