[refs #385] zip archive

This commit is contained in:
Alexander Machehin 2012-04-12 00:29:08 +06:00
parent d2612e63b6
commit 770030e180
5 changed files with 21 additions and 0 deletions

View File

@ -814,3 +814,9 @@ div#git_help_data p {
.center {
text-align: center;
}
.zip {
float: left;
margin-left: 5px;
margin-top: 11px;
}

View File

@ -86,6 +86,16 @@ class ProjectsController < ApplicationController
redirect_to projects_path
end
def archive
treeish = params[:treeish].presence || @project.default_branch
format = params[:format] || 'zip'
file = Tempfile.new(treeish, 'tmp')
system("cd #{@project.path}; git archive --format=#{format} -o #{file.path} #{treeish} >> /dev/null 2>&1")
file.close
send_file file.path, :disposition => 'attachment', :type => "application/#{format == 'tar' ? 'x-tar' : 'zip'}",
:filename => "#{@project.owner.uname}-#{@project.name}-#{treeish}.#{format}"
end
protected
def prepare_list(projects)

View File

@ -61,6 +61,7 @@ class Ability
can(:destroy, Project) {|project| owner? project}
can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.objects.exists?(:object_type => 'User', :object_id => user.id, :role => 'admin')}
can :remove_user, Project
can :archive, Project
can [:read, :owned], BuildList, :user_id => user.id
can [:read, :related], BuildList, :project => {:owner_type => 'User', :owner_id => user.id}

View File

@ -1,4 +1,6 @@
.description-top
.zip= link_to "ZIP", archive_path(project.id, 'zip', @treeish)
= text_field_tag :url, git_repo_url(project.git_repo_name), :class => 'name', :spellcheck => 'false', :readonly => true
.git_help ?
.role= can?(:write, project) ? t("layout.read_write_access") : t("layout.read_access")

View File

@ -154,6 +154,8 @@ Rosa::Application.routes.draw do
# Raw
get '/projects/:project_id/raw/:treeish/*path' => "git/blobs#raw", :defaults => {:treeish => :master}, :as => :raw, :format => false
get '/projects/:id/archive/:format/tree/:treeish' => "projects#archive", :defaults => {:treeish => :master}, :as => :archive, :format => /zip|tar/
# Core callbacks
match 'build_lists/publish_build', :to => "build_lists#publish_build"
match 'build_lists/status_build', :to => "build_lists#status_build"