-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store privacy policy acceptance records (#4095)
- Loading branch information
1 parent
962062e
commit b5d5d5e
Showing
11 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class PrivacyPolicyConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "privacy_policy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 5.1.1 on 2024-09-30 23:48 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PrivacyPolicyAcceptanceRecord', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('accepted_at', models.DateTimeField(auto_now_add=True)), | ||
('ip_address', models.GenericIPAddressField()), | ||
('user_agent', models.TextField()), | ||
('privacy_policy', models.CharField(max_length=1024)), | ||
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.db import models | ||
|
||
|
||
class PrivacyPolicyAcceptanceRecord(models.Model): | ||
user = models.ForeignKey("users.User", on_delete=models.PROTECT) | ||
accepted_at = models.DateTimeField(auto_now_add=True) | ||
ip_address = models.GenericIPAddressField() | ||
user_agent = models.TextField() | ||
privacy_policy = models.CharField(max_length=1024) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django.http.request import HttpRequest | ||
from api.utils import get_ip | ||
from privacy_policy.models import PrivacyPolicyAcceptanceRecord | ||
|
||
|
||
def record_privacy_policy_acceptance( | ||
request: HttpRequest, privacy_policy: str | ||
) -> PrivacyPolicyAcceptanceRecord: | ||
user = request.user | ||
ip = get_ip(request) | ||
user_agent = request.headers.get("User-Agent", "") | ||
|
||
return PrivacyPolicyAcceptanceRecord.objects.create( | ||
user=user, | ||
ip_address=ip, | ||
user_agent=user_agent, | ||
privacy_policy=privacy_policy, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import time_machine | ||
from django.utils import timezone | ||
|
||
from privacy_policy.record import record_privacy_policy_acceptance | ||
from users.tests.factories import UserFactory | ||
|
||
|
||
def test_record_privacy_policy_acceptance(rf): | ||
request = rf.get("/") | ||
request.user = UserFactory(username="testuser", password="testpassword") | ||
request.headers = { | ||
"User-Agent": "Test User Agent", | ||
"x-forwarded-for": "192.168.0.1", | ||
} | ||
|
||
accepted_at = timezone.now() | ||
|
||
with time_machine.travel(accepted_at, tick=False): | ||
record = record_privacy_policy_acceptance(request, "test-privacy-policy") | ||
|
||
assert record.user_id == request.user.id | ||
assert record.accepted_at == accepted_at | ||
assert record.ip_address == "192.168.0.1" | ||
assert record.user_agent == "Test User Agent" | ||
assert record.privacy_policy == "test-privacy-policy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters