mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Add validation for agreement accepted on behalf of
If the user has selected that they are accepting the agreement on behalf of someone else then we need to make the they provide that person’s details. If they’ve selected that they are accepting the agreement themselves then we have to ignore what they might have put in the ‘on behalf of boxes’ (for example if they filled them out but then changed their mind).
This commit is contained in:
@@ -1466,6 +1466,23 @@ class GoLiveNotesForm(StripWhitespaceForm):
|
||||
|
||||
class AcceptAgreementForm(StripWhitespaceForm):
|
||||
|
||||
@classmethod
|
||||
def from_organisation(cls, org):
|
||||
|
||||
if org.agreement_signed_on_behalf_of_name and org.agreement_signed_on_behalf_of_email_address:
|
||||
who = 'someone-else'
|
||||
elif org.agreement_signed_version: # only set if user has submitted form previously
|
||||
who = 'me'
|
||||
else:
|
||||
who = None
|
||||
|
||||
return cls(
|
||||
version=org.agreement_signed_version,
|
||||
who=who,
|
||||
on_behalf_of_name=org.agreement_signed_on_behalf_of_name,
|
||||
on_behalf_of_email=org.agreement_signed_on_behalf_of_email_address,
|
||||
)
|
||||
|
||||
version = StringField(
|
||||
'Which version of the agreement are you accepting?'
|
||||
)
|
||||
@@ -1495,6 +1512,16 @@ class AcceptAgreementForm(StripWhitespaceForm):
|
||||
gov_user=False,
|
||||
)
|
||||
|
||||
def __validate_if_nominating(self, field):
|
||||
if self.who.data == 'someone-else':
|
||||
if not field.data:
|
||||
raise ValidationError('Can’t be empty')
|
||||
else:
|
||||
field.data = ''
|
||||
|
||||
validate_on_behalf_of_name = __validate_if_nominating
|
||||
validate_on_behalf_of_email = __validate_if_nominating
|
||||
|
||||
def validate_version(self, field):
|
||||
try:
|
||||
float(field.data)
|
||||
|
||||
@@ -33,20 +33,10 @@ def service_agreement(service_id):
|
||||
@login_required
|
||||
def service_accept_agreement(service_id):
|
||||
|
||||
org = current_service.organisation
|
||||
|
||||
if not org:
|
||||
if not current_service.organisation:
|
||||
abort(404)
|
||||
|
||||
form = AcceptAgreementForm(
|
||||
version=org.agreement_signed_version,
|
||||
who='someone-else' if (
|
||||
org.agreement_signed_on_behalf_of_name
|
||||
and org.agreement_signed_on_behalf_of_email_address
|
||||
) else 'me',
|
||||
on_behalf_of_name=org.agreement_signed_on_behalf_of_name,
|
||||
on_behalf_of_email=org.agreement_signed_on_behalf_of_email_address,
|
||||
)
|
||||
form = AcceptAgreementForm.from_organisation(current_service.organisation)
|
||||
|
||||
if form.validate_on_submit():
|
||||
current_service.organisation.update(
|
||||
|
||||
Reference in New Issue
Block a user