Merge pull request #121 from abf/rosa-build:120-separate_downloads

#120 Support separate downloads storage
This commit is contained in:
warpc 2013-05-07 14:51:39 +04:00
commit d3e144239c
10 changed files with 22 additions and 50 deletions

View File

@ -77,12 +77,10 @@ module BuildListsHelper
end
end
def container_url(full_path = true, build_list = @build_list)
p = ''
p << "http://#{request.host_with_port}" if full_path
p << "/downloads/#{build_list.save_to_platform.name}/container/#{build_list.id}"
p << "/#{build_list.arch.name}/#{build_list.save_to_repository.name}/release" if full_path && build_list.build_for_platform.distrib_type == 'mdv'
p.html_safe
def container_url(build_list = @build_list)
url = "#{APP_CONFIG['downloads_url']}/#{build_list.save_to_platform.name}/container/#{build_list.id}"
url << "/#{build_list.arch.name}/#{build_list.save_to_repository.name}/release" if build_list.build_for_platform.distrib_type == 'mdv'
url.html_safe
end
def can_publish_in_future?(bl)

View File

@ -412,10 +412,10 @@ class BuildList < ActiveRecord::Base
repos |= ['146'] if build_for_platform_id == 376
include_repos_hash = {}.tap do |h|
Repository.where(:id => (repos | (extra_repositories || [])) ).each do |repo|
path = repo.platform.public_downloads_url(nil, arch.name, repo.name)
path = repo.platform.public_downloads_url(arch.name, repo.name)
# path.gsub!(/^http:\/\/(0\.0\.0\.0|localhost)\:[\d]+/, 'https://abf.rosalinux.ru') unless Rails.env.production?
# Path looks like:
# http://abf.rosalinux.ru/downloads/rosa-server2012/repository/x86_64/base/
# http://abf-downloads.rosalinux.ru/rosa-server2012/repository/x86_64/base/
# so, we should append:
# - release
# - updates
@ -425,7 +425,7 @@ class BuildList < ActiveRecord::Base
end
host = EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
BuildList.where(:id => extra_build_lists).each do |bl|
path = "http://#{host}/downloads/#{bl.save_to_platform.name}/container/"
path = "#{APP_CONFIG['downloads_url']}/#{bl.save_to_platform.name}/container/"
path << "#{bl.id}/#{bl.arch.name}/#{bl.save_to_repository.name}/release"
include_repos_hash["container_#{bl.id}"] = path
end

View File

@ -1,6 +1,6 @@
# -*- encoding : utf-8 -*-
class Platform < ActiveRecord::Base
VISIBILITIES = ['open', 'hidden']
VISIBILITIES = ['open']#, 'hidden'] # Disable support hidden platforms.
belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id'
belongs_to :owner, :polymorphic => true
@ -57,20 +57,17 @@ class Platform < ActiveRecord::Base
def urpmi_list(host = nil, pair = nil, add_commands = true, repository_name = 'main')
host ||= default_host
blank_pair = {:login => 'login', :pass => 'password'}
pair = blank_pair if pair.blank?
urpmi_commands = ActiveSupport::OrderedHash.new
# TODO: rename method or create separate methods for mdv and rhel
# Platform.main.opened.where(:distrib_type => APP_CONFIG['distr_types'].first).each do |pl|
Platform.main.opened.each do |pl|
urpmi_commands[pl.name] = {}
local_pair = pl.id != self.id ? blank_pair : pair
head = hidden? ? "http://#{local_pair[:login]}@#{local_pair[:pass]}:#{host}/private/" : "http://#{host}/downloads/"
# FIXME should support restricting access to the hidden platform
Arch.all.each do |arch|
tail = "/#{arch.name}/#{repository_name}/release"
command = add_commands ? "urpmi.addmedia #{name} " : ''
command << "#{head}#{name}/repository/#{pl.name}#{tail}"
command << "#{APP_CONFIG['downloads_url']}/#{name}/repository/#{pl.name}#{tail}"
urpmi_commands[pl.name][arch.name] = command
end
end
@ -94,21 +91,8 @@ class Platform < ActiveRecord::Base
Rails.root.join("public", "downloads", name)
end
def prefix_url(pub, options = {})
options[:host] ||= default_host
pub ? "http://#{options[:host]}/downloads" : "http://#{options[:login]}:#{options[:password]}@#{options[:host]}/private"
end
def public_downloads_url(host = nil, arch = nil, repo = nil, suffix = nil)
downloads_url prefix_url(true, :host => host), arch, repo, suffix
end
def private_downloads_url(login, password, host = nil, arch = nil, repo = nil, suffix = nil)
downloads_url prefix_url(false, :host => host, :login => login, :password => password), arch, repo, suffix
end
def downloads_url(prefix, arch = nil, repo = nil, suffix = nil)
"#{prefix}/#{name}/repository/".tap do |url|
def public_downloads_url(arch = nil, repo = nil, suffix = nil)
"#{APP_CONFIG['downloads_url']}/#{name}/repository/".tap do |url|
url << "#{arch}/" if arch.present?
url << "#{repo}/" if repo.present?
url << "#{suffix}/" if suffix.present?

