Skip to content

Fix "log as user" functionality - convert GET to POST requests#139

Merged
alexeygrigorev merged 4 commits into
mainfrom
copilot/fix-log-as-user-functionality
Jan 16, 2026
Merged

Fix "log as user" functionality - convert GET to POST requests#139
alexeygrigorev merged 4 commits into
mainfrom
copilot/fix-log-as-user-functionality

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 16, 2026

The "log as user" feature in homework and project submission pages was non-functional because templates used GET requests while django-loginas requires POST for security.

Changes

Templates - Converted links to POST forms:

  • cadmin/templates/cadmin/homework_submissions.html
  • cadmin/templates/cadmin/project_submissions.html
<!-- Before: GET request via link -->
<a href="/admin/login/user/{{ user.id }}/?next=...">Log in as</a>

<!-- After: POST request via form -->
<form method="post" action="{% url 'loginas-user-login' user.id %}">
  {% csrf_token %}
  <input type="hidden" name="next" value="...">
  <button type="submit" class="btn btn-sm btn-info">Log in as</button>
</form>

Settings - Added authorization function restricting staff from impersonating other staff:

def can_login_as(request, target_user):
    """Staff can impersonate students only, not other staff/superusers."""
    return request.user.is_staff and not target_user.is_staff

CAN_LOGIN_AS = can_login_as

Tests - Added coverage for:

  • GET requests properly rejected (405)
  • POST requests work correctly
  • Staff cannot impersonate staff

Screenshots

Homework submissions page with working "Log in as" buttons:
image

Successfully impersonated user (note navbar shows student email):
image

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: /usr/bin/curl curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Log as user not working</issue_title>
<issue_description>In the latest PR (check it!) we implemented log as user functionality. It's not working. Let's cover it with tests first to make sure it fails and then fix it</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 16, 2026 14:54
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix log as user functionality by adding tests Fix "log as user" functionality - convert GET to POST requests Jan 16, 2026
Copilot AI requested a review from alexeygrigorev January 16, 2026 15:03
@alexeygrigorev alexeygrigorev marked this pull request as ready for review January 16, 2026 15:20
@alexeygrigorev alexeygrigorev merged commit 5527d91 into main Jan 16, 2026
2 checks passed
@alexeygrigorev alexeygrigorev deleted the copilot/fix-log-as-user-functionality branch January 24, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log as user not working

2 participants