fet(users): Add SuppressedEmailVerification model (#21561)
This commit is contained in:
Родитель
3ab0252f3a
Коммит
58e827015f
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 4.2.8 on 2023-12-11 17:23
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
import olympia.amo.models
|
||||
import uuid
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('users', '0015_clear_bad_homepage_url_data'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='SuppressedEmailVerification',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('created', models.DateTimeField(blank=True, default=django.utils.timezone.now, editable=False)),
|
||||
('modified', models.DateTimeField(auto_now=True)),
|
||||
('confirmation_code', models.CharField(default=uuid.uuid4, max_length=255)),
|
||||
('suppressed_email', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='suppressed_email', to='users.suppressedemail')),
|
||||
],
|
||||
options={
|
||||
'get_latest_by': 'created',
|
||||
'abstract': False,
|
||||
'base_manager_name': 'objects',
|
||||
},
|
||||
bases=(olympia.amo.models.SaveUpdateMixin, models.Model),
|
||||
),
|
||||
]
|
|
@ -4,7 +4,8 @@ import os
|
|||
import random
|
||||
import re
|
||||
import time
|
||||
from datetime import datetime
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
from fnmatch import fnmatchcase
|
||||
from urllib.parse import urljoin
|
||||
|
||||
|
@ -1343,3 +1344,18 @@ class BannedUserContent(ModelBase):
|
|||
|
||||
class SuppressedEmail(ModelBase):
|
||||
email = models.EmailField(unique=True, null=False, max_length=75)
|
||||
|
||||
|
||||
class SuppressedEmailVerification(ModelBase):
|
||||
confirmation_code = models.CharField(
|
||||
max_length=255, null=False, blank=False, default=uuid.uuid4
|
||||
)
|
||||
suppressed_email = models.OneToOneField(
|
||||
SuppressedEmail,
|
||||
related_name='suppressed_email',
|
||||
on_delete=models.CASCADE,
|
||||
)
|
||||
|
||||
@property
|
||||
def expiration(self):
|
||||
return self.created + timedelta(days=30)
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.contrib.auth import get_user
|
|||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.core import mail
|
||||
from django.db import models
|
||||
from django.db.utils import IntegrityError
|
||||
from django.test.client import RequestFactory
|
||||
from django.test.utils import override_settings
|
||||
|
||||
|
@ -34,6 +35,8 @@ from olympia.users.models import (
|
|||
EmailUserRestriction,
|
||||
IPNetworkUserRestriction,
|
||||
IPReputationRestriction,
|
||||
SuppressedEmail,
|
||||
SuppressedEmailVerification,
|
||||
UserEmailField,
|
||||
UserProfile,
|
||||
generate_auth_id,
|
||||
|
@ -1499,3 +1502,37 @@ def test_get_session_auth_hash_is_used_for_session_auth():
|
|||
|
||||
user.update(auth_id=generate_auth_id())
|
||||
assert get_user(request) != user
|
||||
|
||||
|
||||
class TestSuppressedEmailVerification(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.suppressed_email = SuppressedEmail.objects.create(email='test@example.com')
|
||||
|
||||
def test_raise_for_duplicate_email_block(self):
|
||||
email_verification = SuppressedEmailVerification.objects.create(
|
||||
suppressed_email=self.suppressed_email
|
||||
)
|
||||
|
||||
with pytest.raises(IntegrityError):
|
||||
SuppressedEmailVerification.objects.create(
|
||||
suppressed_email=email_verification.suppressed_email
|
||||
)
|
||||
|
||||
def test_deletes_verification_with_block(self):
|
||||
email_verification = SuppressedEmailVerification.objects.create(
|
||||
suppressed_email=self.suppressed_email
|
||||
)
|
||||
self.suppressed_email.delete()
|
||||
assert not SuppressedEmailVerification.objects.filter(
|
||||
pk=email_verification.pk
|
||||
).exists()
|
||||
|
||||
def test_expiration_thirty_days_after_creation(self):
|
||||
email_verification = SuppressedEmailVerification.objects.create(
|
||||
suppressed_email=self.suppressed_email
|
||||
)
|
||||
|
||||
expected_expiration_date = email_verification.created + timedelta(days=30)
|
||||
|
||||
assert email_verification.expiration == expected_expiration_date
|
||||
|
|
Загрузка…
Ссылка в новой задаче