From 18176c1f73b02b69a04cdfbf619f99dd1b58b43c Mon Sep 17 00:00:00 2001 From: Spencer Olson Date: Mon, 11 Jan 2021 14:21:17 -0600 Subject: [PATCH] assignment enhancements: fix assignment page for observers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When 'Assignment Enhancements — Student' is enabled, observers will now be able to view the assignment page without error. The observers will be sent to the 'old' assignments page. closes EVAL-1383 flag=assignments_2_student Test Plan: 1. Add at least one observer and one assignment to a published course. 2. Enable the Assignment Enhancements - Student feature option at the account. 3. Act as the observer and view the assignment 4. Verify the 'assignment show' page is shown (with assignment title, details, due date, etc.). Note that this is the "old" assignment show page, and not an enhanced version of the page. This is intentional. Change-Id: I07ac9deab33a5a5e5378c9ac15c6e4df433d3932 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/256464 Tested-by: Service Cloud Jenkins Reviewed-by: Adrian Packel Reviewed-by: Kai Bjorkman QA-Review: Syed Hussain Product-Review: Syed Hussain --- app/controllers/assignments_controller.rb | 3 +- spec/integration/assignments_spec.rb | 50 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index 4f40a0d32d1..5159c5a3fec 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -93,7 +93,8 @@ class AssignmentsController < ApplicationController def render_a2_student_view? @assignment.a2_enabled? && !can_do(@context, @current_user, :read_as_admin) && - (!params.key?(:assignments_2) || value_to_boolean(params[:assignments_2])) + (!params.key?(:assignments_2) || value_to_boolean(params[:assignments_2])) && + !@context_enrollment&.observer? end def render_a2_student_view diff --git a/spec/integration/assignments_spec.rb b/spec/integration/assignments_spec.rb index 47803bbc92f..683a3d19ed5 100644 --- a/spec/integration/assignments_spec.rb +++ b/spec/integration/assignments_spec.rb @@ -408,6 +408,56 @@ describe "assignments_2 feature flag and parameter" do end end + describe "as an observer" do + before(:once) do + course_with_student(active_all: true) + @assignment = @course.assignments.create!(title: "Some Assignment") + @observer = user_factory(active_all: true, active_state: 'active') + @course.enroll_user( + @observer, + 'ObserverEnrollment', + section: @course.course_sections.first, + enrollment_state: 'active', allow_multiple_enrollments: true + ) + add_linked_observer(@student, @observer) + end + + before(:each) do + user_session(@observer) + end + + let(:old_assignment_page_indicator) { Nokogiri::HTML(response.body).at_css('div#assignment_show') } + + context "with the feature disabled" do + it "shows the old assignments page even with query parameter" do + get "/courses/#{@course.id}/assignments/#{@assignment.id}?assignments_2=1" + expect(old_assignment_page_indicator).to be_present + end + + it "shows the old assignments page without the query parameter" do + get "/courses/#{@course.id}/assignments/#{@assignment.id}" + expect(old_assignment_page_indicator).to be_present + end + end + + context "with the feature enabled" do + before :once do + Account.default.enable_feature! :assignments_2_student + end + + # we always send observers to the 'old' assignments page + it "shows the old assignments page even with query parameter" do + get "/courses/#{@course.id}/assignments/#{@assignment.id}?assignments_2=1" + expect(old_assignment_page_indicator).to be_present + end + + it "shows the old assignments page without the query parameter" do + get "/courses/#{@course.id}/assignments/#{@assignment.id}" + expect(old_assignment_page_indicator).to be_present + end + end + end + describe "description" do before :each do skip "TODO doesn't work right because public_user_content is wonky"