Class: Ci::Runners::SetRunnerAssociatedProjectsService

Inherits:
Object
  • Object
show all
Defined in:
app/services/ci/runners/set_runner_associated_projects_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(runner:, current_user:, project_ids:) ⇒ SetRunnerAssociatedProjectsService

Returns a new instance of SetRunnerAssociatedProjectsService.

Parameters:

  • runner: (Ci::Runner)

    the project runner to assign/unassign projects from

  • current_user: (User)

    the user performing the operation

  • project_ids: (Array<Integer>)

    the IDs of the associated projects to assign the runner to



9
10
11
12
13
# File 'app/services/ci/runners/set_runner_associated_projects_service.rb', line 9

def initialize(runner:, current_user:, project_ids:)
  @runner = runner
  @current_user = current_user
  @project_ids = project_ids
end

Instance Method Details

#executeObject



15
16
17
18
19
20
21
22
23
# File 'app/services/ci/runners/set_runner_associated_projects_service.rb', line 15

def execute
  unless current_user&.can?(:assign_runner, runner)
    return ServiceResponse.error(message: 'user not allowed to assign runner', http_status: :forbidden)
  end

  return ServiceResponse.success if project_ids.nil?

  set_associated_projects
end