Commit 9cf45b05 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Return the association and check it in controller instead:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4641#note_12444891
parent 6c500034
...@@ -11,7 +11,9 @@ class Admin::RunnerProjectsController < Admin::ApplicationController ...@@ -11,7 +11,9 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
return head(403) if runner.is_shared? || runner.is_locked? 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) redirect_to admin_runner_path(@runner)
else else
redirect_to admin_runner_path(@runner), alert: 'Failed adding runner to project' redirect_to admin_runner_path(@runner), alert: 'Failed adding runner to project'
......
...@@ -10,8 +10,9 @@ class Projects::RunnerProjectsController < Projects::ApplicationController ...@@ -10,8 +10,9 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
return head(403) unless current_user.ci_authorized_runners.include?(@runner) return head(403) unless current_user.ci_authorized_runners.include?(@runner)
path = runners_path(project) 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 redirect_to path
else else
redirect_to path, alert: 'Failed adding runner to project' redirect_to path, alert: 'Failed adding runner to project'
......
...@@ -63,7 +63,7 @@ module Ci ...@@ -63,7 +63,7 @@ module Ci
def assign_to(project, current_user = nil) def assign_to(project, current_user = nil)
self.is_shared = false if shared? self.is_shared = false if shared?
self.save self.save
project.runner_projects.create(runner_id: self.id).persisted? project.runner_projects.create(runner_id: self.id)
end end
def display_name def display_name
......
...@@ -97,7 +97,9 @@ module API ...@@ -97,7 +97,9 @@ module API
runner = get_runner(params[:runner_id]) runner = get_runner(params[:runner_id])
authenticate_enable_runner!(runner) 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 present runner, with: Entities::Runner
else else
conflict!("Runner was already enabled for this project") conflict!("Runner was already enabled for this project")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment