Add Allowed File Extensions Variable Expansion
Added the `com.instructure.Assignment.allowedFileExtensions` variable extensions. If an assignment is present in the context of the current LTI placement/launch and has online_upload present as a submission_type, this new expansion variable will provide a comma separated list of allowed file extensions that can be used for submitting to the assignment. closes INTEROP-6909 flag = none test-plan: * Install the LTI 1.3 Test Tool with at least the homework submission placement. Make sure that you give set it up to use the new custom variable when you're configuring things. * Create an assignment with a file upload submission type. Limit the file types to whatever you want. Note that this must be a comma separated list. * Masquerade as a student and try to submit to the assignment through the tool. Ensure that the in the "https://purl.imsglobal.org/spec/lti/claim/custom" section, you can see that the variable was properly substituted with the list of valid file types. * Create another assignment that also uses file upload, but don't limit the file types. * Go to submit as a student and make sure that in the "https://purl.imsglobal.org/spec/lti/claim/custom" section, the variable was expanded to be an empty string, indicating no limits were imposed on file upload types. Change-Id: I4315ce1cfa98b034446cdc5bfc3f61d133412a5c Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/270094 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Evan Battaglia <ebattaglia@instructure.com> QA-Review: Xander Moffatt <xmoffatt@instructure.com> Product-Review: Karl Lloyd <karl@instructure.com>
This commit is contained in:
parent
f6be80547f
commit
61463046bf
|
@ -245,6 +245,18 @@ the `ext_lti_assignment_id` send in various launches and webhooks.
|
|||
```
|
||||
"9ae4170c-6b64-444d-9246-0b7dedd5f560"
|
||||
```
|
||||
## com.instructure.Assignment.allowedFileExtensions
|
||||
A comma separated list of the file extensions that are allowed for submitting to this
|
||||
assignment. If there are no limits on what files can be uploaded, an empty string will be
|
||||
returned. If the assignment does not allow file uploads as a submission type, then no
|
||||
substitution will be performed.
|
||||
|
||||
**Availability**: *when the tool is used to upload a file as an assignment submission*
|
||||
**Launch Parameter**: *com_instructure_assignment_allowed_file_extensions*
|
||||
|
||||
```
|
||||
"docx,pdf,txt"
|
||||
```
|
||||
## com.instructure.OriginalityReport.id
|
||||
The Canvas id of the Originality Report associated
|
||||
with the launch.
|
||||
|
|
|
@ -128,6 +128,8 @@ class RegisterExpansionHandler < YARD::Handlers::Ruby::Base
|
|||
"when launched as an assignment by a student"
|
||||
when 'EDITOR_GUARD'
|
||||
"when the tool is launched from the editor_button placement"
|
||||
when 'FILE_UPLOAD_GUARD'
|
||||
"when the tool is used to upload a file as an assignment submission"
|
||||
end
|
||||
|
||||
end.compact
|
||||
|
|
|
@ -84,6 +84,7 @@ module Lti
|
|||
ROLES_GUARD = -> { @current_user && (@context.is_a?(Course) || @context.is_a?(Account)) }
|
||||
CONTENT_TAG_GUARD = -> { @content_tag }
|
||||
ASSIGNMENT_GUARD = -> { @assignment }
|
||||
FILE_UPLOAD_GUARD = -> { !!@assignment && @assignment.submission_types.split(',').include?('online_upload') }
|
||||
COLLABORATION_GUARD = -> { @collaboration }
|
||||
MEDIA_OBJECT_GUARD = -> { @attachment && @attachment.media_object}
|
||||
USAGE_RIGHTS_GUARD = -> { @attachment && @attachment.usage_rights}
|
||||
|
@ -263,6 +264,21 @@ module Lti
|
|||
LTI_ASSIGN_ID,
|
||||
default_name: 'com_instructure_assignment_lti_id'
|
||||
|
||||
# A comma separated list of the file extensions that are allowed for submitting to this
|
||||
# assignment. If there are no limits on what files can be uploaded, an empty string will be
|
||||
# returned. If the assignment does not allow file uploads as a submission type, then no
|
||||
# substitution will be performed.
|
||||
#
|
||||
# @launch_parameter com_instructure_originality_report_id
|
||||
# @example
|
||||
# ```
|
||||
# "docx,pdf,txt"
|
||||
# ```
|
||||
register_expansion 'com.instructure.Assignment.allowedFileExtensions', [],
|
||||
-> { @assignment.allowed_extensions.join(',') },
|
||||
FILE_UPLOAD_GUARD,
|
||||
default_name: 'com_instructure_assignment_allowed_file_extensions'
|
||||
|
||||
# The Canvas id of the Originality Report associated
|
||||
# with the launch.
|
||||
# @launch_parameter com_instructure_originality_report_id
|
||||
|
|
|
@ -101,6 +101,7 @@ module Lti
|
|||
vnd.Canvas.submission.url
|
||||
Context.title
|
||||
com.instructure.Assignment.lti.id
|
||||
com.instructure.Assignment.allowedFileExtensions
|
||||
com.instructure.Person.name_sortable
|
||||
com.instructure.PostMessageToken
|
||||
com.instructure.Editor.contents
|
||||
|
|
|
@ -104,12 +104,17 @@ module Lti
|
|||
root_account,
|
||||
account,
|
||||
controller,
|
||||
variable_expander_opts
|
||||
)
|
||||
end
|
||||
let(:variable_expander_opts) do
|
||||
{
|
||||
current_user: user,
|
||||
tool: tool,
|
||||
originality_report: originality_report,
|
||||
editor_contents: editor_contents,
|
||||
editor_selection: editor_selection
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
describe ".deregister_expansion" do
|
||||
|
@ -489,6 +494,46 @@ module Lti
|
|||
expect(exp_hash[:test]).to eq 'api/lti/assignments/{assignment_id}/submissions/{submission_id}/originality_report'
|
||||
end
|
||||
|
||||
context 'com.instructure.Assignment.allowedFileExtensions' do
|
||||
let(:exp_hash) do
|
||||
{
|
||||
test: expansion
|
||||
}
|
||||
end
|
||||
let(:allowed_extensions) { 'docx,txt,pdf' }
|
||||
let(:course) { course_model }
|
||||
let(:assignment) { assignment_model(context: course) }
|
||||
let(:expansion) { '$com.instructure.Assignment.allowedFileExtensions'}
|
||||
let(:variable_expander_opts) { super().merge(context: course, assignment: assignment) }
|
||||
|
||||
it 'it expands when an assignment with online_upload submission type and extensions is present' do
|
||||
assignment.update!(allowed_extensions: allowed_extensions, submission_types: 'online_upload')
|
||||
variable_expander.expand_variables!(exp_hash)
|
||||
expect(exp_hash[:test]).to eq allowed_extensions
|
||||
end
|
||||
|
||||
it "doesn't expand if online_uploads is not a submission_type" do
|
||||
assignment.update!(submission_types: 'online_text_entry,online_url')
|
||||
variable_expander.expand_variables!(exp_hash)
|
||||
expect(exp_hash[:test]).to eq "$com.instructure.Assignment.allowedFileExtensions"
|
||||
end
|
||||
|
||||
it 'expands to an empty string if there are no limits on file types' do
|
||||
assignment.update!(submission_types: 'online_upload,online_text_entry')
|
||||
variable_expander.expand_variables!(exp_hash)
|
||||
expect(exp_hash[:test]).to eq ""
|
||||
end
|
||||
|
||||
context 'no assignment present' do
|
||||
let(:variable_expander_opts) { super().merge(context: course) }
|
||||
|
||||
it "doesn't expand" do
|
||||
variable_expander.expand_variables!(exp_hash)
|
||||
expect(exp_hash[:test]).to eq expansion
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'has substitution for com.instructure.OriginalityReport.id' do
|
||||
exp_hash = {test: '$com.instructure.OriginalityReport.id'}
|
||||
variable_expander.expand_variables!(exp_hash)
|
||||
|
|
Loading…
Reference in New Issue