Skip to content
Snippets Groups Projects
Commit 9cf45b05 authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Return the association and check it in controller instead:

parent 6c500034
Branches
Tags
2 merge requests!4734!4093 is giving me 502,!4093Make it possible to lock runner on a specific project
Pipeline #
Loading
@@ -11,7 +11,9 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
Loading
@@ -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'
Loading
Loading
Loading
@@ -10,8 +10,9 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
Loading
@@ -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'
Loading
Loading
Loading
@@ -63,7 +63,7 @@ module Ci
Loading
@@ -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
Loading
Loading
Loading
@@ -97,7 +97,9 @@ module API
Loading
@@ -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")
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment