mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-12 05:58:18 +02:00
Use waffle flag
Genius suggestion by abbrodrick!
This commit is contained in:
parent
d36435a981
commit
d8265dd423
6 changed files with 5 additions and 117 deletions
|
@ -1,55 +0,0 @@
|
||||||
# Generated by Django 4.2.10 on 2024-05-24 15:15
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.utils.timezone
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
("registrar", "0095_user_middle_name_user_title"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.CreateModel(
|
|
||||||
name="WaffleSwitch",
|
|
||||||
fields=[
|
|
||||||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")),
|
|
||||||
(
|
|
||||||
"name",
|
|
||||||
models.CharField(
|
|
||||||
help_text="The human/computer readable name.", max_length=100, unique=True, verbose_name="Name"
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"active",
|
|
||||||
models.BooleanField(default=False, help_text="Is this switch active?", verbose_name="Active"),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"note",
|
|
||||||
models.TextField(blank=True, help_text="Note where this Switch is used.", verbose_name="Note"),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"created",
|
|
||||||
models.DateTimeField(
|
|
||||||
db_index=True,
|
|
||||||
default=django.utils.timezone.now,
|
|
||||||
help_text="Date when this Switch was created.",
|
|
||||||
verbose_name="Created",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"modified",
|
|
||||||
models.DateTimeField(
|
|
||||||
default=django.utils.timezone.now,
|
|
||||||
help_text="Date when this Switch was last modified.",
|
|
||||||
verbose_name="Modified",
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
options={
|
|
||||||
"verbose_name": "waffle switch",
|
|
||||||
"verbose_name_plural": "Waffle switches",
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -1,37 +0,0 @@
|
||||||
# This migration creates the create_full_access_group and create_cisa_analyst_group groups
|
|
||||||
# It is dependent on 0079 (which populates federal agencies)
|
|
||||||
# If permissions on the groups need changing, edit CISA_ANALYST_GROUP_PERMISSIONS
|
|
||||||
# in the user_group model then:
|
|
||||||
# [NOT RECOMMENDED]
|
|
||||||
# step 1: docker-compose exec app ./manage.py migrate --fake registrar 0035_contenttypes_permissions
|
|
||||||
# step 2: docker-compose exec app ./manage.py migrate registrar 0036_create_groups
|
|
||||||
# step 3: fake run the latest migration in the migrations list
|
|
||||||
# [RECOMMENDED]
|
|
||||||
# Alternatively:
|
|
||||||
# step 1: duplicate the migration that loads data
|
|
||||||
# step 2: docker-compose exec app ./manage.py migrate
|
|
||||||
|
|
||||||
from django.db import migrations
|
|
||||||
from registrar.models import UserGroup
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
|
|
||||||
# For linting: RunPython expects a function reference,
|
|
||||||
# so let's give it one
|
|
||||||
def create_groups(apps, schema_editor) -> Any:
|
|
||||||
UserGroup.create_cisa_analyst_group(apps, schema_editor)
|
|
||||||
UserGroup.create_full_access_group(apps, schema_editor)
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
dependencies = [
|
|
||||||
("registrar", "0096_waffleswitch"),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.RunPython(
|
|
||||||
create_groups,
|
|
||||||
reverse_code=migrations.RunPython.noop,
|
|
||||||
atomic=True,
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -16,7 +16,6 @@ from .website import Website
|
||||||
from .transition_domain import TransitionDomain
|
from .transition_domain import TransitionDomain
|
||||||
from .verified_by_staff import VerifiedByStaff
|
from .verified_by_staff import VerifiedByStaff
|
||||||
from .waffle_flag import WaffleFlag
|
from .waffle_flag import WaffleFlag
|
||||||
from .waffle_switch import WaffleSwitch
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
@ -37,7 +36,6 @@ __all__ = [
|
||||||
"TransitionDomain",
|
"TransitionDomain",
|
||||||
"VerifiedByStaff",
|
"VerifiedByStaff",
|
||||||
"WaffleFlag",
|
"WaffleFlag",
|
||||||
"WaffleSwitch",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
auditlog.register(Contact)
|
auditlog.register(Contact)
|
||||||
|
@ -57,4 +55,3 @@ auditlog.register(Website)
|
||||||
auditlog.register(TransitionDomain)
|
auditlog.register(TransitionDomain)
|
||||||
auditlog.register(VerifiedByStaff)
|
auditlog.register(VerifiedByStaff)
|
||||||
auditlog.register(WaffleFlag)
|
auditlog.register(WaffleFlag)
|
||||||
auditlog.register(WaffleSwitch)
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
from waffle.models import AbstractBaseSwitch
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class WaffleSwitch(AbstractBaseSwitch):
|
|
||||||
"""
|
|
||||||
Custom implementation of django-waffles 'switch' object.
|
|
||||||
Read more here: https://waffle.readthedocs.io/en/stable/types/switch.html
|
|
||||||
Use this class when dealing with switches.
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""Contains meta information about this class"""
|
|
||||||
|
|
||||||
verbose_name = "waffle switch"
|
|
||||||
verbose_name_plural = "Waffle switches"
|
|
|
@ -3,7 +3,7 @@
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from waffle.testutils import override_switch
|
from waffle.testutils import override_flag
|
||||||
from registrar.utility import email
|
from registrar.utility import email
|
||||||
from registrar.utility.email import send_templated_email
|
from registrar.utility.email import send_templated_email
|
||||||
from .common import completed_domain_request, less_console_noise
|
from .common import completed_domain_request, less_console_noise
|
||||||
|
@ -18,7 +18,7 @@ class TestEmails(TestCase):
|
||||||
self.mock_client = self.mock_client_class.return_value
|
self.mock_client = self.mock_client_class.return_value
|
||||||
|
|
||||||
@boto3_mocking.patching
|
@boto3_mocking.patching
|
||||||
@override_switch("disable_email_sending", active=True)
|
@override_flag("disable_email_sending", active=True)
|
||||||
def test_disable_email_switch(self):
|
def test_disable_email_switch(self):
|
||||||
"""Test if the 'disable_email_sending' stops emails from being sent """
|
"""Test if the 'disable_email_sending' stops emails from being sent """
|
||||||
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
with boto3_mocking.clients.handler_for("sesv2", self.mock_client_class):
|
||||||
|
|
|
@ -8,7 +8,7 @@ from django.template.loader import get_template
|
||||||
from email.mime.application import MIMEApplication
|
from email.mime.application import MIMEApplication
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from waffle import switch_is_active
|
from waffle import flag_is_active
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -36,7 +36,8 @@ def send_templated_email(
|
||||||
|
|
||||||
Raises EmailSendingError if SES client could not be accessed
|
Raises EmailSendingError if SES client could not be accessed
|
||||||
"""
|
"""
|
||||||
if switch_is_active("disable_email_sending") and not settings.IS_PRODUCTION:
|
|
||||||
|
if flag_is_active(None, "disable_email_sending") and not settings.IS_PRODUCTION:
|
||||||
message = "Could not send email. Email sending is disabled due to switch 'disable_email_sending'."
|
message = "Could not send email. Email sending is disabled due to switch 'disable_email_sending'."
|
||||||
raise EmailSendingError(message)
|
raise EmailSendingError(message)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue