fix page view participation checkmark with a2

Generates a page view for a2 assignment submissions through
graphql post.

closes EVAL-2290
flag=assignments_2_student

Test Plan:
- make a course populated with students that has the Assignment
Enhancments feature enabled

- create an assignment on the course

- while acting as a student, submit the assignement to trigger
participation

- navigate to the student's page views, verify that a participation
checkmark appears.

Change-Id: I80802137a0d73647cfeb251256cb328c864bbcaf
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/301934
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Kai Bjorkman <kbjorkman@instructure.com>
Reviewed-by: Kai Bjorkman <kbjorkman@instructure.com>
Reviewed-by: Eduardo Escobar <eduardo.escobar@instructure.com>
Product-Review: Deborah Kwak <deborah.kwak@instructure.com>
This commit is contained in:
Derek Williams 2022-09-22 09:52:19 -04:00
parent bf0d247545
commit 21652bfeb7
3 changed files with 46 additions and 2 deletions

View File

@ -1051,8 +1051,9 @@ class ApplicationController < ActionController::Base
def get_context(include_deleted: false)
GuardRail.activate(:secondary) do
unless @context
if params[:course_id]
@context = api_find(Course.active, params[:course_id])
if params[:course_id] || (request.url.include?("/graphql") && params[:operationName] == "CreateSubmission")
@context = params[:course_id] ? api_find(Course.active, params[:course_id]) : pull_context_course
@context.root_account = @domain_root_account if @context.root_account_id == @domain_root_account.id # no sense in refetching it
params[:context_id] = params[:course_id]
params[:context_type] = "Course"
@ -3097,6 +3098,11 @@ class ApplicationController < ActionController::Base
end
helper_method :k5_user?
def pull_context_course
assignment_id = params[:variables][:assignmentLid]
::Assignment.active.find(assignment_id).course
end
def react_discussions_post_enabled_for_preferences_use?
if @context.instance_of?(UserProfile) && Account.default.feature_enabled?(:react_discussions_post)
return true

View File

@ -37,6 +37,7 @@ class GraphQLController < ApplicationController
def execute
result = execute_on(CanvasSchema)
prep_page_view_for_submit
render json: result
end
@ -103,4 +104,12 @@ class GraphQLController < ApplicationController
)
end
end
def prep_page_view_for_submit
return unless params[:operationName] == "CreateSubmission"
assignment = ::Assignment.active.find(params[:variables][:assignmentLid])
get_context
log_asset_access(assignment, "assignments", nil, "participate")
end
end

View File

@ -82,6 +82,35 @@ describe GraphQLController do
expect(JSON.parse(response.body)["data"]).to be_blank
end
it "logs a page view for CreateSubmission" do
Setting.set("enable_page_views", "db")
@course = course_factory(name: "course", active_course: true)
@assignment = @course.assignments.create!(
name: "assignment",
due_at: 5.days.ago,
points_possible: 10,
submission_types: "online_text_entry"
)
test_query = <<~GQL
mutation {
CreateSubmission(input: {assignmentId: $assignmentLid, submissionType: $type, body: $body})
GQL
test_variables = {
assignmentLid: @assignment.id,
body: "<p>test</p>",
type: "online_text_entry"
}
# need this for the page view to be assigned a proper request_id
RequestContext::Generator.new(->(_env) { [200, {}, []] }).call({})
expect { post :execute, params: { query: test_query, operationName: "CreateSubmission", variables: test_variables }, format: :json }.to change { PageView.count }.by(1)
expect(PageView.last.participated).to be(true)
end
context "datadog metrics" do
before { allow(InstStatsd::Statsd).to receive(:increment).and_call_original }