Skip to content

Commit c378afc

Browse files
committed
upload submissions to submissions folder if feature is enabled
test plan: - enable the submissions folder feature - create an assignment that accepts file submissions - submit the assignment by uploading a file - ensure it is uploaded to the read-only Submissions folder - repeat this test with a group assignment (NOTE: submitting an assignment by choosing an alredy-uploaded file will not yet copy the file into the Submissions folder; this is coming up in another commit) closes CNVS-28138 Change-Id: I836b26324cfa87d9a3ea62ca80569bcdfbb3b671 Reviewed-on: https://gerrit.instructure.com/77922 Tested-by: Jenkins Reviewed-by: James Williams <jamesw@instructure.com> QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
1 parent 59821b6 commit c378afc

6 files changed

Lines changed: 54 additions & 2 deletions

File tree

app/controllers/files_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ def create_pending
750750
@folder = @context.folders.active.where(id: params[:attachment][:folder_id]).first
751751
return unless authorized_action(@folder, @current_user, :manage_contents)
752752
end
753+
if intent == 'submit' && context.respond_to?(:submissions_folder) &&
754+
@asset && @asset.context.root_account.feature_enabled?(:submissions_folder)
755+
@folder ||= @context.submissions_folder(@asset.context)
756+
end
753757
@folder ||= Folder.unfiled_folder(@context)
754758
@attachment.folder_id = @folder.id
755759
end

app/controllers/submissions_api_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def create_file
457457
permission = :nothing if @user != @current_user
458458
# we don't check quota when uploading a file for assignment submission
459459
if authorized_action(@assignment, @current_user, permission)
460-
api_attachment_preflight(@user, request, :check_quota => false)
460+
api_attachment_preflight(@user, request, :check_quota => false, :submission_context => @context)
461461
end
462462
end
463463

app/models/group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def favorite_for_user?(user)
733733
user.favorites.where(:context_type => 'Group', :context_id => self).exists?
734734
end
735735

736-
def submissions_folder
736+
def submissions_folder(_course = nil)
737737
return @submissions_folder if @submissions_folder
738738
Folder.unique_constraint_retry do
739739
@submissions_folder = self.folders.where(parent_folder_id: Folder.root_folders(self).first, submission_context_code: 'root')

lib/api/v1/attachment.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ def api_attachment_preflight(context, request, opts = {})
151151
end
152152
if @attachment.folder
153153
return unless authorized_action(@attachment.folder, @current_user, :manage_contents)
154+
elsif opts[:submission_context] && opts[:submission_context].root_account.feature_enabled?(:submissions_folder)
155+
@attachment.folder = context.submissions_folder(opts[:submission_context]) if context.respond_to?(:submissions_folder)
154156
end
155157
duplicate_handling = check_duplicate_handling_option(params)
156158
if opts[:check_quota]

spec/apis/v1/submissions_api_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,6 +2863,18 @@ def has_query_exemption?
28632863
json = api_call(:post, "/api/v1/courses/#{@course.id}/assignments/#{@assignment.id}/submissions/#{@student2.id}/files",
28642864
{ :controller => "submissions_api", :action => "create_file", :format => "json", :course_id => @course.to_param, :assignment_id => @assignment.to_param, :user_id => @student2.to_param }, {}, {}, { :expected_status => 401 })
28652865
end
2866+
2867+
it "should upload to a student's Submissions folder if the feature is enabled" do
2868+
@course.root_account.enable_feature! :submissions_folder
2869+
preflight(name: 'test.txt', size: 12345, content_type: 'text/plain')
2870+
f = Attachment.last.folder
2871+
expect(f.submission_context_code).to eq @course.asset_string
2872+
end
2873+
2874+
it "should not do so otherwise" do
2875+
preflight(name: 'test.txt', size: 12345, content_type: 'text/plain')
2876+
expect(Attachment.last.folder).not_to be_for_submissions
2877+
end
28662878
end
28672879

28682880
it "should reject invalid urls" do

spec/controllers/files_controller_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,40 @@ def submit_file
920920
expect(response.status).to eq 401
921921
end
922922

923+
it "creates a file in the submissions folder if intent=='submit' and the feature is enabled" do
924+
@course.root_account.enable_feature! :submissions_folder
925+
user_session(@student)
926+
assignment = @course.assignments.create!(:submission_types => 'online_upload')
927+
post 'create_pending', {:attachment => {
928+
:context_code => assignment.context_code,
929+
:asset_string => assignment.asset_string,
930+
:filename => 'test.txt',
931+
:intent => 'submit'
932+
}}
933+
f = assigns[:attachment].folder
934+
expect(f.submission_context_code).to eq @course.asset_string
935+
end
936+
937+
it "uses a submissions folder for group assignments when the feature is enabled" do
938+
@course.root_account.enable_feature! :submissions_folder
939+
user_session(@student)
940+
category = group_category
941+
assignment = @course.assignments.create(:group_category => category, :submission_types => 'online_upload')
942+
group = category.groups.create(:context => @course)
943+
group.add_user(@student)
944+
user_session(@student)
945+
post 'create_pending', {:attachment => {
946+
:context_code => @course.asset_string,
947+
:asset_string => assignment.asset_string,
948+
:intent => 'submit',
949+
:filename => "bob.txt"
950+
}}
951+
expect(response).to be_success
952+
expect(assigns[:attachment]).not_to be_nil
953+
expect(assigns[:attachment].context).to eq group
954+
expect(assigns[:attachment].folder).to be_for_submissions
955+
end
956+
923957
context "sharding" do
924958
specs_require_sharding
925959

0 commit comments

Comments
 (0)