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