-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into za/2927-blocked-from-starting-requests
- Loading branch information
Showing
9 changed files
with
541 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,15 @@ | |
import logging | ||
from django import forms | ||
from django.core.validators import RegexValidator | ||
from django.core.validators import MaxLengthValidator | ||
|
||
from registrar.models import ( | ||
PortfolioInvitation, | ||
UserPortfolioPermission, | ||
DomainInformation, | ||
Portfolio, | ||
SeniorOfficial, | ||
User, | ||
) | ||
from registrar.models.utility.portfolio_helper import UserPortfolioPermissionChoices, UserPortfolioRoleChoices | ||
|
||
|
@@ -160,3 +162,112 @@ class Meta: | |
"roles", | ||
"additional_permissions", | ||
] | ||
|
||
|
||
class NewMemberForm(forms.ModelForm): | ||
member_access_level = forms.ChoiceField( | ||
label="Select permission", | ||
choices=[("admin", "Admin Access"), ("basic", "Basic Access")], | ||
widget=forms.RadioSelect(attrs={"class": "usa-radio__input usa-radio__input--tile"}), | ||
required=True, | ||
error_messages={ | ||
"required": "Member access level is required", | ||
}, | ||
) | ||
admin_org_domain_request_permissions = forms.ChoiceField( | ||
label="Select permission", | ||
choices=[("view_only", "View all requests"), ("view_and_create", "View all requests plus create requests")], | ||
widget=forms.RadioSelect, | ||
required=True, | ||
error_messages={ | ||
"required": "Admin domain request permission is required", | ||
}, | ||
) | ||
admin_org_members_permissions = forms.ChoiceField( | ||
label="Select permission", | ||
choices=[("view_only", "View all members"), ("view_and_create", "View all members plus manage members")], | ||
widget=forms.RadioSelect, | ||
required=True, | ||
error_messages={ | ||
"required": "Admin member permission is required", | ||
}, | ||
) | ||
basic_org_domain_request_permissions = forms.ChoiceField( | ||
label="Select permission", | ||
choices=[ | ||
("view_only", "View all requests"), | ||
("view_and_create", "View all requests plus create requests"), | ||
("no_access", "No access"), | ||
], | ||
widget=forms.RadioSelect, | ||
required=True, | ||
error_messages={ | ||
"required": "Basic member permission is required", | ||
}, | ||
) | ||
|
||
email = forms.EmailField( | ||
label="Enter the email of the member you'd like to invite", | ||
max_length=None, | ||
error_messages={ | ||
"invalid": ("Enter an email address in the required format, like [email protected]."), | ||
"required": ("Enter an email address in the required format, like [email protected]."), | ||
}, | ||
validators=[ | ||
MaxLengthValidator( | ||
320, | ||
message="Response must be less than 320 characters.", | ||
) | ||
], | ||
required=True, | ||
) | ||
|
||
class Meta: | ||
model = User | ||
fields = ["email"] | ||
|
||
def clean(self): | ||
cleaned_data = super().clean() | ||
|
||
# Lowercase the value of the 'email' field | ||
email_value = cleaned_data.get("email") | ||
if email_value: | ||
cleaned_data["email"] = email_value.lower() | ||
|
||
########################################## | ||
# TODO: future ticket | ||
# (invite new member) | ||
########################################## | ||
# Check for an existing user (if there isn't any, send an invite) | ||
# if email_value: | ||
# try: | ||
# existingUser = User.objects.get(email=email_value) | ||
# except User.DoesNotExist: | ||
# raise forms.ValidationError("User with this email does not exist.") | ||
|
||
member_access_level = cleaned_data.get("member_access_level") | ||
|
||
# Intercept the error messages so that we don't validate hidden inputs | ||
if not member_access_level: | ||
# If no member access level has been selected, delete error messages | ||
# for all hidden inputs (which is everything except the e-mail input | ||
# and member access selection) | ||
for field in self.fields: | ||
if field in self.errors and field != "email" and field != "member_access_level": | ||
del self.errors[field] | ||
return cleaned_data | ||
|
||
basic_dom_req_error = "basic_org_domain_request_permissions" | ||
admin_dom_req_error = "admin_org_domain_request_permissions" | ||
admin_member_error = "admin_org_members_permissions" | ||
|
||
if member_access_level == "admin" and basic_dom_req_error in self.errors: | ||
# remove the error messages pertaining to basic permission inputs | ||
del self.errors[basic_dom_req_error] | ||
elif member_access_level == "basic": | ||
# remove the error messages pertaining to admin permission inputs | ||
if admin_dom_req_error in self.errors: | ||
del self.errors[admin_dom_req_error] | ||
if admin_member_error in self.errors: | ||
del self.errors[admin_member_error] | ||
return cleaned_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.