summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb18
-rw-r--r--lib/api/runner.rb5
-rw-r--r--lib/api/runners.rb1
-rw-r--r--lib/api/v3/runners.rb1
4 files changed, 21 insertions, 4 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 8aad320e376..f28c4bcc784 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -242,13 +242,18 @@ module API
expose :requested_at
end
- class Group < Grape::Entity
- expose :id, :name, :path, :description, :visibility
+ class BasicGroupDetails < Grape::Entity
+ expose :id
+ expose :web_url
+ expose :name
+ end
+
+ class Group < BasicGroupDetails
+ expose :path, :description, :visibility
expose :lfs_enabled?, as: :lfs_enabled
expose :avatar_url do |group, options|
group.avatar_url(only_path: false)
end
- expose :web_url
expose :request_access_enabled
expose :full_name, :full_path
@@ -965,6 +970,13 @@ module API
options[:current_user].authorized_projects.where(id: runner.projects)
end
end
+ expose :groups, with: Entities::BasicGroupDetails do |runner, options|
+ if options[:current_user].admin?
+ runner.groups
+ else
+ options[:current_user].authorized_groups.where(id: runner.groups)
+ end
+ end
end
class RunnerRegistrationDetails < Grape::Entity
diff --git a/lib/api/runner.rb b/lib/api/runner.rb
index 4d4fbe50f9f..49d9b0b1b4f 100644
--- a/lib/api/runner.rb
+++ b/lib/api/runner.rb
@@ -25,8 +25,11 @@ module API
# Create shared runner. Requires admin access
Ci::Runner.create(attributes.merge(is_shared: true))
elsif project = Project.find_by(runners_token: params[:token])
- # Create a specific runner for project.
+ # Create a specific runner for the project
project.runners.create(attributes)
+ elsif group = Group.find_by(runners_token: params[:token])
+ # Create a specific runner for the group
+ group.runners.create(attributes)
end
break forbidden! unless runner
diff --git a/lib/api/runners.rb b/lib/api/runners.rb
index 5f2a9567605..ef4ec3f4800 100644
--- a/lib/api/runners.rb
+++ b/lib/api/runners.rb
@@ -199,6 +199,7 @@ module API
forbidden!("Runner is shared") if runner.is_shared?
forbidden!("Runner associated with more than one project") if runner.projects.count > 1
+ forbidden!("Runner associated with more that one group") if runner.groups.count > 1
forbidden!("No access granted") unless user_can_access_runner?(runner)
end
diff --git a/lib/api/v3/runners.rb b/lib/api/v3/runners.rb
index c6d9957d452..24e10128b79 100644
--- a/lib/api/v3/runners.rb
+++ b/lib/api/v3/runners.rb
@@ -54,6 +54,7 @@ module API
forbidden!("Runner is shared") if runner.is_shared?
forbidden!("Runner associated with more than one project") if runner.projects.count > 1
+ forbidden!("Runner associated with more that one group") if runner.groups.count > 1
forbidden!("No access granted") unless user_can_access_runner?(runner)
end