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
14 changes: 6 additions & 8 deletions app/controllers/course_user_data_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,18 @@ def sudo
redirect_to([@cud.course]) && return
end

return unless request.post?
@users, @usersEncoded = @course.get_autocomplete_data

sudo_user = User.where(email: params[:sudo_email]).first
unless sudo_user
flash[:error] = "User #{params[:sudo_email]} does not exist"
redirect_to(action: :sudo) && return
end
return unless request.post?

sudo_cud = @course.course_user_data.where(user_id: sudo_user.id).first
sudo_cud = @course.course_user_data.where(id: params[:sudo_id]).first
unless sudo_cud
flash[:error] = "User #{params[:sudo_email]} does not exist in the course"
flash[:error] = "User does not exist in the course"
redirect_to(action: :sudo) && return
end

sudo_user = User.where(id: sudo_cud.user_id).first

unless @cud.can_sudo_to?(sudo_cud)
flash[:error] = "You do not have the privileges to act as " \
"#{sudo_cud.display_name}"
Expand Down
2 changes: 1 addition & 1 deletion app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def asmts_before_date(date)
asmts.where("due_at < ?", date)
end

# Used by manage extensions and create submission
# Used by manage extensions, create submission, and sudo
def get_autocomplete_data
users = {}
usersEncoded = {}
Expand Down
11 changes: 10 additions & 1 deletion app/views/course_user_data/sudo.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<% content_for :javascripts do %>
<%= render partial: "components/autocomplete", locals: { hiddenCUDField: "#sudo_id" } %>
<% 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>
<%= form_tag do %>
Act as user (email): <%= email_field_tag :sudo_email %>
<p><b>Act as user (email):</b></p>
<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>
<%= hidden_field_tag(:sudo_id) %>
<%= submit_tag "Sudo", {:value=>"Sudo", :class=> "btn primary"} %>
<% end %>
</p>
2 changes: 1 addition & 1 deletion app/views/submissions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<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>
</div>
<%= f.hidden_field(:course_user_datum_id)%>

<% else %>
Expand Down