Skip to content

Commit

Permalink
[Utilisateurs] nouveau type "Particulier" (#1002)
Browse files Browse the repository at this point in the history
* New User.kind choice: INDIVIDUAL

* Update signup form

* Update tests

* Fix signup
  • Loading branch information
raphodn authored Dec 6, 2023
1 parent f766596 commit 06bb27d
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 4 deletions.
27 changes: 27 additions & 0 deletions lemarche/stats/migrations/0008_alter_tracker_user_kind.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.2 on 2023-12-04 14:38

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("stats", "0007_tracker_siae_kind_and_contact_email"),
]

operations = [
migrations.AlterField(
model_name="tracker",
name="user_kind",
field=models.CharField(
blank=True,
choices=[
("SIAE", "Structure"),
("BUYER", "Acheteur"),
("PARTNER", "Partenaire"),
("INDIVIDUAL", "Particulier"),
("ADMIN", "Administrateur"),
],
max_length=20,
),
),
]
24 changes: 20 additions & 4 deletions lemarche/templates/auth/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,24 @@ <h1 class="s-title-01__title h1">Inscription</h1>

<div class="c-form">
{% bootstrap_form_errors form type="all" %}

<!-- User kind -->
<fieldset>
<legend>Vous êtes <strong class="fs-base">*</strong></legend>
{% bootstrap_field form.kind %}
</fieldset>
<hr>

<!-- User contact -->
<fieldset>
<legend>Contact</legend>
{% bootstrap_field form.first_name %}
{% bootstrap_field form.last_name %}
{% bootstrap_field form.phone form_group_class="phone-form-group form-group" %}

</fieldset>
<hr>

<!-- User company -->
<fieldset id="infoStructuresFieldset" class="d-none">
<legend>Informations structure</legend>
{% bootstrap_field form.buyer_kind_detail form_group_class="buyer-kind-detail-form-group form-group form-group-required d-none" %}
Expand All @@ -66,12 +71,17 @@ <h1 class="s-title-01__title h1">Inscription</h1>
</div>
<hr>
</fieldset>

<!-- User password -->
<fieldset>
<legend>Création du mot de passe</legend>
{% bootstrap_field form.email %}
{% bootstrap_field form.password1 %}
{% bootstrap_field form.password2 %}
</fieldset>
<hr>

<!-- Legal mentions, survey & co -->
<fieldset id="statsSignupBuyer" class="d-none">
<hr>
<div class="form-group">
Expand All @@ -86,6 +96,8 @@ <h1 class="s-title-01__title h1">Inscription</h1>
{% bootstrap_field form.accept_share_contact_to_external_partners form_group_class="form-group accept-survey-form-group d-none" %}
</div>
<hr>

<!-- Submit -->
<div class="row">
<div class="col-12">
<div class="form-row justify-content-end align-items-center">
Expand Down Expand Up @@ -117,6 +129,8 @@ <h1 class="s-title-01__title h1">Inscription</h1>
* - 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');
Expand Down Expand Up @@ -164,10 +178,12 @@ <h1 class="s-title-01__title h1">Inscription</h1>
} 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');
}
}));
});
Expand Down
3 changes: 3 additions & 0 deletions lemarche/users/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
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

KIND_CHOICES = (
(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),)

Expand Down
28 changes: 28 additions & 0 deletions lemarche/users/migrations/0032_alter_user_kind.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
1 change: 1 addition & 0 deletions lemarche/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lemarche/www/auth/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 28 additions & 0 deletions lemarche/www/auth/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@
# "id_accept_survey" # not required
}

INDIVIDUAL = {
"id_kind": 3,
"first_name": "Prenom",
"last_name": "Nom",
# "phone": "012345678", # not required
"email": "[email protected]",
"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):
"""
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 06bb27d

Please sign in to comment.