summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/runner_projects_controller.rb4
-rw-r--r--app/controllers/projects/runner_projects_controller.rb3
-rw-r--r--app/models/ci/runner.rb2
-rw-r--r--lib/api/runners.rb4
4 files changed, 9 insertions, 4 deletions
diff --git a/app/controllers/admin/runner_projects_controller.rb b/app/controllers/admin/runner_projects_controller.rb
index 29307aeab6d..5383afdbd20 100644
--- a/app/controllers/admin/runner_projects_controller.rb
+++ b/app/controllers/admin/runner_projects_controller.rb
@@ -11,7 +11,9 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
return head(403) if runner.is_shared? || runner.is_locked?
- if @runner.assign_to(@project, current_user)
+ runner_project = @runner.assign_to(@project, current_user)
+
+ if runner_project.persisted?
redirect_to admin_runner_path(@runner)
else
redirect_to admin_runner_path(@runner), alert: 'Failed adding runner to project'
diff --git a/app/controllers/projects/runner_projects_controller.rb b/app/controllers/projects/runner_projects_controller.rb
index 4c013303269..2413e583d7b 100644
--- a/app/controllers/projects/runner_projects_controller.rb
+++ b/app/controllers/projects/runner_projects_controller.rb
@@ -10,8 +10,9 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
return head(403) unless current_user.ci_authorized_runners.include?(@runner)
path = runners_path(project)
+ runner_project = @runner.assign_to(project, current_user)
- if @runner.assign_to(project, current_user)
+ if runner_project.persisted?
redirect_to path
else
redirect_to path, alert: 'Failed adding runner to project'
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index df343fc957a..8149929f492 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -63,7 +63,7 @@ module Ci
def assign_to(project, current_user = nil)
self.is_shared = false if shared?
self.save
- project.runner_projects.create(runner_id: self.id).persisted?
+ project.runner_projects.create(runner_id: self.id)
end
def display_name
diff --git a/lib/api/runners.rb b/lib/api/runners.rb
index 2c2610fc2e7..ecc8f2fc5a2 100644
--- a/lib/api/runners.rb
+++ b/lib/api/runners.rb
@@ -97,7 +97,9 @@ module API
runner = get_runner(params[:runner_id])
authenticate_enable_runner!(runner)
- if runner.assign_to(user_project)
+ runner_project = runner.assign_to(user_project)
+
+ if runner_project.persisted?
present runner, with: Entities::Runner
else
conflict!("Runner was already enabled for this project")