Skip to content

Commit 9cf45b0

Browse files
committed
Return the association and check it in controller instead:
Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4641#note_12444891
1 parent 6c50003 commit 9cf45b0

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

app/controllers/admin/runner_projects_controller.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ def create
1111

1212
return head(403) if runner.is_shared? || runner.is_locked?
1313

14-
if @runner.assign_to(@project, current_user)
14+
runner_project = @runner.assign_to(@project, current_user)
15+
16+
if runner_project.persisted?
1517
redirect_to admin_runner_path(@runner)
1618
else
1719
redirect_to admin_runner_path(@runner), alert: 'Failed adding runner to project'

app/controllers/projects/runner_projects_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ def create
1010
return head(403) unless current_user.ci_authorized_runners.include?(@runner)
1111

1212
path = runners_path(project)
13+
runner_project = @runner.assign_to(project, current_user)
1314

14-
if @runner.assign_to(project, current_user)
15+
if runner_project.persisted?
1516
redirect_to path
1617
else
1718
redirect_to path, alert: 'Failed adding runner to project'

app/models/ci/runner.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def set_default_values
6363
def assign_to(project, current_user = nil)
6464
self.is_shared = false if shared?
6565
self.save
66-
project.runner_projects.create(runner_id: self.id).persisted?
66+
project.runner_projects.create(runner_id: self.id)
6767
end
6868

6969
def display_name

lib/api/runners.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ class Runners < Grape::API
9797
runner = get_runner(params[:runner_id])
9898
authenticate_enable_runner!(runner)
9999

100-
if runner.assign_to(user_project)
100+
runner_project = runner.assign_to(user_project)
101+
102+
if runner_project.persisted?
101103
present runner, with: Entities::Runner
102104
else
103105
conflict!("Runner was already enabled for this project")

0 commit comments

Comments
 (0)