1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2024-12-05 02:06:52 +00:00

Administrators can update the team of the email validation status of a team.

This commit is contained in:
Yohann D'ANELLO 2020-12-11 12:31:00 +01:00
parent 833f9147ce
commit 10115a0419
3 changed files with 23 additions and 3 deletions

View File

@ -64,7 +64,7 @@ class StudentRegistrationForm(forms.ModelForm):
""" """
class Meta: class Meta:
model = StudentRegistration model = StudentRegistration
fields = ('student_class', 'school', 'give_contact_to_animath',) fields = ('team', 'student_class', 'school', 'give_contact_to_animath', 'email_confirmed',)
class PhotoAuthorizationForm(forms.ModelForm): class PhotoAuthorizationForm(forms.ModelForm):
@ -92,7 +92,7 @@ class CoachRegistrationForm(forms.ModelForm):
""" """
class Meta: class Meta:
model = CoachRegistration model = CoachRegistration
fields = ('professional_activity', 'give_contact_to_animath',) fields = ('team', 'professional_activity', 'give_contact_to_animath', 'email_confirmed',)
class AdminRegistrationForm(forms.ModelForm): class AdminRegistrationForm(forms.ModelForm):
@ -101,4 +101,4 @@ class AdminRegistrationForm(forms.ModelForm):
""" """
class Meta: class Meta:
model = AdminRegistration model = AdminRegistration
fields = ('role', 'give_contact_to_animath',) fields = ('role', 'give_contact_to_animath', 'email_confirmed',)

View File

@ -226,6 +226,8 @@ class TestRegistration(TestCase):
last_name="Name", last_name="Name",
email="new_" + user.email, email="new_" + user.email,
give_contact_to_animath=True, give_contact_to_animath=True,
email_confirmed=True,
team_id="",
)) ))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@ -234,6 +236,8 @@ class TestRegistration(TestCase):
last_name="Name", last_name="Name",
email="new_" + user.email, email="new_" + user.email,
give_contact_to_animath=True, give_contact_to_animath=True,
email_confirmed=True,
team_id="",
) )
response = self.client.post(reverse("registration:update_user", args=(user.pk,)), data=data) response = self.client.post(reverse("registration:update_user", args=(user.pk,)), data=data)
self.assertRedirects(response, reverse("registration:user_detail", args=(user.pk,)), 302, 200) self.assertRedirects(response, reverse("registration:user_detail", args=(user.pk,)), 302, 200)

View File

@ -43,6 +43,11 @@ class SignupView(CreateView):
context["student_registration_form"] = StudentRegistrationForm(self.request.POST or None) context["student_registration_form"] = StudentRegistrationForm(self.request.POST or None)
context["coach_registration_form"] = CoachRegistrationForm(self.request.POST or None) context["coach_registration_form"] = CoachRegistrationForm(self.request.POST or None)
del context["student_registration_form"].fields["team"]
del context["student_registration_form"].fields["email_confirmed"]
del context["coach_registration_form"].fields["team"]
del context["coach_registration_form"].fields["email_confirmed"]
return context return context
@transaction.atomic @transaction.atomic
@ -52,6 +57,8 @@ class SignupView(CreateView):
registration_form = StudentRegistrationForm(self.request.POST) registration_form = StudentRegistrationForm(self.request.POST)
else: else:
registration_form = CoachRegistrationForm(self.request.POST) registration_form = CoachRegistrationForm(self.request.POST)
del registration_form.fields["team"]
del registration_form.fields["email_confirmed"]
if not registration_form.is_valid(): if not registration_form.is_valid():
return self.form_invalid(form) return self.form_invalid(form)
@ -191,6 +198,10 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
context["title"] = _("Update user {user}").format(user=str(self.object.registration)) context["title"] = _("Update user {user}").format(user=str(self.object.registration))
context["registration_form"] = user.registration.form_class(data=self.request.POST or None, context["registration_form"] = user.registration.form_class(data=self.request.POST or None,
instance=self.object.registration) instance=self.object.registration)
if not user.registration.is_admin:
if "team" in context["registration_form"].fields:
del context["registration_form"].fields["team"]
del context["registration_form"].fields["email_confirmed"]
return context return context
@transaction.atomic @transaction.atomic
@ -198,6 +209,11 @@ class UserUpdateView(LoginRequiredMixin, UpdateView):
user = form.instance user = form.instance
registration_form = user.registration.form_class(data=self.request.POST or None, registration_form = user.registration.form_class(data=self.request.POST or None,
instance=self.object.registration) instance=self.object.registration)
if not user.registration.is_admin:
if "team" in registration_form.fields:
del registration_form.fields["team"]
del registration_form.fields["email_confirmed"]
if not registration_form.is_valid(): if not registration_form.is_valid():
return self.form_invalid(form) return self.form_invalid(form)