fix eportfolio export cleanup if export has been re-uploaded to canvas

fixes CNVS-15885

test plan:
- create an eportfolio
- export it
- uploade the exported zip back to your user file space
- add more entries to the eportfolio
- export it again
- it should work

Change-Id: Icfc540e8e2ccffdb8c7ebafe0f6db43320138260
Reviewed-on: https://gerrit.instructure.com/42188
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Sean Lewis <slewis@instructure.com>
Reviewed-by: Mike Nomitch <mnomitch@instructure.com>
Product-Review: Simon Williams <simon@instructure.com>
This commit is contained in:
Simon Williams 2014-10-01 16:22:15 -06:00
parent ef4de34d5b
commit 37d86c00be
2 changed files with 42 additions and 3 deletions

View File

@ -150,11 +150,11 @@ class EportfoliosController < ApplicationController
zip_filename = "eportfolio.zip"
@portfolio = Eportfolio.find(params[:eportfolio_id])
if authorized_action(@portfolio, @current_user, :update)
@attachments = @portfolio.attachments.where(display_name: zip_filename, workflow_state: ['to_be_zipped', 'zipping', 'zipped', 'unattached']).order(:created_at).to_a
@attachments = @portfolio.attachments.not_deleted.where(display_name: zip_filename, workflow_state: ['to_be_zipped', 'zipping', 'zipped', 'unattached']).order(:created_at).to_a
@attachment = @attachments.pop
@attachments.each{|a| a.destroy! }
@attachments.each{|a| a.related_attachments.exists? ? a.destroy : a.destroy! }
if @attachment && (@attachment.created_at < 1.hour.ago || @attachment.created_at < (@portfolio.eportfolio_entries.map{|s| s.updated_at}.compact.max || @attachment.created_at))
@attachment.destroy!
@attachment.related_attachments.exists? ? @attachment.destroy : @attachment.destroy!
@attachment = nil
end

View File

@ -280,4 +280,43 @@ describe EportfoliosController do
feed.entries.all?{|e| e.authors.present?}.should be_true
end
end
describe "GET 'export'" do
before(:once) do
eportfolio
@old_zipfile = @portfolio.attachments.build(:display_name => "eportfolio.zip")
@old_zipfile.workflow_state = 'to_be_zipped'
@old_zipfile.file_state = '0'
@old_zipfile.save!
Attachment.where(id: @old_zipfile).update_all(created_at: 1.day.ago)
end
it "should hard delete old zips if there are no assiciated attachments" do
@portfolio.attachments.count.should == 1
@old_zipfile.related_attachments.exists?.should be_false
user_session(@user)
get 'export', :eportfolio_id => @portfolio.id
@portfolio.reload
@portfolio.attachments.count.should == 1
@portfolio.attachments.first.id.should_not == @old_zipfile.id
end
it "should soft delete old zips if there are assiciated attachments" do
@portfolio.attachments.count.should == 1
cloned_att = @old_zipfile.clone_for(@user)
cloned_att.workflow_state = 'to_be_zipped'
cloned_att.file_state = '0'
cloned_att.save!
@old_zipfile.reload.related_attachments.exists?.should be_true
user_session(@user)
get 'export', :eportfolio_id => @portfolio.id
@portfolio.reload
@portfolio.attachments.count.should == 2
@portfolio.attachments.map(&:file_state).should include "deleted"
end
end
end