diff --git a/swh/web/add_forge_now/migrations/0002_authorized_null_comment.py b/swh/web/add_forge_now/migrations/0002_authorized_null_comment.py
new file mode 100644
--- /dev/null
+++ b/swh/web/add_forge_now/migrations/0002_authorized_null_comment.py
@@ -0,0 +1,32 @@
+# Generated by Django 2.2.24 on 2022-03-21 15:42
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("add_forge_now", "0001_initial"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="request",
+ name="forge_contact_comment",
+ field=models.TextField(
+ help_text="Where did you find this contact information (url, ...)",
+ null=True,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="requesthistory",
+ name="actor_role",
+ field=models.TextField(
+ choices=[
+ ("MODERATOR", "moderator"),
+ ("SUBMITTER", "submitter"),
+ ("FORGE_ADMIN", "forge admin"),
+ ]
+ ),
+ ),
+ ]
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
@@ -95,5 +95,5 @@
forge_contact_email = models.EmailField()
forge_contact_name = models.TextField()
forge_contact_comment = models.TextField(
- help_text="Where did you find this contact information (url, ...)",
+ null=True, help_text="Where did you find this contact information (url, ...)",
)
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
@@ -5,9 +5,12 @@
from datetime import datetime, timezone
+import pytest
+
APP_NAME = "add_forge_now"
MIGRATION_0001 = "0001_initial"
+MIGRATION_0002 = "0002_authorized_null_comment"
def now() -> datetime:
@@ -60,3 +63,35 @@
)
req_history2.save()
assert req_history2.date > req_history.date
+
+
+def test_add_forge_now_allow_no_comment(migrator):
+ """Basic migration test to check new model authorized empty comment"""
+
+ from django.db.utils import IntegrityError
+
+ state = migrator.apply_tested_migration((APP_NAME, MIGRATION_0001))
+
+ def make_request_with_empty_comment(requestModel):
+ return requestModel(
+ status="PENDING",
+ submitter_name="dudess",
+ submitter_email="dudess@orga.org",
+ forge_type="cgit",
+ forge_url="https://example.org/forge",
+ forge_contact_email="forge@//example.org",
+ forge_contact_name="forge",
+ forge_contact_comment=None,
+ )
+
+ requestModel = state.apps.get_model(APP_NAME, "Request")
+
+ req = make_request_with_empty_comment(requestModel)
+ with pytest.raises(IntegrityError, match="violates not-null constraint"):
+ req.save()
+
+ state = migrator.apply_tested_migration((APP_NAME, MIGRATION_0002))
+ requestModel2 = state.apps.get_model(APP_NAME, "Request")
+
+ req2 = make_request_with_empty_comment(requestModel2)
+ req2.save()
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
@@ -35,6 +35,8 @@
class AddForgeNowRequestForm(ModelForm):
+ forge_contact_comment = CharField(required=False,)
+
class Meta:
model = AddForgeRequest
fields = (
diff --git a/swh/web/templates/add_forge_now/create-request.html b/swh/web/templates/add_forge_now/create-request.html
--- a/swh/web/templates/add_forge_now/create-request.html
+++ b/swh/web/templates/add_forge_now/create-request.html
@@ -116,7 +116,7 @@
- If you wish to leave a comment regarding your request.
+ If you wish to leave a comment to the moderator regarding your request.
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
@@ -34,7 +34,7 @@
assert '"forge_type"' in resp.data["reason"]
-ADD_FORGE_DATA = {
+ADD_FORGE_DATA_FORGE1 = {
"forge_type": "gitlab",
"forge_url": "https://gitlab.example.org",
"forge_contact_email": "admin@gitlab.example.org",
@@ -42,7 +42,7 @@
"forge_contact_comment": "user marked as owner in forge members",
}
-ADD_OTHER_FORGE_DATA = {
+ADD_FORGE_DATA_FORGE2 = {
"forge_type": "gitea",
"forge_url": "https://gitea.example.org",
"forge_contact_email": "admin@gitea.example.org",
@@ -50,23 +50,34 @@
"forge_contact_comment": "user marked as owner in forge members",
}
+ADD_FORGE_DATA_FORGE3 = {
+ "forge_type": "heptapod",
+ "forge_url": "https://heptapod.host/",
+ "forge_contact_email": "admin@example.org",
+ "forge_contact_name": "heptapod admin",
+ "forge_contact_comment": "", # authorized empty or null comment
+}
+
@pytest.mark.django_db(transaction=True, reset_sequences=True)
-def test_add_forge_request_create_success(api_client, regular_user):
+@pytest.mark.parametrize(
+ "add_forge_data", [ADD_FORGE_DATA_FORGE1, ADD_FORGE_DATA_FORGE3]
+)
+def test_add_forge_request_create_success(api_client, regular_user, add_forge_data):
api_client.force_login(regular_user)
url = reverse("api-1-add-forge-request-create")
date_before = datetime.datetime.now(tz=datetime.timezone.utc)
resp = check_api_post_response(
- api_client, url, data=ADD_FORGE_DATA, status_code=201,
+ api_client, url, data=add_forge_data, status_code=201,
)
date_after = datetime.datetime.now(tz=datetime.timezone.utc)
assert resp.data == {
- **ADD_FORGE_DATA,
- "id": 1,
+ **add_forge_data,
+ "id": resp.data["id"],
"status": "PENDING",
"submission_date": resp.data["submission_date"],
"submitter_name": regular_user.username,
@@ -75,9 +86,9 @@
assert date_before < iso8601.parse_date(resp.data["submission_date"]) < date_after
- request = Request.objects.all()[0]
+ request = Request.objects.all().last()
- assert request.forge_url == ADD_FORGE_DATA["forge_url"]
+ assert request.forge_url == add_forge_data["forge_url"]
assert request.submitter_name == regular_user.username
@@ -92,14 +103,14 @@
client,
url,
request_content_type="application/x-www-form-urlencoded",
- data=urlencode(ADD_FORGE_DATA),
+ data=urlencode(ADD_FORGE_DATA_FORGE1),
status_code=201,
)
date_after = datetime.datetime.now(tz=datetime.timezone.utc)
assert resp.data == {
- **ADD_FORGE_DATA,
+ **ADD_FORGE_DATA_FORGE1,
"id": 1,
"status": "PENDING",
"submission_date": resp.data["submission_date"],
@@ -111,7 +122,7 @@
request = Request.objects.all()[0]
- assert request.forge_url == ADD_FORGE_DATA["forge_url"]
+ assert request.forge_url == ADD_FORGE_DATA_FORGE1["forge_url"]
assert request.submitter_name == regular_user.username
@@ -120,10 +131,10 @@
api_client.force_login(regular_user)
url = reverse("api-1-add-forge-request-create")
check_api_post_response(
- api_client, url, data=ADD_FORGE_DATA, status_code=201,
+ api_client, url, data=ADD_FORGE_DATA_FORGE1, status_code=201,
)
check_api_post_response(
- api_client, url, data=ADD_FORGE_DATA, status_code=409,
+ api_client, url, data=ADD_FORGE_DATA_FORGE1, status_code=409,
)
requests = Request.objects.all()
@@ -150,7 +161,7 @@
check_api_post_response(api_client, url, status_code=400)
-def create_add_forge_request(api_client, regular_user, data=ADD_FORGE_DATA):
+def create_add_forge_request(api_client, regular_user, data=ADD_FORGE_DATA_FORGE1):
api_client.force_login(regular_user)
url = reverse("api-1-add-forge-request-create")
return check_api_post_response(api_client, url, data=data, status_code=201,)
@@ -272,8 +283,8 @@
resp = check_api_get_responses(api_client, url, status_code=200)
add_forge_request = {
- "forge_url": ADD_FORGE_DATA["forge_url"],
- "forge_type": ADD_FORGE_DATA["forge_type"],
+ "forge_url": ADD_FORGE_DATA_FORGE1["forge_url"],
+ "forge_type": ADD_FORGE_DATA_FORGE1["forge_type"],
"status": "PENDING",
"submission_date": resp.data[0]["submission_date"],
"id": 1,
@@ -281,13 +292,13 @@
assert resp.data == [add_forge_request]
- create_add_forge_request(api_client, regular_user, data=ADD_OTHER_FORGE_DATA)
+ create_add_forge_request(api_client, regular_user, data=ADD_FORGE_DATA_FORGE2)
resp = check_api_get_responses(api_client, url, status_code=200)
other_forge_request = {
- "forge_url": ADD_OTHER_FORGE_DATA["forge_url"],
- "forge_type": ADD_OTHER_FORGE_DATA["forge_type"],
+ "forge_url": ADD_FORGE_DATA_FORGE2["forge_url"],
+ "forge_type": ADD_FORGE_DATA_FORGE2["forge_type"],
"status": "PENDING",
"submission_date": resp.data[0]["submission_date"],
"id": 2,
@@ -303,13 +314,13 @@
url = reverse("api-1-add-forge-request-list")
create_add_forge_request(api_client, regular_user)
- create_add_forge_request(api_client, regular_user, data=ADD_OTHER_FORGE_DATA)
+ create_add_forge_request(api_client, regular_user, data=ADD_FORGE_DATA_FORGE2)
api_client.force_login(add_forge_moderator)
resp = check_api_get_responses(api_client, url, status_code=200)
add_forge_request = {
- **ADD_FORGE_DATA,
+ **ADD_FORGE_DATA_FORGE1,
"status": "PENDING",
"submission_date": resp.data[1]["submission_date"],
"submitter_name": regular_user.username,
@@ -318,7 +329,7 @@
}
other_forge_request = {
- **ADD_OTHER_FORGE_DATA,
+ **ADD_FORGE_DATA_FORGE2,
"status": "PENDING",
"submission_date": resp.data[0]["submission_date"],
"submitter_name": regular_user.username,
@@ -334,7 +345,7 @@
api_client, regular_user, api_request_factory
):
create_add_forge_request(api_client, regular_user)
- create_add_forge_request(api_client, regular_user, data=ADD_OTHER_FORGE_DATA)
+ create_add_forge_request(api_client, regular_user, data=ADD_FORGE_DATA_FORGE2)
url = reverse("api-1-add-forge-request-list", query_params={"per_page": 1})
@@ -370,7 +381,7 @@
api_client, regular_user, regular_user2
):
create_add_forge_request(api_client, regular_user)
- create_add_forge_request(api_client, regular_user2, data=ADD_OTHER_FORGE_DATA)
+ create_add_forge_request(api_client, regular_user2, data=ADD_FORGE_DATA_FORGE2)
api_client.force_login(regular_user)
url = reverse(
@@ -404,8 +415,8 @@
assert resp.data == {
"request": {
- "forge_url": ADD_FORGE_DATA["forge_url"],
- "forge_type": ADD_FORGE_DATA["forge_type"],
+ "forge_url": ADD_FORGE_DATA_FORGE1["forge_url"],
+ "forge_type": ADD_FORGE_DATA_FORGE1["forge_type"],
"id": 1,
"status": "WAITING_FOR_FEEDBACK",
"submission_date": submission_date,
@@ -449,7 +460,7 @@
assert resp.data == {
"request": {
- **ADD_FORGE_DATA,
+ **ADD_FORGE_DATA_FORGE1,
"id": 1,
"status": "WAITING_FOR_FEEDBACK",
"submission_date": submission_date,