Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Render download test result button on assignment summary page only if the assignment has automated testing (#7417)
- Group test results by Test Groups id (#7422)
- Display HTML previews of RMarkdown files (#7394)
- Allow instructors to assign scans to inactive students (#7482)
- Added members parameter to add_group_api to support explicit member assignment during group creation (#7481)
- Modified add_group_api to use username as group name for individual assignments (#7481)

Expand Down
9 changes: 5 additions & 4 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,25 @@ def assign_scans
def get_names
names = current_course.students
.joins(:user)
.where('(lower(first_name) like ? OR
.where("(lower(first_name) like ? OR
lower(last_name) like ? OR
lower(user_name) like ? OR
id_number like ?) AND roles.hidden = false AND roles.id NOT IN (?)',
id_number like ?) AND roles.hidden IN (?) AND roles.id NOT IN (?)",
"#{ApplicationRecord.sanitize_sql_like(params[:term].downcase)}%",
"#{ApplicationRecord.sanitize_sql_like(params[:term].downcase)}%",
"#{ApplicationRecord.sanitize_sql_like(params[:term].downcase)}%",
"#{ApplicationRecord.sanitize_sql_like(params[:term])}%",
params[:display_inactive] == 'true' ? [true, false] : [false],
Membership.select(:role_id)
.joins(:grouping)
.where(groupings: { assessment_id: params[:assignment_id] }))
.pluck_to_hash(:id, 'users.id_number', 'users.user_name',
'users.first_name', 'users.last_name')
'users.first_name', 'users.last_name', 'roles.hidden')
names = names.map do |h|
{ id: h[:id],
id_number: h['users.id_number'],
user_name: h['users.user_name'],
value: "#{h['users.first_name']} #{h['users.last_name']}" }
value: "#{h['users.first_name']} #{h['users.last_name']}#{h['roles.hidden'] ? ' (inactive)' : ''}" }
end
render json: names
end
Expand Down
8 changes: 6 additions & 2 deletions app/views/groups/assign_scans.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
$.getJSON("get_names",
{
assignment_id: <%= @assignment.id %>,
term: $("#names").val()
term: $("#names").val(),
display_inactive: $("#display_inactive").is(':checked')
},
response);
},
Expand Down Expand Up @@ -122,8 +123,11 @@
<input id="grouping_id" name="g_id" value="" type="hidden">

<p>
<label for="skip"><%= t('exam_templates.assign_scans.skip_group') %></label>
<input type="checkbox" name="skip" id="skip" value="1">
<label for="skip"><%= t('exam_templates.assign_scans.skip_group') %></label>
&nbsp;&nbsp;
<input type="checkbox" name="display_inactive" id="display_inactive">
<label for="display_inactive"><%= t('exam_templates.assign_scans.display_inactive') %></label>
</p>
<p>
<button type="submit"><%= t('save') %></button>
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/exam_templates/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ en:
page_number: Page Number
upside_down: Page Upside Down?
assign_scans:
display_inactive: Display inactive students
done: All groups have been successfully assigned students
help: Assign students to scanned exam groups based on printed student names.
no_cover_page: This submission does not have a cover page.
Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/groups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,13 @@
'value' => "#{students[0].first_name} #{students[0].last_name}" }]
end

let(:expected_inactive) do
[{ 'id' => students[3].id,
'id_number' => students[3].id_number,
'user_name' => students[3].user_name,
'value' => "#{students[3].first_name} #{students[3].last_name} (inactive)" }]
end

it 'returns matches for user_name' do
post_as instructor, :get_names, params: { course_id: course.id,
assignment_id: assignment.id,
Expand Down Expand Up @@ -810,6 +817,17 @@
expect(response.parsed_body).to match_array expected
end

it 'returns matches for inactive students' do
post_as instructor, :get_names, params: { course_id: course.id,
assignment_id: assignment.id,
assignment: assignment.id,
term: 'fhe',
format: :json,
display_inactive: true }

expect(response.parsed_body).to match_array expected_inactive
end

context 'when users are already in groups' do
before { create(:grouping_with_inviter, assignment: assignment, inviter: students[0]) }

Expand Down