diff --git a/app/assets/stylesheets/design/custom.scss b/app/assets/stylesheets/design/custom.scss index dbd61fe82..edc3f3c47 100644 --- a/app/assets/stylesheets/design/custom.scss +++ b/app/assets/stylesheets/design/custom.scss @@ -814,3 +814,9 @@ div#git_help_data p { .center { text-align: center; } + +.zip { + float: left; + margin-left: 5px; + margin-top: 11px; +} diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 8f9a949ad..dc9bd9acb 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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) diff --git a/app/models/ability.rb b/app/models/ability.rb index 3c9db3a8d..17eadf3bc 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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} diff --git a/app/views/projects/_repo_block.html.haml b/app/views/projects/_repo_block.html.haml index 0e9a26b07..7edfb02dc 100644 --- a/app/views/projects/_repo_block.html.haml +++ b/app/views/projects/_repo_block.html.haml @@ -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") diff --git a/config/routes.rb b/config/routes.rb index 20e8e1dcd..70f523a8d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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"