From e46000ecdfb4d954f1ba09fe784435195de77f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Tue, 20 Jul 2021 11:16:12 +0300 Subject: [PATCH] Add admin action to log in as any user --- CHANGELOG.md | 1 + hc/accounts/admin.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f13cbe73..cfca89e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. ### Improvements - Use multicolor channel icons for better appearance in the dark mode - Add SITE_LOGO_URL setting (#323) +- Add admin action to log in as any user ### Bug Fixes - Fix dark mode styling issues in Cron Syntax Cheatsheet diff --git a/hc/accounts/admin.py b/hc/accounts/admin.py index 5487dabf..7bff3fca 100644 --- a/hc/accounts/admin.py +++ b/hc/accounts/admin.py @@ -1,7 +1,9 @@ from django.contrib import admin +from django.contrib.auth import login as auth_login from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from django.db.models import Count, F +from django.shortcuts import redirect from django.template.loader import render_to_string from django.urls import reverse from django.utils.html import escape @@ -121,6 +123,7 @@ class ProfileAdmin(admin.ModelAdmin): NumChecksFilter, "theme", ) + actions = ("login",) fieldsets = (ProfileFieldset.tuple(), TeamFieldset.tuple()) @@ -160,6 +163,11 @@ class ProfileAdmin(admin.ModelAdmin): def sms(self, obj): return "%d of %d" % (obj.sms_sent, obj.sms_limit) + def login(self, request, qs): + profile = qs.get() + auth_login(request, profile.user, "hc.accounts.backends.EmailBackend") + return redirect("hc-index") + @admin.register(Project) class ProjectAdmin(admin.ModelAdmin):