diff --git a/swh/web/add_forge_now/migrations/0003_request_submitter_consent.py b/swh/web/add_forge_now/migrations/0003_request_submitter_consent.py new file mode 100644 --- /dev/null +++ b/swh/web/add_forge_now/migrations/0003_request_submitter_consent.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.24 on 2022-03-21 16:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("add_forge_now", "0002_authorized_null_comment"), + ] + + operations = [ + migrations.AddField( + model_name="request", + name="submitter_consent", + field=models.BooleanField(default=False), + ), + ] diff --git a/swh/web/add_forge_now/models.py b/swh/web/add_forge_now/models.py --- a/swh/web/add_forge_now/models.py +++ b/swh/web/add_forge_now/models.py @@ -89,6 +89,7 @@ submission_date = models.DateTimeField(auto_now_add=True) submitter_name = models.TextField() submitter_email = models.TextField() + submitter_consent = models.BooleanField(default=False) # FIXME: shall we do create a user model inside the webapp instead? forge_type = models.TextField() forge_url = models.TextField() diff --git a/swh/web/add_forge_now/tests/test_migration.py b/swh/web/add_forge_now/tests/test_migration.py --- a/swh/web/add_forge_now/tests/test_migration.py +++ b/swh/web/add_forge_now/tests/test_migration.py @@ -11,6 +11,7 @@ MIGRATION_0001 = "0001_initial" MIGRATION_0002 = "0002_authorized_null_comment" +MIGRATION_0003 = "0003_request_submitter_consent" def now() -> datetime: @@ -95,3 +96,16 @@ req2 = make_request_with_empty_comment(requestModel2) req2.save() + + +def test_add_forge_now_store_submitter_consent(migrator): + """Basic migration test to check new model authorized empty comment""" + + state = migrator.apply_tested_migration((APP_NAME, MIGRATION_0002)) + requestModel = state.apps.get_model(APP_NAME, "Request") + assert not hasattr(requestModel, "submitter_consent") + + state = migrator.apply_tested_migration((APP_NAME, MIGRATION_0003)) + requestModel2 = state.apps.get_model(APP_NAME, "Request") + + assert hasattr(requestModel2, "submitter_consent") diff --git a/swh/web/api/views/add_forge_now.py b/swh/web/api/views/add_forge_now.py --- a/swh/web/api/views/add_forge_now.py +++ b/swh/web/api/views/add_forge_now.py @@ -45,6 +45,7 @@ "forge_contact_email", "forge_contact_name", "forge_contact_comment", + "submitter_consent", ) diff --git a/swh/web/tests/api/views/test_add_forge_now.py b/swh/web/tests/api/views/test_add_forge_now.py --- a/swh/web/tests/api/views/test_add_forge_now.py +++ b/swh/web/tests/api/views/test_add_forge_now.py @@ -40,6 +40,7 @@ "forge_contact_email": "admin@gitlab.example.org", "forge_contact_name": "gitlab.example.org admin", "forge_contact_comment": "user marked as owner in forge members", + "submitter_consent": True, } ADD_FORGE_DATA_FORGE2 = { @@ -48,6 +49,7 @@ "forge_contact_email": "admin@gitea.example.org", "forge_contact_name": "gitea.example.org admin", "forge_contact_comment": "user marked as owner in forge members", + "submitter_consent": True, } ADD_FORGE_DATA_FORGE3 = { @@ -56,6 +58,7 @@ "forge_contact_email": "admin@example.org", "forge_contact_name": "heptapod admin", "forge_contact_comment": "", # authorized empty or null comment + "submitter_consent": False, }