Skip to content
Closed
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
5 changes: 5 additions & 0 deletions app/controllers/course_user_data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ def sudo
redirect_to([@cud.course]) && return
end

@users = {}
@course.course_user_data.each do |cud|
@users[cud.full_name_with_email] = cud.email
end

return unless request.post?

sudo_user = User.where(email: params[:sudo_email]).first
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/extensions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ class ExtensionsController < ApplicationController
def index
@extensions = @assessment.extensions.includes(:course_user_datum)
@users = {}
@usersEncoded = {}
@course.course_user_data.each do |cud|
@users[cud.full_name_with_email] = cud.id
@usersEncoded[Base64.encode64(cud.full_name_with_email.strip).strip] = cud.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we have this Base64 encoding here for a reason, perhaps for students who username is not stored in base64 format? I will have to take a further look before deciding what's the appropriate fix here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original issue: #931

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, autocomplete seems to strip leading spaces, etc. from names which can make ID lookup fail.

end
@new_extension = @assessment.extensions.new
end
Expand Down
39 changes: 36 additions & 3 deletions app/views/course_user_data/sudo.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
<% content_for :javascripts do %>
<script type="application/javascript">
jQuery(function() {
userData = {
<% @users.each do |k,v| %>
"<%= k %>": "<%= v %>",
<% end %>
};

/* user autocomplete */
$studentAutocompleteField = $('#student_autocomplete');
$hiddenCUDField = $('#sudo_email');
$studentAutocompleteField.autocomplete({
data: {
<% @users.each do |k,v| %>
"<%= k %>": null,
<% end %>
}
});

/* track changes in student autocomplete field */
$studentAutocompleteField.on('change', function() {
$hiddenCUDField.val(userData[$studentAutocompleteField.val()]);
})
});
</script>
<% end %>

<h2>Act as User</h2>

<p>You can use sudo to examine how Autolab appears to other users. You can also change your permission levels to see what your course assistants or students generically see.</p>

<p>
<div>
<%= form_tag do %>
Act as user (email): <%= email_field_tag :sudo_email %>
Act as user (email):
<div class="input-field">
<input type="text" size="3" id="student_autocomplete" class="autocomplete" autocomplete="off"/>
<label for="student_autocomplete">Start typing student name or email</label>
</div><br>
<%= hidden_field_tag(:sudo_email)%>
<%= submit_tag "Sudo", {:value=>"Sudo", :class=> "btn primary"} %>
<% end %>
</p>
</div>
4 changes: 2 additions & 2 deletions app/views/extensions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
jQuery(function() {
/* match user name/email with cud_id */
userData = {
<% @usersEncoded.each do |k,v| %>
<% @users.each do |k,v| %>
"<%= k %>": "<%= v %>",
<% end %>
};
Expand All @@ -24,7 +24,7 @@

/* track changes in student autocomplete field */
$studentAutocompleteField.on('change', function() {
$hiddenCUDField.val(userData[window.btoa($studentAutocompleteField.val())]);
$hiddenCUDField.val(userData[$studentAutocompleteField.val()]);
})

/* set up dates */
Expand Down
2 changes: 1 addition & 1 deletion app/views/submissions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/* user autocomplete */
$studentAutocompleteField = $('#student_autocomplete');
$hiddenCUDField = $('#extension_course_user_datum_id');
$hiddenCUDField = $('#submission_course_user_datum_id');
$studentAutocompleteField.autocomplete({
data: {
<% @cuds.each do |k,v| %>
Expand Down