This commit is contained in:
Vokhmin Alexey V 2015-04-14 23:21:37 +03:00
parent 07ae486d5b
commit 04b5b77f7c
5 changed files with 6 additions and 11 deletions

View File

@ -294,8 +294,9 @@ module BuildListsHelper
end end
def default_extra_repos(project) def default_extra_repos(project)
project.repositories.joins(:platform).accessible_by(current_ability, :read) scope = project.repositories.joins(:platform).where(platforms: { platform_type: 'personal' })
.where(platforms: { platform_type: 'personal' }).map do |extra| scope = PlatformPolicy::Scope.new(current_user, scope).show
scope.map do |extra|
{ {
id: extra.id, id: extra.id,
platform_id: extra.platform.id, platform_id: extra.platform.id,

View File

@ -724,10 +724,6 @@ class BuildList < ActiveRecord::Base
save save
end end
# def current_ability
# @current_ability ||= Ability.new(user)
# end
def prepare_extra_repositories def prepare_extra_repositories
if save_to_platform && save_to_platform.main? if save_to_platform && save_to_platform.main?
self.extra_repositories = nil self.extra_repositories = nil

View File

@ -19,9 +19,7 @@ class Search < Struct.new(:query, :user, :paginate_params)
User.opened User.opened
else else
klass = type.classify.constantize klass = type.classify.constantize
# scope_policy(type.classify.constantize).accessible_by(ability, :show) "#{klass}Policy::Scope".constantize.new(user, klass).show
"#{klass}Policy::Scope".classify.constantize.new(user, klass).show
# policy_scope(type.classify.constantize).show
end end
scope.search(query). scope.search(query).
search_order. search_order.

View File

@ -3,7 +3,7 @@
.row.offset10 ng-controller = 'BuildListsController' ng-init = 'init()' ng-cloak = true .row.offset10 ng-controller = 'BuildListsController' ng-init = 'init()' ng-cloak = true
= hidden_field_tag :name_with_owner, @project.try(:name_with_owner) = hidden_field_tag :name_with_owner, @project.try(:name_with_owner)
.col-lg-2.col-sm-12 .col-lg-2.col-sm-12
-if @project and can?(:create, @project.build_lists.build) -if @project && policy(@project.build_lists.build).create?
button.btn.btn-primary.btn-block[ id = 'filter_new_build' button.btn.btn-primary.btn-block[ id = 'filter_new_build'
type = 'button' type = 'button'

View File

@ -12,7 +12,7 @@ module Grack
return ::Rack::Auth::Basic.new(@app) do |u, p| return ::Rack::Auth::Basic.new(@app) do |u, p|
user = User.auth_by_token_or_login_pass(u, p) and user = User.auth_by_token_or_login_pass(u, p) and
ability = ::Ability.new(user) and ability.can?(action, project) and ability = ProjectPolicy.new(user, project).send("#{action}?") and
ENV['GL_ID'] = "user-#{user.id}" and ENV['GL_ID'] = "user-#{user.id}" and
ENV['GL_REPO_NAME'] = project.path ENV['GL_REPO_NAME'] = project.path
end.call(env) unless project.public? && read? # need auth end.call(env) unless project.public? && read? # need auth