Add field to expose viewable submissions that have comments
closes VICE-2655 flag=react_inbox Test Plan 1. Test work 2. go to http://localhost:3000/graphiql 3. Verify that new field returns submission data correctly Here is a graphiql Query to help with testing. legacyNode(_id: "5", type: User) { ... on User { id email viewableSubmissionsConnection { nodes { _id commentsConnection { nodes { comment author { name } _id } } } } } } Change-Id: Ie7a152ba41c5a66f0ddcaa7dc54df1e8fb5dd92a Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/288571 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Omar Soto-Fortuño <omar.soto@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com>
This commit is contained in:
parent
82113f7f40
commit
e075ce961d
|
@ -302,6 +302,26 @@ module Types
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
field :viewable_submissions_connection, Types::SubmissionType.connection_type, null: true do
|
||||||
|
description "All submissions with comments that the current_user is able to view"
|
||||||
|
end
|
||||||
|
def viewable_submissions_connection
|
||||||
|
return unless object == current_user
|
||||||
|
|
||||||
|
submissions = []
|
||||||
|
|
||||||
|
ssi_scope = current_user.visible_stream_item_instances(only_active_courses: true)
|
||||||
|
ssi_scope = ssi_scope.eager_load(:stream_item).where("stream_items.asset_type=?", "Submission")
|
||||||
|
ssi_scope = ssi_scope.joins("INNER JOIN #{Submission.quoted_table_name} ON submissions.id=asset_id")
|
||||||
|
ssi_scope = ssi_scope.where("submissions.workflow_state <> 'deleted' AND submissions.submission_comments_count>0")
|
||||||
|
|
||||||
|
Shard.partition_by_shard(ssi_scope, ->(sii) { sii.stream_item_id }) do |shard_stream_items|
|
||||||
|
submission_ids = StreamItem.where(id: shard_stream_items.map(&:stream_item_id)).pluck(:asset_id)
|
||||||
|
submissions += Submission.where(id: submission_ids)
|
||||||
|
end
|
||||||
|
submissions
|
||||||
|
end
|
||||||
|
|
||||||
field :submission_comments_connection, Types::SubmissionCommentType.connection_type, null: true
|
field :submission_comments_connection, Types::SubmissionCommentType.connection_type, null: true
|
||||||
def submission_comments_connection
|
def submission_comments_connection
|
||||||
return unless object == current_user
|
return unless object == current_user
|
||||||
|
|
|
@ -793,107 +793,150 @@ describe Types::UserType do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def submission_comments_mutation_str(teacher_id)
|
|
||||||
<<~GQL
|
|
||||||
{
|
|
||||||
legacyNode(_id: \"#{teacher_id}\", type: User) {
|
|
||||||
... on User {
|
|
||||||
submissionCommentsConnection(first: 10) {
|
|
||||||
nodes {
|
|
||||||
_id
|
|
||||||
submissionId
|
|
||||||
createdAt
|
|
||||||
comment
|
|
||||||
assignment {
|
|
||||||
name
|
|
||||||
}
|
|
||||||
course {
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GQL
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "submission comments" do
|
describe "submission comments" do
|
||||||
before(:once) do
|
before(:once) do
|
||||||
course = Course.create! name: "TEST"
|
@course = Course.create! name: "TEST"
|
||||||
|
|
||||||
@teacher = course_with_user("TeacherEnrollment", course: course, name: "Mr Teacher", active_all: true).user
|
@teacher = course_with_user("TeacherEnrollment", course: @course, name: "Mr Teacher", active_all: true).user
|
||||||
student = course_with_user("StudentEnrollment", course: course, name: "Mr Student 1", active_all: true).user
|
@student = course_with_user("StudentEnrollment", course: @course, name: "Mr Student 1", active_all: true).user
|
||||||
|
|
||||||
assignment = course.assignments.create!(
|
assignment = @course.assignments.create!(
|
||||||
name: "Test Assignment",
|
name: "Test Assignment",
|
||||||
moderated_grading: true,
|
moderated_grading: true,
|
||||||
grader_count: 10,
|
grader_count: 10,
|
||||||
final_grader: @teacher
|
final_grader: @teacher
|
||||||
)
|
)
|
||||||
assignment.grade_student(student, grade: 1, grader: @teacher, provisional: true)
|
assignment2 = @course.assignments.create!(
|
||||||
@submission = assignment.submissions.find_by(user: student)
|
name: "Assignment without Comments",
|
||||||
|
moderated_grading: true,
|
||||||
@sc1 = @submission.add_comment(author: student, comment: "First comment")
|
grader_count: 10,
|
||||||
@sc2 = @submission.add_comment(author: @teacher, comment: "Second comment")
|
final_grader: @teacher
|
||||||
@sc3 = @submission.add_comment(author: @teacher, comment: "Third comment")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "can get comments" do
|
|
||||||
result = CanvasSchema.execute(
|
|
||||||
submission_comments_mutation_str(@teacher.id),
|
|
||||||
context: { current_user: @teacher }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
assignment.grade_student(@student, grade: 1, grader: @teacher, provisional: true)
|
||||||
|
assignment2.grade_student(@student, grade: 1, grader: @teacher, provisional: true)
|
||||||
|
|
||||||
expect(nodes.map { |c| c["comment"] }).to match_array ["First comment", "Second comment", "Third comment"]
|
@student_submission_1 = assignment.submissions.find_by(user: @student)
|
||||||
|
|
||||||
|
@sc1 = @student_submission_1.add_comment(author: @student, comment: "First comment")
|
||||||
|
@sc2 = @student_submission_1.add_comment(author: @teacher, comment: "Second comment")
|
||||||
|
@sc3 = @student_submission_1.add_comment(author: @teacher, comment: "Third comment")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can get submissionId" do
|
let(:teacher_type) do
|
||||||
result = CanvasSchema.execute(
|
GraphQLTypeTester.new(@teacher, current_user: @teacher, domain_root_account: @course.account.root_account, request: ActionDispatch::TestRequest.create)
|
||||||
submission_comments_mutation_str(@teacher.id),
|
|
||||||
context: { current_user: @teacher }
|
|
||||||
)
|
|
||||||
|
|
||||||
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
|
||||||
|
|
||||||
expect(nodes.map { |c| c["submissionId"] }).to match_array [@submission.id.to_s, @submission.id.to_s, @submission.id.to_s]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can get createdAt" do
|
describe "viewableSubmissionsConnection field" do
|
||||||
result = CanvasSchema.execute(
|
it "only gets submissions with comments" do
|
||||||
submission_comments_mutation_str(@teacher.id),
|
query_result = teacher_type.resolve("viewableSubmissionsConnection { nodes { _id } }")
|
||||||
context: { current_user: @teacher }
|
expect(query_result.count).to eq 1
|
||||||
)
|
expect(query_result[0].to_i).to eq @student_submission_1.id
|
||||||
|
end
|
||||||
|
|
||||||
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
it "can retrieve submission comments" do
|
||||||
|
query_result = teacher_type.resolve("viewableSubmissionsConnection { nodes { commentsConnection { nodes { comment }} } }")
|
||||||
|
expect(query_result[0].count).to eq 3
|
||||||
|
expect(query_result[0]).to match_array ["First comment", "Second comment", "Third comment"]
|
||||||
|
end
|
||||||
|
|
||||||
[@sc1, @sc2, @sc3].each do |sc|
|
it "can get createdAt" do
|
||||||
expect(Time.parse(nodes.find { |n| n["_id"] == sc.id.to_s }["createdAt"])).to be_within(1.minute).of(sc.created_at)
|
query_result = teacher_type.resolve("viewableSubmissionsConnection { nodes { commentsConnection { nodes { createdAt }} } }")
|
||||||
|
retrieved_values = query_result[0].map { |string_date| Time.parse(string_date) }
|
||||||
|
expect(retrieved_values).to all(be_within(1.minute).of(@sc1.created_at))
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can get assignment names" do
|
||||||
|
expect(teacher_type.resolve("viewableSubmissionsConnection { nodes { assignment { name } } }")[0]).to eq @student_submission_1.assignment.name
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can get course names" do
|
||||||
|
expect(teacher_type.resolve("viewableSubmissionsConnection { nodes { commentsConnection { nodes { course { name } } } } }")[0]).to match_array %w[TEST TEST TEST]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can get assignment names" do
|
describe "submissionCommentsConnection field" do
|
||||||
result = CanvasSchema.execute(
|
def submission_comments_mutation_str(teacher_id)
|
||||||
submission_comments_mutation_str(@teacher.id),
|
<<~GQL
|
||||||
context: { current_user: @teacher }
|
{
|
||||||
)
|
legacyNode(_id: \"#{teacher_id}\", type: User) {
|
||||||
|
... on User {
|
||||||
|
submissionCommentsConnection(first: 10) {
|
||||||
|
nodes {
|
||||||
|
_id
|
||||||
|
submissionId
|
||||||
|
createdAt
|
||||||
|
comment
|
||||||
|
assignment {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
course {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GQL
|
||||||
|
end
|
||||||
|
|
||||||
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
it "can get comments" do
|
||||||
|
result = CanvasSchema.execute(
|
||||||
|
submission_comments_mutation_str(@teacher.id),
|
||||||
|
context: { current_user: @teacher }
|
||||||
|
)
|
||||||
|
|
||||||
expect(nodes.map { |c| c["assignment"]["name"] }).to match_array ["Test Assignment", "Test Assignment", "Test Assignment"]
|
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
||||||
end
|
|
||||||
|
|
||||||
it "can get course names" do
|
expect(nodes.map { |c| c["comment"] }).to match_array ["First comment", "Second comment", "Third comment"]
|
||||||
result = CanvasSchema.execute(
|
end
|
||||||
submission_comments_mutation_str(@teacher.id),
|
|
||||||
context: { current_user: @teacher }
|
|
||||||
)
|
|
||||||
|
|
||||||
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
it "can get submissionId" do
|
||||||
|
result = CanvasSchema.execute(
|
||||||
|
submission_comments_mutation_str(@teacher.id),
|
||||||
|
context: { current_user: @teacher }
|
||||||
|
)
|
||||||
|
|
||||||
expect(nodes.map { |c| c["course"]["name"] }).to match_array %w[TEST TEST TEST]
|
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
||||||
|
|
||||||
|
expect(nodes.map { |c| c["submissionId"] }).to match_array [@student_submission_1.id.to_s, @student_submission_1.id.to_s, @student_submission_1.id.to_s]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can get createdAt" do
|
||||||
|
result = CanvasSchema.execute(
|
||||||
|
submission_comments_mutation_str(@teacher.id),
|
||||||
|
context: { current_user: @teacher }
|
||||||
|
)
|
||||||
|
|
||||||
|
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
||||||
|
|
||||||
|
[@sc1, @sc2, @sc3].each do |sc|
|
||||||
|
expect(Time.parse(nodes.find { |n| n["_id"] == sc.id.to_s }["createdAt"])).to be_within(1.minute).of(sc.created_at)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can get assignment names" do
|
||||||
|
result = CanvasSchema.execute(
|
||||||
|
submission_comments_mutation_str(@teacher.id),
|
||||||
|
context: { current_user: @teacher }
|
||||||
|
)
|
||||||
|
|
||||||
|
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
||||||
|
|
||||||
|
expect(nodes.map { |c| c["assignment"]["name"] }).to match_array ["Test Assignment", "Test Assignment", "Test Assignment"]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "can get course names" do
|
||||||
|
result = CanvasSchema.execute(
|
||||||
|
submission_comments_mutation_str(@teacher.id),
|
||||||
|
context: { current_user: @teacher }
|
||||||
|
)
|
||||||
|
|
||||||
|
nodes = result.dig("data", "legacyNode", "submissionCommentsConnection", "nodes")
|
||||||
|
|
||||||
|
expect(nodes.map { |c| c["course"]["name"] }).to match_array %w[TEST TEST TEST]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue