2012-07-17 09:02:56 +01:00
|
|
|
module Rosa
|
|
|
|
module Constraints
|
|
|
|
class Owner
|
|
|
|
def initialize(class_name, bang = false)
|
|
|
|
@class_name = class_name
|
|
|
|
@finder = 'find_by_insensitive_uname'
|
|
|
|
@finder << '!' if bang
|
|
|
|
end
|
|
|
|
|
|
|
|
def matches?(request)
|
|
|
|
@class_name.send(@finder, request.params[:uname]).present?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class AdminAccess
|
|
|
|
def self.matches?(request)
|
|
|
|
!!request.env['warden'].user.try(:admin?)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Treeish
|
|
|
|
def self.matches?(request)
|
2012-07-31 15:35:18 +01:00
|
|
|
if (params = request.path_parameters) && params[:treeish] # parse existing branch (tag) and path
|
2012-07-17 09:02:56 +01:00
|
|
|
branch_or_tag = begin
|
2014-03-25 19:18:00 +00:00
|
|
|
(p = Project.find_by_owner_and_name params[:name_with_owner]) &&
|
2012-08-02 15:54:34 +01:00
|
|
|
p.repo.branches_and_tags.map(&:name).sort{|a,b| b.length <=> a.length}.detect{|b| params[:treeish].start_with?(b)} ||
|
2012-07-17 09:02:56 +01:00
|
|
|
params[:treeish].split('/').first
|
|
|
|
end
|
|
|
|
if path = params[:treeish].sub(branch_or_tag, '')[1..-1] and path.present?
|
|
|
|
params[:path] = File.join([path, params[:path]].compact)
|
|
|
|
end
|
|
|
|
params[:treeish] = branch_or_tag
|
|
|
|
end
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|