@@ -117,6 +129,8 @@
Inscription
* - add buyer_kind_detail field (and make it required)
* - add position field (and make it required)
* - add survey checkbox for newsletter
+ * - if the user is an INDIVIDUAL:
+ * - hide company section
*/
document.addEventListener('DOMContentLoaded', function() {
let phoneInput = document.getElementById('id_phone');
@@ -164,10 +178,12 @@ Inscription
} else {
toggleInputElement(false, element=partnerKindInput, required=false);
}
- if(radio.value){
- infoStructuresFieldset.classList.remove('d-none');
- } else { //empty
+
+ if (radio.value === 'INDIVIDUAL') {
+ toggleInputElement(false, element=companyNameInput, required=false);
infoStructuresFieldset.classList.add('d-none');
+ } else {
+ infoStructuresFieldset.classList.remove('d-none');
}
}));
});
diff --git a/lemarche/users/constants.py b/lemarche/users/constants.py
index 3d9dc091c..385a46567 100644
--- a/lemarche/users/constants.py
+++ b/lemarche/users/constants.py
@@ -4,6 +4,8 @@
KIND_BUYER_DISPLAY = "Acheteur"
KIND_PARTNER = "PARTNER"
KIND_PARTNER_DISPLAY = "Partenaire"
+KIND_INDIVIDUAL = "INDIVIDUAL"
+KIND_INDIVIDUAL_DISPLAY = "Particulier"
KIND_ADMIN = "ADMIN"
KIND_ADMIN_DISPLAY = "Administrateur" # Administrateur.trice
@@ -11,6 +13,7 @@
(KIND_SIAE, KIND_SIAE_DISPLAY),
(KIND_BUYER, KIND_BUYER_DISPLAY),
(KIND_PARTNER, KIND_PARTNER_DISPLAY),
+ (KIND_INDIVIDUAL, KIND_INDIVIDUAL_DISPLAY),
)
KIND_CHOICES_WITH_ADMIN = KIND_CHOICES + ((KIND_ADMIN, KIND_ADMIN_DISPLAY),)
diff --git a/lemarche/users/migrations/0032_alter_user_kind.py b/lemarche/users/migrations/0032_alter_user_kind.py
new file mode 100644
index 000000000..cc035f5ed
--- /dev/null
+++ b/lemarche/users/migrations/0032_alter_user_kind.py
@@ -0,0 +1,28 @@
+# Generated by Django 4.2.2 on 2023-12-04 14:38
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("users", "0031_user_rename_buyer_kind_detail_display"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="user",
+ name="kind",
+ field=models.CharField(
+ blank=True,
+ choices=[
+ ("SIAE", "Structure"),
+ ("BUYER", "Acheteur"),
+ ("PARTNER", "Partenaire"),
+ ("INDIVIDUAL", "Particulier"),
+ ("ADMIN", "Administrateur"),
+ ],
+ max_length=20,
+ verbose_name="Type",
+ ),
+ ),
+ ]
diff --git a/lemarche/users/models.py b/lemarche/users/models.py
index 21802bb96..89b95f0ef 100644
--- a/lemarche/users/models.py
+++ b/lemarche/users/models.py
@@ -137,6 +137,7 @@ class User(AbstractUser):
KIND_SIAE = user_constants.KIND_SIAE
KIND_BUYER = user_constants.KIND_BUYER
KIND_PARTNER = user_constants.KIND_PARTNER
+ KIND_INDIVIDUAL = user_constants.KIND_INDIVIDUAL
KIND_ADMIN = user_constants.KIND_ADMIN
username = None
diff --git a/lemarche/www/auth/forms.py b/lemarche/www/auth/forms.py
index a43a83af1..1c82d7bbc 100644
--- a/lemarche/www/auth/forms.py
+++ b/lemarche/www/auth/forms.py
@@ -14,6 +14,7 @@ class SignupForm(UserCreationForm):
(User.KIND_SIAE, "Une entreprise sociale inclusive (SIAE ou structure du handicap, GEIQ)"),
(User.KIND_BUYER, "Un acheteur"),
(User.KIND_PARTNER, "Un partenaire (réseaux, facilitateurs)"),
+ (User.KIND_INDIVIDUAL, "Un particulier"),
)
FORM_PARTNER_KIND_CHOICES = EMPTY_CHOICE + user_constants.PARTNER_KIND_CHOICES
diff --git a/lemarche/www/auth/tests.py b/lemarche/www/auth/tests.py
index d4d8d52bd..589498b15 100644
--- a/lemarche/www/auth/tests.py
+++ b/lemarche/www/auth/tests.py
@@ -68,6 +68,18 @@
# "id_accept_survey" # not required
}
+INDIVIDUAL = {
+ "id_kind": 3,
+ "first_name": "Prenom",
+ "last_name": "Nom",
+ # "phone": "012345678", # not required
+ "email": "individual@example.com",
+ "password1": "Erls92#32",
+ "password2": "Erls92#32",
+ # "id_accept_rgpd" # required
+ # "id_accept_survey" # not required
+}
+
def scroll_to_and_click_element(driver, element, click=True, sleep_time=1):
"""
@@ -231,6 +243,22 @@ def test_partner_submits_signup_form_error(self):
# should not submit form (company_name field is required)
self.assertEqual(self.driver.current_url, f"{self.live_server_url}{reverse('auth:signup')}")
+ # TODO: problem with this test
+ # def test_individual_submits_signup_form_success(self):
+ # self._complete_form(user_profile=INDIVIDUAL, with_submit=False)
+
+ # # should redirect INDIVIDUAL to home
+ # self._assert_signup_success(redirect_url=reverse("wagtail_serve", args=("",)))
+
+ def test_individual_submits_signup_form_error(self):
+ user_profile = INDIVIDUAL.copy()
+ del user_profile["last_name"]
+
+ self._complete_form(user_profile=user_profile, with_submit=True)
+
+ # should not submit form (last_name field is required)
+ self.assertEqual(self.driver.current_url, f"{self.live_server_url}{reverse('auth:signup')}")
+
def test_user_submits_signup_form_with_next_param_success_and_redirect(self):
next_url = f"{reverse('siae:search_results')}?kind=ESAT"
self._complete_form(