assignment enhancements: fix assignment page for observers

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 <svc.cloudjenkins@instructure.com>
Reviewed-by: Adrian Packel <apackel@instructure.com>
Reviewed-by: Kai Bjorkman <kbjorkman@instructure.com>
QA-Review: Syed Hussain <shussain@instructure.com>
Product-Review: Syed Hussain <shussain@instructure.com>
This commit is contained in:
Spencer Olson 2021-01-11 14:21:17 -06:00
parent 4aa05e2fcd
commit 18176c1f73
2 changed files with 52 additions and 1 deletions

View File

@ -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

View File

@ -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"