Skip to content

Commit 8cd5abc

Browse files
authored
add impersonation styling to django admin (#1214)
1 parent b1440be commit 8cd5abc

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

codecov/settings_base.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@
7676
TEMPLATES = [
7777
{
7878
"BACKEND": "django.template.backends.django.DjangoTemplates",
79-
"DIRS": [],
79+
"DIRS": [
80+
"templates",
81+
],
8082
"APP_DIRS": True,
8183
"OPTIONS": {
8284
"context_processors": [

templates/admin/base_site.html

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{% extends "admin/base_site.html" %}
2+
{% load i18n %}
3+
4+
{% block branding %}
5+
<h1 id="site-name">
6+
<a href="{% url 'admin:index' %}">
7+
{% trans 'Django administration' %}
8+
<span id="impersonation-notice" style="display: none;">
9+
- Impersonating (return to codecov.io and log out)
10+
</span>
11+
</a>
12+
</h1>
13+
{% endblock %}
14+
15+
{% block extrahead %}
16+
{{ block.super }}
17+
<style>
18+
/* Custom styling when cookie is present */
19+
html[data-theme="light"].impersonation, :root.impersonation {
20+
--primary: #ff9800;
21+
--secondary: #ff9800;
22+
--link-fg: #ff9800;
23+
--link-selected-fg: #ff9800;
24+
}
25+
26+
#header.impersonation {
27+
background-color: #ff9800 !important;
28+
}
29+
</style>
30+
<script>
31+
document.addEventListener('DOMContentLoaded', function() {
32+
function getCookie(name) {
33+
const value = `; ${document.cookie}`;
34+
const parts = value.split(`; ${name}=`);
35+
if (parts.length === 2) return parts.pop().split(';').shift();
36+
return null;
37+
}
38+
39+
// Check for the "staff_user" cookie
40+
const staffUserCookie = getCookie('staff_user');
41+
42+
if (staffUserCookie) {
43+
// Modify the header appearance
44+
const headerElement = document.querySelector('#header');
45+
if (headerElement) {
46+
headerElement.classList.add('impersonation');
47+
}
48+
49+
// Add class to html element for theme variables
50+
document.documentElement.classList.add('impersonation');
51+
52+
// Show the impersonation notice
53+
const impersonationNotice = document.getElementById('impersonation-notice');
54+
if (impersonationNotice) {
55+
impersonationNotice.style.display = 'inline';
56+
}
57+
}
58+
});
59+
</script>
60+
{% endblock %}

0 commit comments

Comments
 (0)