fix exported attachments for teachers with concluded enrollment

closes CLAB-36
flag=none

Test Plan:
Prerequisites: A course with a concluded teacher enrollment

- Upload two files: set one file's availability to Publish and the other file's availability to Only available with link
- Act as the concluded teacher
- Export the course (using the Content Export page)
- Download and observe the exported data
    > both files are included under the web_resources folder

Change-Id: I01a89ae7ad67665aed34ef79b98223d6f22d96f0
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/347298
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Mysti Lilla <mysti@instructure.com>
QA-Review: Viktor Szpisják <viktor.szpisjak@instructure.com>
Product-Review: Endre Berki <endre.berki@instructure.com>
This commit is contained in:
Endre Berki 2024-05-14 17:25:16 +02:00
parent 61f1474687
commit bcea4f9805
2 changed files with 30 additions and 14 deletions

View File

@ -245,7 +245,7 @@ class ContentZipper
# 2. we're doing this inside a course context export, and are bypassing
# the user check (@check_user == false)
attachments =
if !@check_user || folder.context.grants_any_right?(@user, *RoleOverride::GRANULAR_FILE_PERMISSIONS)
if !@check_user || folder.context.grants_any_right?(@user, :read_as_admin, :manage_contents, *RoleOverride::GRANULAR_FILE_PERMISSIONS)
folder.active_file_attachments
else
folder.visible_file_attachments

View File

@ -354,6 +354,14 @@ describe ContentZipper do
@attachment.context = folder.reload
end
let(:visible_files) do
["visible.png", "visible/sub-vis.png"].sort
end
let(:all_files) do
(visible_files + ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible/sub-locked.png", "locked.png"]).sort
end
def zipped_files_for_user(user = nil, check_user = true)
@attachment.user_id = user.id if user
@attachment.save!
@ -373,22 +381,30 @@ describe ContentZipper do
@course.save
end
it "gives logged in students some files" do
expect(zipped_files_for_user(@user)).to eq ["visible.png", "visible/sub-vis.png"].sort
it "gives logged in students visible files" do
expect(zipped_files_for_user(@user)).to eq visible_files
end
context("for a logged in teacher with a concluded enrollment") do
it "gives the teacher all files" do
concluded_teacher = User.create!
@course.enroll_teacher(concluded_teacher, enrollment_state: :completed)
expect(zipped_files_for_user(concluded_teacher)).to eq all_files
end
end
it "gives logged in teachers all files" do
expect(zipped_files_for_user(@teacher)).to eq ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
expect(zipped_files_for_user(@teacher)).to eq all_files
end
end
context "in a private course" do
it "gives logged in students some files" do
expect(zipped_files_for_user(@user)).to eq ["visible.png", "visible/sub-vis.png"].sort
it "gives logged in students visible files" do
expect(zipped_files_for_user(@user)).to eq visible_files
end
it "gives logged in teachers all files" do
expect(zipped_files_for_user(@teacher)).to eq ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
expect(zipped_files_for_user(@teacher)).to eq all_files
end
it "gives logged out people no files" do
@ -396,7 +412,7 @@ describe ContentZipper do
end
it "gives all files if check_user=false" do
expect(zipped_files_for_user(nil, false)).to eq ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
expect(zipped_files_for_user(nil, false)).to eq all_files
end
end
@ -406,20 +422,20 @@ describe ContentZipper do
@course.save!
end
it "gives logged in students some files" do
expect(zipped_files_for_user(@user)).to eq ["visible.png", "visible/sub-vis.png"].sort
it "gives logged in students visible files" do
expect(zipped_files_for_user(@user)).to eq visible_files
end
it "gives logged in teachers all files" do
expect(zipped_files_for_user(@teacher)).to eq ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
expect(zipped_files_for_user(@teacher)).to eq all_files
end
it "gives logged out people the same thing as students" do
expect(zipped_files_for_user(nil)).to eq ["visible.png", "visible/sub-vis.png"].sort
it "gives logged out people visible files" do
expect(zipped_files_for_user(nil)).to eq visible_files
end
it "gives all files if check_user=false" do
expect(zipped_files_for_user(nil, false)).to eq ["locked/sub-locked-vis.png", "hidden/sub-hidden.png", "hidden.png", "visible.png", "visible/sub-locked.png", "visible/sub-vis.png", "locked.png"].sort
expect(zipped_files_for_user(nil, false)).to eq all_files
end
end
end