Skip to content

Commit 52a9221

Browse files
authored
Add indicators for unique login expiration status (#19084)
1 parent b70f937 commit 52a9221

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

tests/unit/test_filters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ def test_now():
2424
assert now() <= datetime.datetime.now()
2525

2626

27+
def test_now_with_timezone():
28+
assert isinstance(now(tz=True), datetime.datetime)
29+
assert now(tz=True).tzinfo is not None
30+
assert now(tz=True) < datetime.datetime.now(datetime.UTC)
31+
32+
2733
def test_camo_url():
2834
request = pretend.stub(
2935
registry=pretend.stub(

warehouse/admin/templates/admin/users/detail.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ <h3 class="card-title">Unique logins</h3>
10021002
<th scope="col">Created</th>
10031003
<th scope="col">IP address</th>
10041004
<th scope="col">Status</th>
1005+
<th scope="col">Expired?</th>
10051006
<th scope="col">Device Information</th>
10061007
</tr>
10071008
</thead>
@@ -1011,6 +1012,17 @@ <h3 class="card-title">Unique logins</h3>
10111012
<td>{{ login.created }}</td>
10121013
<td><a href="{{ request.route_path('admin.ip_address.detail', ip_address=login.ip_address ) }}">{{ login.ip_address }}</a></td>
10131014
<td>{{ login.status.value }}</td>
1015+
<td>
1016+
{% if login.status.value == 'pending' %}
1017+
{% if login.expires < now(tz=True) %}
1018+
<span title="Expired: {{ login.expires|format_datetime }}">🔴</span>
1019+
{% else %}
1020+
<span title="Expires: {{ login.expires|format_datetime }}">🟠</span>
1021+
{% endif %}
1022+
{% elif login.status.value == 'confirmed' %}
1023+
<span title="Confirmed">🟢</span>
1024+
{% endif %}
1025+
</td>
10141026
<td>{{ login.device_information }}</td>
10151027
</tr>
10161028
{% endfor %}

warehouse/utils/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import datetime
44

55

6-
def now() -> datetime.datetime:
7-
"""Return the current datetime in UTC without a timezone."""
8-
return datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
6+
def now(tz=False) -> datetime.datetime:
7+
"""Return the current datetime in UTC with or without a timezone."""
8+
now = datetime.datetime.now(datetime.UTC)
9+
return now if tz else now.replace(tzinfo=None)
910

1011

1112
def dotted_navigator(path):

0 commit comments

Comments
 (0)