use workflow_state for group enrollment inactive status

test plan:
* have a student in a course with term dates
 that haven't begun yet
* add them to a group
* they shouldn't be listed as "inactive"

closes #COMMS-624

Change-Id: Ie490f37c99469d6cffacf12194761860c0316d09
Reviewed-on: https://gerrit.instructure.com/137465
Tested-by: Jenkins
Reviewed-by: Steven Burnett <sburnett@instructure.com>
Reviewed-by: Venk Natarajan <vnatarajan@instructure.com>
QA-Review: Felix Milea-Ciobanu <fmileaciobanu@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
James Williams 2018-01-10 10:45:01 -07:00
parent 7ad20f57ac
commit e1bc67cadb
3 changed files with 17 additions and 12 deletions

View File

@ -711,10 +711,9 @@ class GroupsController < ApplicationController
end
if (includes.include? 'active_status') && (@context.context.is_a? Course)
user_ids = users.pluck('id')
enrollments = Enrollment.where(user_id: user_ids, course_id: @context.context_id)
enrollments = Enrollment.where(user_id: json_users.map{|u| u[:id]}, course_id: @context.context_id)
inactive_students = enrollments.select(&:inactive?).pluck('user_id').to_set
inactive_students = enrollments.group_by(&:user_id).select{|_id, enrollments| enrollments.all?(&:hard_inactive?)}.map(&:first)
json_users.each do |user|
user[:is_inactive] = inactive_students.include?(user[:id])
end

View File

@ -791,6 +791,10 @@ class Enrollment < ActiveRecord::Base
state_based_on_date == :inactive
end
def hard_inactive?
workflow_state == 'inactive'
end
def invited?
state_based_on_date == :invited
end

View File

@ -733,22 +733,25 @@ describe GroupsController do
describe "inactive students" do
before :once do
course_with_teacher(:active_all => true)
students = create_users_in_course(@course, 2, return_type: :record)
student1, student2 = students
students = create_users_in_course(@course, 3, return_type: :record)
@student1, @student2, @student3 = students
category1 = @course.group_categories.create(:name => "category 1")
@group = @course.groups.create(:name => "some group", :group_category => category1)
@group.add_user(student1)
@group.add_user(student2)
student2.enrollments.first.deactivate
@group.add_user(@student1)
@group.add_user(@student2)
@group.add_user(@student3)
@student2.enrollments.first.deactivate
@student3.enrollments.first.update_attributes(:start_at => 1.day.from_now, :end_at => 2.days.from_now) # technically "inactive" but not really
end
it "include active status if requested" do
user_session(@teacher)
get 'users', params: { :group_id => @group.id, include: ['active_status'] }
json = JSON.parse(response.body[@json_prefix.length, response.body.length])
expect(json.length).to eq 2
expect(json.first['is_inactive']).to be_falsey
expect(json.second['is_inactive']).to be_truthy
expect(json.length).to eq 3
expect(json.detect{|r| r['id'] == @student1.id}['is_inactive']).to be_falsey
expect(json.detect{|r| r['id'] == @student2.id}['is_inactive']).to be_truthy
expect(json.detect{|r| r['id'] == @student3.id}['is_inactive']).to be_falsey
end
it "don't include active status if not requested" do
@ -756,7 +759,6 @@ describe GroupsController do
get 'users', params: { :group_id => @group.id }
json = JSON.parse(response.body[@json_prefix.length, response.body.length])
expect(json.first['is_inactive']).to be_nil
expect(json.second['is_inactive']).to be_nil
end
end
end