summaryrefslogtreecommitdiff
path: root/lib/api/runners.rb
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2016-01-29 15:40:25 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2016-02-19 13:18:46 +0100
commitd42ced44d9f2ddeae5a76d60273a59d7253ca2b2 (patch)
tree82742396a4dea2588e822a6ab9c4c9975f674778 /lib/api/runners.rb
parent128be3c0103f601b2c80f3489646e57e202f6327 (diff)
downloadgitlab-ce-d42ced44d9f2ddeae5a76d60273a59d7253ca2b2.tar.gz
Add feature to enable/disable runner in project
Diffstat (limited to 'lib/api/runners.rb')
-rw-r--r--lib/api/runners.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/api/runners.rb b/lib/api/runners.rb
index 7d4ca3f1587..87b37c05397 100644
--- a/lib/api/runners.rb
+++ b/lib/api/runners.rb
@@ -59,6 +59,26 @@ module API
runners = filter_runners(Ci::Runner.owned_or_shared(user_project.id), params[:scope])
present paginate(runners), with: Entities::Runner
end
+
+ put ':id/runners/:runner_id' do
+ runner = get_runner(params[:runner_id])
+ can_enable_runner?(runner)
+ Ci::RunnerProject.create(runner: runner, project: user_project)
+
+ present runner, with: Entities::Runner
+ end
+
+ delete ':id/runners/:runner_id' do
+ runner_project = user_project.runner_projects.find_by(runner_id: params[:runner_id])
+ not_found!('Runner') unless runner_project
+
+ runner = runner_project.runner
+ forbidden!("Can't disable runner - only one project associated with it. Please remove runner instead") if runner.projects.count == 1
+
+ runner_project.destroy
+
+ present runner, with: Entities::Runner
+ end
end
helpers do
@@ -97,6 +117,12 @@ module API
forbidden!("Can't delete runner - no access granted") unless user_can_access_runner?(runner)
end
+ def can_enable_runner?(runner)
+ forbidden!("Can't enable shared runner directly") if runner.is_shared?
+ return true if current_user.is_admin?
+ forbidden!("Can't update runner - no access granted") unless user_can_access_runner?(runner)
+ end
+
def user_can_access_runner?(runner)
runner.projects.inject(false) do |final, project|
final ||= abilities.allowed?(current_user, :admin_project, project)