Add group categories and extra group params to the group report
Test Plan: Run the group and group_categories reports, make sure you get all group categories, with course and account contexts and make sure you get context information for the group report Change-Id: Ie769a8679edf1240db571a6acaaa40009c060a22 refs: PFS-6415 Reviewed-on: https://gerrit.instructure.com/100180 Reviewed-by: Rob Orton <rob@instructure.com> Tested-by: Jenkins QA-Review: Trevor Byington <tbyington@instructure.com> Product-Review: Chad McGuire <cmcguire@instructure.com>
This commit is contained in:
parent
38934f5563
commit
67fd784f87
|
@ -0,0 +1,99 @@
|
|||
<table>
|
||||
<%= render :partial => 'terms_parameters', :locals => { :all_terms_option => true } %>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[users]" %>
|
||||
<%= t('account_reports.default.users.check_box','Users CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[accounts]" %>
|
||||
<%= t('account_reports.default.accounts.check_box','Accounts CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[terms]" %>
|
||||
<%= t('account_reports.default.terms.check_box','Terms CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[courses]" %>
|
||||
<%= t('account_reports.default.courses.check_box','Courses CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[sections]" %>
|
||||
<%= t('account_reports.default.sections.check_box','Sections CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[enrollments]" %>
|
||||
<%= t('account_reports.default.enrollments.check_box','Enrollments CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[groups]" %>
|
||||
<%= t('account_reports.default.groups.check_box','Groups CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[group_membership]" %>
|
||||
<%= t('account_reports.default.group_membership.login.check_box','Group Membership CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[group_categories]" %>
|
||||
<%= t('account_reports.default.group_categories.login.check_box','Group Categories CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[xlist]" %>
|
||||
<%= t('account_reports.default.xlist.check_box','X list CSV') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label class="checkbox">
|
||||
<%= check_box_tag "parameters[created_by_sis]" %>
|
||||
<%= t('Created by SIS') %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<%= t('account_reports.sis_default.parameters.note', %{*Term settings only impact Courses, Sections, Enrollments, and X list CSV files.}) %>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<%= render :partial => 'include_deleted_parameter' %>
|
||||
</table>
|
|
@ -110,7 +110,7 @@ module AccountReports
|
|||
},
|
||||
'provisioning_csv' => {
|
||||
:title => proc { I18n.t(:provisioning_title, 'Provisioning') },
|
||||
:parameters_partial => 'sis_export_csv_parameters',
|
||||
:parameters_partial => 'provisioning_csv_parameters',
|
||||
:description_partial => true,
|
||||
:parameters => {
|
||||
:enrollment_term_id => {
|
||||
|
@ -138,6 +138,9 @@ module AccountReports
|
|||
:groups => {
|
||||
:description => 'Get the Provisioning file for groups'
|
||||
},
|
||||
:group_categories => {
|
||||
:description => 'Get the Provisioning file for group_categories'
|
||||
},
|
||||
:group_membership => {
|
||||
:description => 'Get the Provisioning file for group_membership'
|
||||
},
|
||||
|
|
|
@ -22,7 +22,7 @@ module AccountReports
|
|||
class SisExporter
|
||||
include ReportHelper
|
||||
|
||||
SIS_CSV_REPORTS = ["users", "accounts", "terms", "courses", "sections", "enrollments", "groups", "group_membership", "xlist"]
|
||||
SIS_CSV_REPORTS = ["users", "accounts", "terms", "courses", "sections", "enrollments", "groups", "group_membership", "group_categories", "xlist"].freeze
|
||||
|
||||
def initialize(account_report, params = {})
|
||||
@account_report = account_report
|
||||
|
@ -490,6 +490,9 @@ module AccountReports
|
|||
headers << I18n.t('#account_reports.report_header_name', 'name')
|
||||
headers << I18n.t('#account_reports.report_header_status', 'status')
|
||||
headers << I18n.t('created_by_sis')
|
||||
headers << I18n.t('context_id')
|
||||
headers << I18n.t('context_type')
|
||||
headers << I18n.t('group_category_id')
|
||||
end
|
||||
|
||||
groups = root_account.all_groups.
|
||||
|
@ -519,11 +522,56 @@ module AccountReports
|
|||
row << g.name
|
||||
row << g.workflow_state
|
||||
row << g.sis_batch_id? unless @sis_format
|
||||
row << g.context_id unless @sis_format
|
||||
row << g.context_type unless @sis_format
|
||||
row << g.group_category_id unless @sis_format
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def group_categories
|
||||
return if @sis_format
|
||||
headers = []
|
||||
headers << I18n.t('canvas_group_category_id')
|
||||
headers << I18n.t('context_id')
|
||||
headers << I18n.t('context_type')
|
||||
headers << I18n.t('name')
|
||||
headers << I18n.t('role')
|
||||
headers << I18n.t('self_signup')
|
||||
headers << I18n.t('group_limit')
|
||||
headers << I18n.t('auto_leader')
|
||||
|
||||
root_account.shard.activate do
|
||||
group_categories = GroupCategory.
|
||||
joins("LEFT JOIN #{Course.quoted_table_name} c ON c.id = group_categories.context_id AND group_categories.context_type = 'Course'").
|
||||
joins("LEFT JOIN #{Account.quoted_table_name} a ON a.id = group_categories.context_id AND group_categories.context_type = 'Account'").
|
||||
where("a.id IN (#{Account.sub_account_ids_recursive_sql(account.id)})
|
||||
OR a.id=?
|
||||
OR EXISTS (?)",
|
||||
account,
|
||||
CourseAccountAssociation.where("course_id=c.id").where(account_id: account))
|
||||
|
||||
unless @include_deleted
|
||||
group_categories.where!('group_categories.deleted_at IS NULL')
|
||||
end
|
||||
generate_and_run_report headers do |csv|
|
||||
group_categories.order('group_categories.id ASC').find_each do |g|
|
||||
row = []
|
||||
row << g.id
|
||||
row << g.context_id
|
||||
row << g.context_type
|
||||
row << g.name
|
||||
row << g.role
|
||||
row << g.self_signup
|
||||
row << g.group_limit
|
||||
row << g.auto_leader
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def group_membership
|
||||
if @sis_format
|
||||
# headers are not translated on sis_export to maintain import compatibility
|
||||
|
|
|
@ -95,6 +95,32 @@ describe "Default Account Reports" do
|
|||
@term1.save!
|
||||
end
|
||||
|
||||
def create_some_group_categories()
|
||||
create_some_courses
|
||||
@group_category1 = GroupCategory.create(
|
||||
:name => 'Test Group Category'
|
||||
)
|
||||
@group_category2 = GroupCategory.create(
|
||||
:name => 'Test Group Category2'
|
||||
)
|
||||
@group_category1.save!
|
||||
@group_category2.auto_leader = 'first'
|
||||
@group_category2.group_limit = 2
|
||||
@group_category2.save!
|
||||
@group_category3 = GroupCategory.create(
|
||||
:name => 'Test Group Category Deleted'
|
||||
)
|
||||
@group_category4 = GroupCategory.create(
|
||||
:name => 'Test Group Category Course'
|
||||
)
|
||||
@account.group_categories << @group_category1
|
||||
@account.group_categories << @group_category2
|
||||
@account.group_categories << @group_category3
|
||||
@course3.group_categories << @group_category4
|
||||
@group_category3.destroy
|
||||
@account.save!
|
||||
end
|
||||
|
||||
def create_some_terms()
|
||||
create_a_term
|
||||
@term2 = EnrollmentTerm.create(:name => 'Winter',:start_at => 3.weeks.ago,
|
||||
|
@ -224,13 +250,15 @@ describe "Default Account Reports" do
|
|||
end
|
||||
|
||||
def create_some_groups()
|
||||
create_an_account()
|
||||
create_some_group_categories
|
||||
@group1 = @account.groups.create(:name => 'group1name')
|
||||
@group1.group_category = @group_category1
|
||||
@group1.sis_source_id = 'group1sis'
|
||||
@group1.sis_batch_id = @sis.id
|
||||
@group1.save!
|
||||
@group2 = @sub_account.groups.create(:name => 'group2name')
|
||||
@group2.sis_source_id = 'group2sis'
|
||||
@group2.group_category = @group_category2
|
||||
@group2.sis_batch_id = @sis.id
|
||||
@group2.save!
|
||||
@group3 = @sub_account.groups.create(:name => 'group3name')
|
||||
|
@ -240,6 +268,10 @@ describe "Default Account Reports" do
|
|||
@group4.sis_batch_id = @sis.id
|
||||
@group4.save!
|
||||
@group4.destroy
|
||||
@group5 = @course1.groups.create(:name => 'group5name')
|
||||
@group5.sis_source_id = 'group5sis'
|
||||
@group5.sis_batch_id = @sis.id
|
||||
@group5.save!
|
||||
end
|
||||
|
||||
def create_some_group_memberships_n_stuff()
|
||||
|
@ -838,9 +870,10 @@ describe "Default Account Reports" do
|
|||
parameters["enrollment_term_id"] = @default_term.id
|
||||
parameters["groups"] = true
|
||||
parsed = read_report("sis_export_csv",{params: parameters, order: 2})
|
||||
expect(parsed.length).to eq 2
|
||||
expect(parsed.length).to eq 3
|
||||
expect(parsed[0]).to eq ["group1sis",nil,"group1name","available"]
|
||||
expect(parsed[1]).to eq ["group2sis","sub1","group2name","available"]
|
||||
expect(parsed[2]).to eq ["group5sis","sub1","group5name","available"]
|
||||
end
|
||||
|
||||
it "should run the SIS report with deleted groups" do
|
||||
|
@ -848,23 +881,26 @@ describe "Default Account Reports" do
|
|||
parameters["include_deleted"] = true
|
||||
parameters["groups"] = true
|
||||
parsed = read_report("sis_export_csv",{params: parameters, order: 2})
|
||||
expect(parsed.length).to eq 3
|
||||
expect(parsed.length).to eq 4
|
||||
expect(parsed[0]).to eq ["group1sis",nil,"group1name","available"]
|
||||
expect(parsed[1]).to eq ["group2sis","sub1","group2name","available"]
|
||||
expect(parsed[2]).to eq ["group4sis",nil,"group4name","deleted"]
|
||||
expect(parsed[3]).to eq ["group5sis","sub1","group5name","available"]
|
||||
end
|
||||
|
||||
it "should run the provisioning report" do
|
||||
parameters = {}
|
||||
parameters["groups"] = true
|
||||
parsed = read_report("provisioning_csv", {params: parameters, order: 4})
|
||||
expect(parsed.length).to eq 3
|
||||
expect(parsed.length).to eq 4
|
||||
expect(parsed[0]).to eq [@group1.id.to_s, "group1sis", @account.id.to_s,
|
||||
nil, "group1name", "available", "true"]
|
||||
nil, "group1name", "available", "true", @account.id.to_s, 'Account', @group1.group_category.id.to_s]
|
||||
expect(parsed[1]).to eq [@group2.id.to_s, "group2sis", @sub_account.id.to_s,
|
||||
"sub1", "group2name", "available", "true"]
|
||||
"sub1", "group2name", "available", "true", @sub_account.id.to_s, 'Account', @group2.group_category.id.to_s]
|
||||
expect(parsed[2]).to eq [@group3.id.to_s, nil, @sub_account.id.to_s,
|
||||
"sub1", "group3name", "available", "false"]
|
||||
"sub1", "group3name", "available", "false", @sub_account.id.to_s,'Account', nil]
|
||||
expect(parsed[3]).to eq [@group5.id.to_s, "group5sis", @sub_account.id.to_s,
|
||||
"sub1", "group5name", "available", "true", @course1.id.to_s,'Course', @group5.group_category.id.to_s]
|
||||
end
|
||||
|
||||
it "should run the provisioning report on a sub account" do
|
||||
|
@ -873,9 +909,48 @@ describe "Default Account Reports" do
|
|||
parsed = read_report("provisioning_csv", {params: parameters, account: @sub_account, order: 4})
|
||||
expect(parsed.length).to eq 2
|
||||
expect(parsed[0]).to eq [@group2.id.to_s, "group2sis", @sub_account.id.to_s,
|
||||
"sub1", "group2name", "available", "true"]
|
||||
"sub1", "group2name", "available", "true", @sub_account.id.to_s, 'Account', @group2.group_category.id.to_s]
|
||||
expect(parsed[1]).to eq [@group3.id.to_s, nil, @sub_account.id.to_s,
|
||||
"sub1", "group3name", "available", "false"]
|
||||
"sub1", "group3name", "available", "false", @sub_account.id.to_s, 'Account', nil]
|
||||
end
|
||||
end
|
||||
|
||||
describe "Group Categories" do
|
||||
before(:once) do
|
||||
create_some_groups
|
||||
@student_category = GroupCategory.where(name: "Student Groups").first
|
||||
end
|
||||
|
||||
it 'should run the provisioning report' do
|
||||
parameters = {}
|
||||
parameters["group_categories"] = true
|
||||
parsed = read_report("provisioning_csv", {params: parameters, order: 4})
|
||||
expect(parsed.length).to eq 4
|
||||
expect(parsed[0]).to eq [@group_category1.id.to_s, @account.id.to_s, "Account", "Test Group Category", nil, nil, nil, nil]
|
||||
expect(parsed[1]).to eq [@group_category2.id.to_s, @account.id.to_s, "Account", "Test Group Category2", nil, nil, "2", "first"]
|
||||
expect(parsed[2]).to eq [@group_category4.id.to_s, @course3.id.to_s, "Course", "Test Group Category Course", nil, nil, nil, nil]
|
||||
expect(parsed[3]).to eq [@student_category.id.to_s, @course1.id.to_s, "Course", "Student Groups", "student_organized", nil, nil, nil]
|
||||
end
|
||||
|
||||
it 'should run the provisioning report for a sub account' do
|
||||
parameters = {}
|
||||
parameters["group_categories"] = true
|
||||
parsed = read_report("provisioning_csv", {params: parameters, order: 4, account: @sub_account})
|
||||
expect(parsed.length).to eq 1
|
||||
expect(parsed[0]).to eq [@student_category.id.to_s, @course1.id.to_s, "Course", "Student Groups", "student_organized", nil, nil, nil]
|
||||
end
|
||||
|
||||
it 'should run the report for deleted categories' do
|
||||
parameters = {}
|
||||
parameters["group_categories"] = true
|
||||
parameters["include_deleted"] = true
|
||||
parsed = read_report("provisioning_csv", {params: parameters, order: 4})
|
||||
expect(parsed.length).to eq 5
|
||||
expect(parsed[0]).to eq [@group_category1.id.to_s, @account.id.to_s, "Account", "Test Group Category", nil, nil, nil, nil]
|
||||
expect(parsed[1]).to eq [@group_category2.id.to_s, @account.id.to_s, "Account", "Test Group Category2", nil, nil, "2", "first"]
|
||||
expect(parsed[2]).to eq [@group_category3.id.to_s, @account.id.to_s, "Account", "Test Group Category Deleted", nil, nil, nil, nil]
|
||||
expect(parsed[3]).to eq [@group_category4.id.to_s, @course3.id.to_s, "Course", "Test Group Category Course", nil, nil, nil, nil]
|
||||
expect(parsed[4]).to eq [@student_category.id.to_s, @course1.id.to_s, "Course", "Student Groups", "student_organized", nil, nil, nil]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue