From ca4494c09ecb1930591d9556f65545efcb8435f3 Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 11 Mar 2026 16:01:43 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(backend)=20align=20Applicati?= =?UTF-8?q?on=20model=20field=20with=20`is=5Factive`=20convention?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most models in the project use `is_active` rather than `active`. The Application model was not aligned with this convention. Rename the field and add a migration to standardize the naming. Update related tests accordingly. This change should not introduce breaking changes for external applications. --- CHANGELOG.md | 1 + .../core/external_api/authentication.py | 2 +- src/backend/core/external_api/viewsets.py | 2 +- src/backend/core/factories.py | 2 +- ...018_rename_active_application_is_active.py | 18 +++++++++++++++++ src/backend/core/models.py | 2 +- .../core/tests/test_external_api_rooms.py | 2 +- .../core/tests/test_external_api_token.py | 20 +++++++++---------- .../core/tests/test_models_applications.py | 2 +- 9 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 src/backend/core/migrations/0018_rename_active_application_is_active.py diff --git a/CHANGELOG.md b/CHANGELOG.md index c8bb1dd9..de4573ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to - ♿(frontend) improve ui and aria labels for help article links #1108 - 🌐(frontend) improve German translation #1125 - 🔨(python-env) migrate meet main app to UV #1120 +- ♻️(backend) align Application model field with `is_active` convention ### Fixed diff --git a/src/backend/core/external_api/authentication.py b/src/backend/core/external_api/authentication.py index c16f6573..eb5eea9d 100644 --- a/src/backend/core/external_api/authentication.py +++ b/src/backend/core/external_api/authentication.py @@ -203,7 +203,7 @@ class ApplicationJWTAuthentication(BaseJWTAuthentication): logger.warning("Application not found: %s", client_id) raise exceptions.AuthenticationFailed("Application not found.") from e - if not application.active: + if not application.is_active: logger.warning( "Inactive application attempted authentication: %s", client_id ) diff --git a/src/backend/core/external_api/viewsets.py b/src/backend/core/external_api/viewsets.py index 5a0e550c..530ef9cd 100644 --- a/src/backend/core/external_api/viewsets.py +++ b/src/backend/core/external_api/viewsets.py @@ -61,7 +61,7 @@ class ApplicationViewSet(viewsets.ViewSet): except models.Application.DoesNotExist as e: raise drf_exceptions.AuthenticationFailed("Invalid credentials") from e - if not application.active: + if not application.is_active: raise drf_exceptions.AuthenticationFailed("Application is inactive") if not check_password(client_secret, application.client_secret): diff --git a/src/backend/core/factories.py b/src/backend/core/factories.py index de56f98b..a50f1b23 100644 --- a/src/backend/core/factories.py +++ b/src/backend/core/factories.py @@ -129,7 +129,7 @@ class ApplicationFactory(factory.django.DjangoModelFactory): model = models.Application name = factory.Faker("company") - active = True + is_active = True client_id = factory.LazyFunction(utils.generate_client_id) client_secret = factory.LazyFunction(utils.generate_client_secret) scopes = [] diff --git a/src/backend/core/migrations/0018_rename_active_application_is_active.py b/src/backend/core/migrations/0018_rename_active_application_is_active.py new file mode 100644 index 00000000..9e98821d --- /dev/null +++ b/src/backend/core/migrations/0018_rename_active_application_is_active.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.12 on 2026-03-11 14:39 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0017_file'), + ] + + operations = [ + migrations.RenameField( + model_name='application', + old_name='active', + new_name='is_active', + ), + ] diff --git a/src/backend/core/models.py b/src/backend/core/models.py index 4e23d76c..9e921ae5 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -759,7 +759,7 @@ class Application(BaseModel): verbose_name=_("Application name"), help_text=_("Descriptive name for this application."), ) - active = models.BooleanField(default=True) + is_active = models.BooleanField(default=True) client_id = models.CharField( max_length=100, unique=True, default=utils.generate_client_id ) diff --git a/src/backend/core/tests/test_external_api_rooms.py b/src/backend/core/tests/test_external_api_rooms.py index c4d7322a..424bce0c 100644 --- a/src/backend/core/tests/test_external_api_rooms.py +++ b/src/backend/core/tests/test_external_api_rooms.py @@ -904,7 +904,7 @@ def test_api_rooms_token_unknown_application(settings): def test_api_rooms_token_inactive_application(settings): """Token for inactive application should be rejected.""" - application = ApplicationFactory(active=False) + application = ApplicationFactory(is_active=False) now = datetime.now(timezone.utc) payload = { diff --git a/src/backend/core/tests/test_external_api_token.py b/src/backend/core/tests/test_external_api_token.py index cc6a2278..fb6f147e 100644 --- a/src/backend/core/tests/test_external_api_token.py +++ b/src/backend/core/tests/test_external_api_token.py @@ -23,7 +23,7 @@ def test_api_applications_generate_token_success(settings): """Valid credentials should return a JWT token.""" UserFactory(email="User.Family@example.com") application = ApplicationFactory( - active=True, + is_active=True, scopes=[ApplicationScope.ROOMS_LIST, ApplicationScope.ROOMS_CREATE], ) @@ -79,7 +79,7 @@ def test_api_applications_generate_token_invalid_client_id(): def test_api_applications_generate_token_invalid_client_secret(): """Invalid client_secret should return 401.""" user = UserFactory(email="user@example.com") - application = ApplicationFactory(active=True) + application = ApplicationFactory(is_active=True) client = APIClient() response = client.post( @@ -100,7 +100,7 @@ def test_api_applications_generate_token_invalid_client_secret(): def test_api_applications_generate_token_inactive_application(): """Inactive application should return 401.""" user = UserFactory(email="user@example.com") - application = ApplicationFactory(active=False) + application = ApplicationFactory(is_active=False) plain_secret = "test-secret-123" application.client_secret = plain_secret @@ -124,7 +124,7 @@ def test_api_applications_generate_token_inactive_application(): def test_api_applications_generate_token_invalid_email_format(): """Invalid email format should return 400.""" - application = ApplicationFactory(active=True) + application = ApplicationFactory(is_active=True) plain_secret = "test-secret-123" application.client_secret = plain_secret @@ -149,7 +149,7 @@ def test_api_applications_generate_token_invalid_email_format(): def test_api_applications_generate_token_domain_not_authorized(): """Application without domain authorization should return 403.""" user = UserFactory(email="user@denied.com") - application = ApplicationFactory(active=True) + application = ApplicationFactory(is_active=True) ApplicationDomainFactory(application=application, domain="allowed.com") plain_secret = "test-secret-123" @@ -176,7 +176,7 @@ def test_api_applications_generate_token_domain_authorized(): """Application with domain authorization should succeed.""" user = UserFactory(email="user@allowed.com") application = ApplicationFactory( - active=True, + is_active=True, scopes=[ApplicationScope.ROOMS_LIST], ) ApplicationDomainFactory(application=application, domain="allowed.com") @@ -203,7 +203,7 @@ def test_api_applications_generate_token_domain_authorized(): def test_api_applications_generate_token_user_not_found(): """Non-existent user should return 404.""" - application = ApplicationFactory(active=True) + application = ApplicationFactory(is_active=True) plain_secret = "test-secret-123" application.client_secret = plain_secret @@ -231,7 +231,7 @@ def test_api_applications_token_payload_structure(settings): user = UserFactory(email="user@example.com") application = ApplicationFactory( - active=True, + is_active=True, scopes=[ApplicationScope.ROOMS_LIST, ApplicationScope.ROOMS_CREATE], ) @@ -284,7 +284,7 @@ def test_api_applications_token_new_user(settings): assert len(User.objects.all()) == 0 application = ApplicationFactory( - active=True, + is_active=True, scopes=[ApplicationScope.ROOMS_LIST, ApplicationScope.ROOMS_CREATE], ) @@ -342,7 +342,7 @@ def test_api_applications_token_existing_user(settings): assert len(User.objects.all()) == 1 application = ApplicationFactory( - active=True, + is_active=True, scopes=[ApplicationScope.ROOMS_LIST, ApplicationScope.ROOMS_CREATE], ) diff --git a/src/backend/core/tests/test_models_applications.py b/src/backend/core/tests/test_models_applications.py index 035738c0..dd6cf9ed 100644 --- a/src/backend/core/tests/test_models_applications.py +++ b/src/backend/core/tests/test_models_applications.py @@ -41,7 +41,7 @@ def test_models_application_name_maxlength(): def test_models_application_active_default(): """An application should be active by default.""" application = Application.objects.create(name="Test App") - assert application.active is True + assert application.is_active is True def test_models_application_scopes_default():