summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-06-29 19:04:06 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-06-29 19:04:06 +0800
commit23a3ce946ad0f7ef1c63036bf313cd549d18f0ab (patch)
treec4e64fd652b9ed0289659fb673fa79206ae162de
parentdeb5509f7bc3eec8fa47939144a52cda7d408625 (diff)
downloadgitlab-ce-23a3ce946ad0f7ef1c63036bf313cd549d18f0ab.tar.gz
Use Ability to check pre-requisite. Change back to 403 because:
If we're using `can?` it would look weird to use 409
-rw-r--r--app/controllers/projects/runner_projects_controller.rb3
-rw-r--r--app/models/ability.rb13
2 files changed, 14 insertions, 2 deletions
diff --git a/app/controllers/projects/runner_projects_controller.rb b/app/controllers/projects/runner_projects_controller.rb
index dc825557928..8267b14941d 100644
--- a/app/controllers/projects/runner_projects_controller.rb
+++ b/app/controllers/projects/runner_projects_controller.rb
@@ -6,8 +6,7 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
def create
@runner = Ci::Runner.find(params[:runner_project][:runner_id])
- return head(409) if @runner.is_shared? || @runner.locked?
- return head(409) unless current_user.ci_authorized_runners.include?(@runner)
+ return head(403) unless can?(current_user, :assign_runner, @runner)
path = runners_path(project)
runner_project = @runner.assign_to(project, current_user)
diff --git a/app/models/ability.rb b/app/models/ability.rb
index f5950879ccb..0add2f5a34a 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -19,6 +19,7 @@ class Ability
when ProjectMember then project_member_abilities(user, subject)
when User then user_abilities
when ExternalIssue, Deployment, Environment then project_abilities(user, subject.project)
+ when Ci::Runner then runner_abilities(user, subject)
else []
end.concat(global_abilities(user))
end
@@ -512,6 +513,18 @@ class Ability
rules
end
+ def runner_abilities(user, runner)
+ if user.is_admin?
+ [:assign_runner]
+ elsif runner.is_shared? || runner.locked?
+ []
+ elsif user.ci_authorized_runners.include?(runner)
+ [:assign_runner]
+ else
+ []
+ end
+ end
+
def user_abilities
[:read_user]
end