diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-10-23 18:15:13 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-10-26 11:23:11 +0100 |
commit | 6db014987d3c9cd4595adad70bb8a11ccacf9545 (patch) | |
tree | 581e3a1d9b93e0c5f9b9f442aaea3dc0fbeb72e0 /app | |
parent | f66ec1bc8157e5481ba23660b226267293c85129 (diff) | |
download | gitlab-ce-6db014987d3c9cd4595adad70bb8a11ccacf9545.tar.gz |
Fix specific runner visibility
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/runners_controller.rb | 9 | ||||
-rw-r--r-- | app/models/ci/runner.rb | 1 | ||||
-rw-r--r-- | app/models/user.rb | 23 |
3 files changed, 19 insertions, 14 deletions
diff --git a/app/controllers/projects/runners_controller.rb b/app/controllers/projects/runners_controller.rb index deb07a21416..bfbcf2567f3 100644 --- a/app/controllers/projects/runners_controller.rb +++ b/app/controllers/projects/runners_controller.rb @@ -6,11 +6,10 @@ class Projects::RunnersController < Projects::ApplicationController layout 'project_settings' def index - @runners = @ci_project.runners.order('id DESC') - @specific_runners = - Ci::Runner.specific.includes(:runner_projects). - where(Ci::RunnerProject.table_name => { project_id: current_user.authorized_projects } ). - where.not(id: @runners).order("#{Ci::Runner.table_name}.id DESC").page(params[:page]).per(20) + @runners = @ci_project.runners.ordered + @specific_runners = current_user.ci_authorized_runners. + where.not(id: @ci_project.runners). + ordered.page(params[:page]).per(20) @shared_runners = Ci::Runner.shared.active @shared_runners_count = @shared_runners.count(:all) end diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 1b3669f1b7a..b719ad3c87e 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -36,6 +36,7 @@ module Ci scope :active, ->() { where(active: true) } scope :paused, ->() { where(active: false) } scope :online, ->() { where('contacted_at > ?', LAST_CONTACT_TIME) } + scope :ordered, ->() { order(id: :desc) } acts_as_taggable diff --git a/app/models/user.rb b/app/models/user.rb index 7e4321d5376..c72beacbf0f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -401,15 +401,17 @@ class User < ActiveRecord::Base end end + def authorized_projects_id + @authorized_projects_id ||= begin + project_ids = personal_projects.pluck(:id) + project_ids.push(*groups_projects.pluck(:id)) + project_ids.push(*projects.pluck(:id).uniq) + end + end # Projects user has access to def authorized_projects - @authorized_projects ||= begin - project_ids = personal_projects.pluck(:id) - project_ids.push(*groups_projects.pluck(:id)) - project_ids.push(*projects.pluck(:id).uniq) - Project.where(id: project_ids) - end + @authorized_projects ||= Project.where(id: authorized_projects_id) end def owned_projects @@ -768,11 +770,14 @@ class User < ActiveRecord::Base end def ci_authorized_projects - @ci_authorized_projects ||= Ci::Project.where(gitlab_id: authorized_projects) + @ci_authorized_projects ||= Ci::Project.where(gitlab_id: authorized_projects_id) end def ci_authorized_runners - Ci::Runner.specific.includes(:runner_projects). - where(ci_runner_projects: { project_id: ci_authorized_projects } ) + @ci_authorized_runners ||= begin + runner_ids = Ci::RunnerProject.joins(:project). + where(ci_projects: { gitlab_id: authorized_projects_id }).select(:runner_id) + Ci::Runner.specific.where(id: runner_ids) + end end end |