Commit 8d10f856 authored by azul's avatar azul

simplify: use only one controller for the one group archive

parent 33a6080b
......@@ -5,23 +5,26 @@ class Group::ArchiveController < Group::BaseController
def show
authorize @group, :admin?
redirect_to group_archives_url(@group) unless @group.archive
send_file @group.archive.zipfile,
type: 'application/zip',
charset: 'utf-8',
status: 202
@request = RequestToCreateGroupArchive.to_group(@group).pending.last
@archive = @group.archive
respond_to do |format|
format.html
format.zip do
send_file @archive.zipfile, type: 'application/zip', charset: 'utf-8'
end
end
end
def create
authorize @group, :create_archive?
Delayed::Job.enqueue GroupArchiveJob.new(@group, current_user, I18n.locale)
redirect_to group_archives_url(@group)
redirect_to group_archive_url(@group)
end
def destroy
authorize @group, :admin?
@group.archive.destroy
redirect_to group_archives_url(@group)
redirect_to group_archive_url(@group)
end
end
class Group::ArchivesController < Group::BaseController
def index
authorize @group, :admin?
@request = Request.to_group(@group).pending.where(type: RequestToCreateGroupArchive).last
@archive = @group.archive
end
end
......@@ -144,7 +144,7 @@ module Group::LinksHelper
end
def reload_archive_page_link
link_to :group_archive_settings_reload.t, group_archives_path(@group)
link_to :group_archive_settings_reload.t, group_archive_path(@group)
end
def request_to_create_group_archive
......@@ -162,7 +162,9 @@ module Group::LinksHelper
def download_group_archive_link
if logged_in? && policy(@group).admin?
link_to @group.archive.zipname, group_archive_path(@group)
link_to @group.archive.zipname,
group_archive_path(@group, format: :zip),
class: 'btn btn-default'
end
end
end
......@@ -5,10 +5,11 @@ GroupArchiveJob = Struct.new(:group, :user, :language) do
I18n.locale = language
end
def perform()
# although we should only have one archive per group, we make sure
# to get the newest
archive = Group::Archive.order('created_at DESC').find_by(group: group, created_by_id: user.id)
def perform
# although we should only have one archive per group,
# we make sure to get the newest
archive = Group::Archive.order(created_at: :desc).
find_by(group: group, created_by_id: user.id)
archive.process if archive
end
......
......@@ -38,9 +38,6 @@ class Group::Archive < ActiveRecord::Base
self.filename = zipname
self.state = 'success'
save!
rescue Exception => exc
Rails.logger.error 'Archive could not be created: ' + exc.message
Rails.logger.warn exc.backtrace.join("\n")
end
def zipfile
......
%html
%head
%meta{ charset: 'utf8' }
%link{ rel: :stylesheet, type: :"text/css", href: css_file }
%link{ rel: :stylesheet, type: :"text/css", href: @css_file }
%body
%img{ src: "assets/#{group.name}.jpg", alt: 'avatar', height: '64', width: '64' }
%h1= "Archive of #{group.display_name}"
%img{ src: "assets/#{@group.name}.jpg", alt: 'avatar', height: '64', width: '64' }
%h1= "Archive of #{@group.display_name}"
-# Todo: hide if wikis are empty
-if group.private_wiki&.has_content?
-if @group.private_wiki&.has_content?
%h3= :private_wiki.t
%p= group.private_wiki.body_html
- if group.public_wiki&.has_content?
%p= @group.private_wiki.body_html
- if @group.public_wiki&.has_content?
%h3= :public_wiki.t
%p= group.public_wiki.body_html
%p= @group.public_wiki.body_html
%h2= :pages.t
%table
%tr
%th= :title.t
%th= :updated
- pages.each do |page|
- @pages.each do |page|
%tr
%td
%a{ href: "#{page.name_url}.html" } #{page.title}
......@@ -27,11 +27,11 @@
#{page.updated_by.display_name}
%td
#{page.updated_at}
- if group.real_committees.any?
- if @group.real_committees.any?
%h2= :committees.t
- group.real_committees.each do |committee|
- @group.real_committees.each do |committee|
-# unless group_pages(committee).empty?
%a{ href: "#{committee.name}/index.html" } #{committee.display_name}
- if group.parent and not group.council?
- if @group.parent and not @group.council?
%h2= h(:back_to_group.t)
%a{ href: "../index.html"} #{group.parent.display_name}
%a{ href: "../index.html"} #{@group.parent.display_name}
= render 'group/archives/page',
= render 'page',
page: @page,
type: :pages,
wiki_html: @wiki_html
......@@ -8,7 +8,7 @@
- else
- f.row do |r|
- r.label :download.t
- r.input link_line(download_group_archive_link, :download_archive.t)
- r.input download_group_archive_link
- r.info "Archived by #{@archive.archived_by} on #{friendly_date(@archive.updated_at)}"
- if @archive.excluded_assets.any?
- f.row do |r|
......
......@@ -19,6 +19,6 @@
%h2= h(:back_to_group.t)
%a{ href: "#{@group.parent.name}.html"} #{@group.parent.display_name}
= render partial: 'group/archives/page',
= render partial: 'page',
collection: @pages,
locals: {type: :singlepage}
......@@ -26,7 +26,6 @@ en:
## ARCHIVE
archive: Archive
archives: Archives
archive_info: "Zip file containing all wiki pages and discussion pages in HTML format and all uploaded files.<br/>Shortly after creation, the archive will be available for download for all group admins. (If a council exists, only council members can access the archive.)"
archive_confirmation: "Are you sure you want to create an archive of %{thing} for download? This action will not delete any content."
archive_destroy_confirmation: "Are you sure you want to delete the archive of %{thing}?"
......
......@@ -157,7 +157,6 @@ Crabgrass::Application.routes.draw do
resource :profile, only: %i[edit update]
resource :structure, only: %i[show new create update]
resource :archive, only: %i[show create destroy], controller: 'archive'
get 'archives', as: 'archives', to: 'archives#index'
end
##
......
......@@ -249,7 +249,7 @@ define_navigation do
label { :settings.t }
icon :control
url { group_settings_path(@group) }
active { controller?('group/settings', 'group/permissions', 'group/profiles', 'group/structures', 'group/archives', 'group/requests', 'group/wikis', 'wiki/versions', 'wiki/diffs') }
active { controller?('group/settings', 'group/permissions', 'group/profiles', 'group/structures', 'group/archive', 'group/requests', 'group/wikis', 'wiki/versions', 'wiki/diffs') }
local_section :settings do
visible { may_admin?(@group) }
......@@ -286,11 +286,11 @@ define_navigation do
active { controller?('group/structures') }
end
local_section :archives do
local_section :archive do
visible { may_admin?(@group) }
label { :archives.t }
url { group_archives_path(@group, action: :index) }
active { controller?('group/archives') }
label { :archive.t }
url { group_archive_path(@group, action: :index) }
active { controller?('group/archive') }
end
local_section :requests do
......
require 'test_helper'
class Group::ArchiveControllerTest < ActionController::TestCase
fixtures :users, :groups
fixtures :all
def setup
@user = users(:blue)
......@@ -16,11 +16,29 @@ class Group::ArchiveControllerTest < ActionController::TestCase
Group::Archive.delete_all # FIXME: not working
end
def test_access_archive_page
login_as @user
get :show, params: { group_id: :recent_group }
assert_response :success
assert_select '.btn-primary'
end
def test_not_logged_in
get :show, params: { group_id: @group.to_param }
assert_not_found
end
def test_no_member
login_as :red
get :show, params: { group_id: @group.to_param }
assert_not_found
end
def test_download_archive
login_as @user
post :create, params: { group_id: :recent_group }
get :show, params: { group_id: :recent_group }
assert_response 202 # TODO: download file
assert_response 200 # TODO: download file
end
def test_show_not_logged_in
......
require 'test_helper'
class Group::ArchivesControllerTest < ActionController::TestCase
fixtures :users, :groups
def setup
@user = users(:blue)
@group = groups(:recent_group)
# FIXME: we should not need this. Deleting records in teardown
# of ArchiveControllerTest does not work properly
Group::Archive.delete_all
end
def test_access_archive_page
login_as @user
get :index, params: { group_id: :recent_group }
assert_response :success
assert_select '.btn-primary'
end
def test_not_logged_in
get :index, params: { group_id: @group.to_param }
assert_not_found
end
def test_no_member
login_as :red
get :index, params: { group_id: @group.to_param }
assert_not_found
end
end
......@@ -21,10 +21,10 @@ class GroupArchiveTest < IntegrationTest
login
visit '/recent_group'
click_on 'Settings'
click_on 'Archives'
click_on 'Archive'
click_on 'Create a new Archive'
# sleep 2
click_on 'Archives'
click_on 'Archive'
assert_content 'Download'
end
......@@ -33,7 +33,7 @@ class GroupArchiveTest < IntegrationTest
login
visit '/animals'
click_on 'Settings'
click_on 'Archives'
click_on 'Archive'
click_link 'Create a new Archive'
assert_content 'Request to create Group Archive'
logout
......@@ -44,7 +44,7 @@ class GroupArchiveTest < IntegrationTest
click_on 'Approve'
# sleep 2
click_on 'Settings'
click_on 'Archives'
click_on 'Archive'
assert_content 'animals.zip'
end
......@@ -53,9 +53,9 @@ class GroupArchiveTest < IntegrationTest
login
visit '/recent_group'
click_on 'Settings'
click_on 'Archives'
click_on 'Archive'
click_on 'Create a new Archive'
click_on 'Archives'
click_on 'Archive'
# sleep 2
click_on 'Destroy'
assert_no_content 'Destroy'
......@@ -66,15 +66,15 @@ class GroupArchiveTest < IntegrationTest
login
visit '/recent_group'
click_on 'Settings'
click_on 'Archives'
click_on 'Archive'
click_on 'Create a new Archive'
click_on 'Archives'
click_on 'Archive'
# sleep 2
click_on 'Destroy'
assert_no_content 'Destroy'
click_on 'Create a new Archive'
# sleep 2
click_on 'Archives'
click_on 'Archive'
assert_content 'Download'
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment