Return the association and check it in controller instead:

Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/4641#note_12444891
This commit is contained in:
Lin Jen-Shin 2016-06-14 23:11:43 +08:00
parent 6c500034f4
commit 9cf45b0586
4 changed files with 9 additions and 4 deletions

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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")