View File

@ -119,10 +119,6 @@ class ProductBuildList < ActiveRecord::Base
[BUILD_STARTED, BUILD_PENDING].include? status
end
def container_path
"/downloads/#{product.platform.name}/product/#{id}/"
end
def event_log_message
{:product => product.name}.inspect
end

View File

@ -6,7 +6,7 @@ json.build_list do |json|
json.build_log_url log_build_list_path(@build_list)
if @build_list.container_published?
json.container_path container_url(false)
json.container_path container_url
else
json.container_path ''
end
@ -65,7 +65,7 @@ json.build_list do |json|
extra_build_lists = BuildList.where(:id => @build_list.extra_build_lists)
json.extra_build_lists extra_build_lists do |json_extra_build_lists, bl|
json_extra_build_lists.(bl, :id, :status)
json_extra_build_lists.container_path container_url(false, bl)
json_extra_build_lists.container_path container_url(bl)
json_extra_build_lists.url api_v1_build_list_path(bl, :format => :json)
end

View File

@ -8,12 +8,9 @@
%h3= t("layout.build_lists.main_data")
.leftlist= t("activerecord.attributes.build_list.container_path")
.rightlist
- if @build_list.build_published?
= raw "%s %s" % [t("layout.build_lists.container_published"),
link_to("#{@build_list.save_to_platform.name}/#{@build_list.save_to_repository.name}",
[@build_list.save_to_platform, @build_list.save_to_repository])]
- if @build_list.container_published?
= link_to container_url, container_url
-url = container_url
= link_to url, url
- elsif @build_list.container_publish?
= t("layout.build_lists.creating")
.both

View File

@ -21,7 +21,7 @@ common: &common
facebook:
id: 'APP_ID'
secret: 'APP_SECRET'
downloads_url: 'http://abf-downloads.rosalinux.ru'
wiki_formats:
markdown: "Markdown"
textile: "Textile"

View File

@ -1,2 +1,4 @@
# -*- encoding : utf-8 -*-
APP_CONFIG = YAML.load_file("#{Rails.root}/config/application.yml")[Rails.env]
APP_CONFIG = YAML.load_file("#{Rails.root}/config/application.yml")[Rails.env]
# Remove '/' from the end of url
APP_CONFIG.keys.select {|key| key =~ /_url\Z/}.each {|key| APP_CONFIG[key] = APP_CONFIG[key].chomp('/')}

View File

@ -4,7 +4,7 @@ class ReservedNameValidator < ActiveModel::EachValidator
app apps archive archives auth
blog
config connect contact create commit commits
dashboard delete direct_messages downloads
dashboard delete direct_messages download downloads
edit email
faq favorites feed feeds follow followers following
help home
@ -20,7 +20,7 @@ class ReservedNameValidator < ActiveModel::EachValidator
signup sign-up sign_up signin sign-in sign_in signout sign-out sign_out
sitemap ssl subscribe
teams terms test tour trends tree
unfollow unsubscribe url user
unfollow unsubscribe upload uploads url user
widget widgets wiki
xfn xmpp
}

View File

@ -49,7 +49,6 @@ describe CanCan do
end
context 'Site guest' do
let(:hidden_platform) { FactoryGirl.create(:platform, :visibility => 'hidden') }
let(:register_request) { FactoryGirl.create(:register_request) }
before(:each) do
@ -60,10 +59,6 @@ describe CanCan do
@ability.should_not be_able_to(:read, open_platform)
end
it 'should not be able to read hidden platform' do
@ability.should_not be_able_to(:read, hidden_platform)
end
[:publish, :cancel, :reject_publish, :create_container].each do |action|
it "should not be able to #{ action } build list" do
@ability.should_not be_able_to(action, BuildList)