add url to the submission draft model/graphql type
Test Plan - run the db migration to add url to the SubmissionDraft table - bundle exec rake db:migrate:up VERSION=20190916193616 - Create a course and add a student to it - Create an assignment with a submission type of online url - Masquerade as the student and navigate to the /graphiql endpoint - Run the following mutation updated with the appropriate submissionID: ``` mutation MyMutation { __typename createSubmissionDraft(input: {submissionId: <your_submission_id>, url: "http://www.google.com", attempt: 1}) { errors { attribute message } submissionDraft { _id url submissionAttempt } } } ``` - The mutation should return 0 errors and the submission draft should reflect the given url - Run the following query updated with the appropriate submissionID: ``` query MyQuery { __typename legacyNode(_id: <your_submission_id>, type: Submission) { ... on Submission { id submissionDraft { url submissionAttempt _id } } } } ``` - The query result should show the url you entered in the previous mutation refs COMMS-2331 flag=assignments_2 Change-Id: I60d756a9f0a29ea5aece960416edbb43c0949ddc Reviewed-on: https://gerrit.instructure.com/209727 Tested-by: Jenkins Reviewed-by: Landon Gilbert-Bland <lbland@instructure.com> QA-Review: Ben Nelson <bnelson@instructure.com> Product-Review: Matthew Lemon <mlemon@instructure.com>
This commit is contained in:
parent
66181c70ea
commit
726ee1a6f5
|
@ -32,6 +32,7 @@ class Mutations::CreateSubmissionDraft < Mutations::BaseMutation
|
|||
argument :body, String, required: false
|
||||
argument :file_ids, [ID], required: false, prepare: GraphQLHelpers.relay_or_legacy_ids_prepare_func('Attachment')
|
||||
argument :submission_id, ID, required: true, prepare: GraphQLHelpers.relay_or_legacy_id_prepare_func('Submission')
|
||||
argument :url, String, required: false
|
||||
|
||||
field :submission_draft, Types::SubmissionDraftType, null: true
|
||||
def resolve(input:)
|
||||
|
@ -46,8 +47,9 @@ class Mutations::CreateSubmissionDraft < Mutations::BaseMutation
|
|||
submission_attempt: input[:attempt] || (submission.attempt + 1)
|
||||
).first_or_create!
|
||||
submission_draft.attachments = attachments
|
||||
# for drafts we allow the body to be null or empty, so there's nothing to validate
|
||||
# for drafts we allow the body and url to be null or empty, so there's nothing to validate
|
||||
submission_draft.body = input[:body]
|
||||
submission_draft.url = input[:url]
|
||||
submission_draft.save!
|
||||
|
||||
{submission_draft: submission_draft}
|
||||
|
|
|
@ -57,5 +57,7 @@ module Types
|
|||
end
|
||||
|
||||
field :submission_attempt, Integer, null: false
|
||||
|
||||
field :url, Types::UrlType, null: true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,9 +68,15 @@ export const CREATE_SUBMISSION_COMMENT = gql`
|
|||
`
|
||||
|
||||
export const CREATE_SUBMISSION_DRAFT = gql`
|
||||
mutation CreateSubmissionDraft($id: ID!, $attempt: Int!, $body: String, $fileIds: [ID!]) {
|
||||
mutation CreateSubmissionDraft(
|
||||
$id: ID!
|
||||
$attempt: Int!
|
||||
$body: String
|
||||
$fileIds: [ID!]
|
||||
$url: String
|
||||
) {
|
||||
createSubmissionDraft(
|
||||
input: {submissionId: $id, attempt: $attempt, body: $body, fileIds: $fileIds}
|
||||
input: {submissionId: $id, attempt: $attempt, body: $body, fileIds: $fileIds, url: $url}
|
||||
) {
|
||||
submissionDraft {
|
||||
...SubmissionDraft
|
||||
|
|
|
@ -28,6 +28,7 @@ export const SubmissionDraft = {
|
|||
}
|
||||
body
|
||||
meetsAssignmentCriteria
|
||||
url
|
||||
}
|
||||
${SubmissionDraftFile.fragment}
|
||||
`,
|
||||
|
@ -36,7 +37,8 @@ export const SubmissionDraft = {
|
|||
_id: string,
|
||||
attachments: arrayOf(SubmissionDraftFile.shape),
|
||||
body: string,
|
||||
meetsAssignmentCriteria: bool
|
||||
meetsAssignmentCriteria: bool,
|
||||
url: string
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -44,6 +46,7 @@ export const SubmissionDraftDefaultMocks = {
|
|||
SubmissionDraft: () => ({
|
||||
attachments: () => [],
|
||||
body: null,
|
||||
meetsAssignmentCriteria: false
|
||||
meetsAssignmentCriteria: false,
|
||||
url: null
|
||||
})
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#
|
||||
|
||||
class SubmissionDraft < ActiveRecord::Base
|
||||
include CustomValidations
|
||||
|
||||
belongs_to :submission, inverse_of: :submission_drafts
|
||||
has_many :submission_draft_attachments, inverse_of: :submission_draft, dependent: :delete_all
|
||||
has_many :attachments, through: :submission_draft_attachments
|
||||
|
@ -26,6 +28,7 @@ class SubmissionDraft < ActiveRecord::Base
|
|||
validates :submission, uniqueness: { scope: :submission_attempt }
|
||||
validates :body, length: {maximum: maximum_text_length, allow_nil: true, allow_blank: true}
|
||||
validate :submission_attempt_matches_submission
|
||||
validates_as_url :url
|
||||
|
||||
def submission_attempt_matches_submission
|
||||
current_submission_attempt = self.submission&.attempt || 0
|
||||
|
@ -46,6 +49,8 @@ class SubmissionDraft < ActiveRecord::Base
|
|||
return true if self.body.present?
|
||||
when 'online_upload'
|
||||
return true if self.attachments.present?
|
||||
when 'online_url'
|
||||
return true if self.url.present?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# Copyright (C) 2019 - present Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
# Canvas is free software: you can redistribute it and/or modify it under
|
||||
# the terms of the GNU Affero General Public License as published by the Free
|
||||
# Software Foundation, version 3 of the License.
|
||||
#
|
||||
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
# details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
class AddUrlToSubmissionDraft < ActiveRecord::Migration[5.2]
|
||||
tag :predeploy
|
||||
|
||||
def change
|
||||
add_column :submission_drafts, :url, :text
|
||||
end
|
||||
end
|
|
@ -1077,6 +1077,7 @@ input CreateSubmissionDraftInput {
|
|||
body: String
|
||||
fileIds: [ID!]
|
||||
submissionId: ID!
|
||||
url: String
|
||||
}
|
||||
|
||||
"""
|
||||
|
@ -2846,6 +2847,7 @@ type SubmissionDraft implements LegacyIDInterface {
|
|||
body: String
|
||||
meetsAssignmentCriteria: Boolean!
|
||||
submissionAttempt: Int!
|
||||
url: URL
|
||||
}
|
||||
|
||||
"""
|
||||
|
|
|
@ -32,7 +32,8 @@ RSpec.describe Mutations::CreateSubmissionDraft do
|
|||
submission_id: @submission.id,
|
||||
attempt: nil,
|
||||
body: nil,
|
||||
file_ids: []
|
||||
file_ids: [],
|
||||
url: nil
|
||||
)
|
||||
<<~GQL
|
||||
mutation {
|
||||
|
@ -41,6 +42,7 @@ RSpec.describe Mutations::CreateSubmissionDraft do
|
|||
#{"attempt: #{attempt}" if attempt}
|
||||
#{"body: \"#{body}\"" if body}
|
||||
fileIds: #{file_ids}
|
||||
#{"url: \"#{url}\"" if url}
|
||||
}) {
|
||||
submissionDraft {
|
||||
_id
|
||||
|
@ -50,6 +52,7 @@ RSpec.describe Mutations::CreateSubmissionDraft do
|
|||
displayName
|
||||
}
|
||||
body
|
||||
url
|
||||
}
|
||||
errors {
|
||||
attribute
|
||||
|
@ -113,6 +116,28 @@ RSpec.describe Mutations::CreateSubmissionDraft do
|
|||
).to eq 'some text body'
|
||||
end
|
||||
|
||||
it 'allows you to set a url on the submission draft' do
|
||||
result = run_mutation(
|
||||
submission_id: @submission.id,
|
||||
attempt: @submission.attempt,
|
||||
url: 'http://www.google.com'
|
||||
)
|
||||
expect(
|
||||
result.dig(:data, :createSubmissionDraft, :submissionDraft, :url)
|
||||
).to eq 'http://www.google.com'
|
||||
end
|
||||
|
||||
it 'returns an error if the url is not a valid url' do
|
||||
result = run_mutation(
|
||||
submission_id: @submission.id,
|
||||
attempt: @submission.attempt,
|
||||
url: 'ooo eee Im not a valid url'
|
||||
)
|
||||
expect(
|
||||
result.dig(:data, :createSubmissionDraft, :errors, 0, :message)
|
||||
).to eq 'is not a valid URL'
|
||||
end
|
||||
|
||||
it 'returns an error if the attachments are not owned by the user' do
|
||||
attachment = attachment_with_context(@teacher)
|
||||
result = run_mutation(
|
||||
|
|
|
@ -43,6 +43,7 @@ RSpec.describe Types::SubmissionDraftType do
|
|||
body
|
||||
meetsAssignmentCriteria
|
||||
submissionAttempt
|
||||
url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,4 +86,12 @@ RSpec.describe Types::SubmissionDraftType do
|
|||
submission_draft = resolve_submission_draft
|
||||
expect(submission_draft['meetsAssignmentCriteria']).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns the draft url' do
|
||||
@submission_draft.url = 'http://www.google.com'
|
||||
@submission_draft.save!
|
||||
|
||||
submission_draft = resolve_submission_draft
|
||||
expect(submission_draft['url']).to eq('http://www.google.com')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -130,6 +130,29 @@ RSpec.describe SubmissionDraft do
|
|||
end
|
||||
end
|
||||
|
||||
context 'the assignment is an online_url type' do
|
||||
before(:once) do
|
||||
@submission.assignment.submission_types = 'online_url'
|
||||
end
|
||||
|
||||
it 'returns true if there is a url' do
|
||||
@submission_draft.url = 'http://www.google.com'
|
||||
expect(@submission_draft.meets_assignment_criteria?).to eq(true)
|
||||
end
|
||||
|
||||
it 'returns false if the url is empty' do
|
||||
@submission_draft.url = ''
|
||||
expect(@submission_draft.meets_assignment_criteria?).to eq(false)
|
||||
end
|
||||
|
||||
it 'returns false if drafts exist for a different type' do
|
||||
attachment = attachment_model
|
||||
@submission_draft.attachments = [attachment]
|
||||
|
||||
expect(@submission_draft.meets_assignment_criteria?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'there are multiple submission types' do
|
||||
before(:once) do
|
||||
@submission.assignment.submission_types = 'online_text_entry,online_upload'
|
||||
|
|
Loading…
Reference in New Issue