Skip to content

Commit 39cfcdf

Browse files
committed
show view restricted future/completed enrollments as completed
test plan: * enroll a student in a course with "Restrict students from viewing after end date" enabled * set the term dates to the past * on the account user details page for the student (e.g. "/users/X") it should not say that the enrollment is "Inactive", but rather "Completed" * repeat for a future course (it should say "Pending") closes #CNVS-27436 Change-Id: I4b774267cb5e6418ef76b6ed93fe2e6bcc686fd1 Reviewed-on: https://gerrit.instructure.com/73623 Tested-by: Jenkins Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Deepeeca Soundarrajan <dsoundarrajan@instructure.com> Product-Review: Allison Weiss <allison@instructure.com>
1 parent be51970 commit 39cfcdf

4 files changed

Lines changed: 79 additions & 13 deletions

File tree

app/models/enrollment.rb

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -677,17 +677,37 @@ def calculated_state_based_on_date
677677
self.restrict_past_view? ? :inactive : :completed
678678
elsif self.fake_student? # Allow student view students to use the course before the term starts
679679
state
680-
elsif view_restrictable? && !self.restrict_future_view?
680+
else
681681
self.available_at = global_start_at
682-
if state == :active
683-
# an accepted enrollment state means they still can't participate yet,
684-
# but should be able to view just like an invited enrollment
685-
:accepted
682+
if view_restrictable? && !self.restrict_future_view?
683+
if state == :active
684+
# an accepted enrollment state means they still can't participate yet,
685+
# but should be able to view just like an invited enrollment
686+
:accepted
687+
else
688+
state
689+
end
686690
else
687-
state
691+
:inactive
688692
end
693+
end
694+
end
695+
696+
def readable_state_based_on_date
697+
# when view restrictions are in place, the effective state_based_on_date is :inactive, but
698+
# to admins we should show that they are :completed or :pending
699+
700+
if state == :completed || ([:invited, :active].include?(state) && self.course.completed?)
701+
:completed
689702
else
690-
:inactive
703+
date_state = state_based_on_date
704+
if self.available_at
705+
:pending
706+
elsif self.soft_completed_at
707+
:completed
708+
else
709+
date_state
710+
end
691711
end
692712
end
693713

@@ -857,10 +877,6 @@ def self.workflow_readable_type(state)
857877
end
858878
end
859879

860-
def workflow_readable_type
861-
Enrollment.workflow_readable_type(self.workflow_state)
862-
end
863-
864880
def readable_role_name
865881
self.role.built_in? ? self.readable_type : self.role.name
866882
end

app/views/users/_enrollment.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<% end %>
1414

1515
<span class="subtitle ellipsis">
16-
<%= Enrollment.workflow_readable_type(enrollment.state_based_on_date) %>,
16+
<%= Enrollment.workflow_readable_type(enrollment.readable_state_based_on_date) %>,
1717
<%=
1818
case enrollment.class.to_s
1919
when 'TeacherEnrollment'

spec/integration/enrollment_date_restrictions_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
Account.default.account_users.create!(user: @user)
133133
@user.reload
134134
get "/users/#{@user.id}"
135-
expect(response.body).to match /Inactive/
136135
expect(response.body).to match /Completed/
137136
expect(response.body).to match /Active/
138137
end

spec/models/enrollment_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,4 +2002,55 @@ def enrollment_dates_override_test
20022002
expect(Enrollment.not_yet_started(@course)).not_to include(@enrollment)
20032003
end
20042004
end
2005+
2006+
describe "readable_state_based_on_date" do
2007+
before :once do
2008+
course(:active_all => true)
2009+
@enrollment = @course.enroll_student(user)
2010+
@enrollment.accept!
2011+
end
2012+
2013+
it "should return pending for future enrollments (even if view restricted)" do
2014+
@course.start_at = 1.month.from_now
2015+
@course.restrict_student_future_view = true
2016+
@course.restrict_enrollments_to_course_dates = true
2017+
@course.save!
2018+
2019+
@enrollment.reload
2020+
expect(@enrollment.state_based_on_date).to eq :inactive
2021+
expect(@enrollment.readable_state_based_on_date).to eq :pending
2022+
2023+
@course.restrict_student_future_view = false
2024+
@course.save!
2025+
2026+
@enrollment = Enrollment.find(@enrollment.id)
2027+
expect(@enrollment.state_based_on_date).to eq :accepted
2028+
expect(@enrollment.readable_state_based_on_date).to eq :pending
2029+
end
2030+
2031+
it "should return completed for completed enrollments (even if view restricted)" do
2032+
@course.start_at = 2.months.ago
2033+
@course.conclude_at = 1.month.ago
2034+
@course.restrict_student_past_view = true
2035+
@course.restrict_enrollments_to_course_dates = true
2036+
@course.save!
2037+
2038+
@enrollment.reload
2039+
expect(@enrollment.state_based_on_date).to eq :inactive
2040+
expect(@enrollment.readable_state_based_on_date).to eq :completed
2041+
2042+
@course.complete!
2043+
2044+
@enrollment = Enrollment.find(@enrollment.id)
2045+
expect(@enrollment.state_based_on_date).to eq :inactive
2046+
expect(@enrollment.readable_state_based_on_date).to eq :completed
2047+
2048+
@course.restrict_student_past_view = false
2049+
@course.save!
2050+
2051+
@enrollment = Enrollment.find(@enrollment.id)
2052+
expect(@enrollment.state_based_on_date).to eq :completed
2053+
expect(@enrollment.readable_state_based_on_date).to eq :completed
2054+
end
2055+
end
20052056
end

0 commit comments

Comments
 (0)