• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DemocracyClub / aggregator-api / 93f28176-d12b-44aa-8582-a03ba3be77a2

05 Dec 2023 03:31PM UTC coverage: 77.419% (-0.8%) from 78.236%
93f28176-d12b-44aa-8582-a03ba3be77a2

push

circleci

web-flow
Merge pull request #441 from DemocracyClub/self-serve-api-keys

Self-serve API keys

315 of 422 new or added lines in 17 files covered. (74.64%)

1 existing line in 1 file now uncovered.

864 of 1116 relevant lines covered (77.42%)

0.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/frontend/apps/api_users/utils.py
1
import os
1✔
2

3
from django.core.mail import send_mail
1✔
4
from django.http import HttpRequest
1✔
5
from django.urls import reverse
1✔
6

7
from api_users.models import APIKey
1✔
8

9

10
def get_domain(request: HttpRequest):
1✔
NEW
11
    return os.environ.get("APP_DOMAIN", request.get_host())
×
12

13

14
def send_new_key_notification(request, api_key: APIKey):
1✔
15
    user_admin_url = request.build_absolute_uri(
1✔
16
        reverse(
17
            "admin:api_users_customuser_change",
18
            kwargs={"object_id": api_key.user_id},
19
        )
20
    )
21

22
    message = f"""
1✔
23
    {api_key.user.name} has just created a new API key called {api_key.name}.
24

25
    This is a {api_key.key_type} key.
26

27
    They said the usage reason was:
28

29
    > "{api_key.usage_reason}"
30

31
    You can contact {api_key.user.name} on {api_key.user.email}.
32

33
    Or, you can view the user in the admin interface here: {user_admin_url}
34

35
    """
36
    send_mail(
1✔
37
        "New email key creation",
38
        message,
39
        "developers@democracyclub.org.uk",
40
        ["hello@democracyclub.org.uk"],
41
        fail_silently=True,
42
    )
43
    return message
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc