mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-16 22:44:11 +02:00
added placeholder to role selection, and handled validation error when user not selected
This commit is contained in:
parent
aa7e9d83a4
commit
c7aa2f3a38
3 changed files with 17 additions and 12 deletions
|
@ -229,7 +229,7 @@ class PortfolioPermissionsForm(forms.ModelForm):
|
||||||
|
|
||||||
# Dropdown for selecting the user role (e.g., Admin or Basic)
|
# Dropdown for selecting the user role (e.g., Admin or Basic)
|
||||||
role = forms.ChoiceField(
|
role = forms.ChoiceField(
|
||||||
choices=UserPortfolioRoleChoices.choices,
|
choices=[("", "---------")] + UserPortfolioRoleChoices.choices,
|
||||||
required=True,
|
required=True,
|
||||||
widget=forms.Select(attrs={"class": "admin-dropdown"}),
|
widget=forms.Select(attrs={"class": "admin-dropdown"}),
|
||||||
label="Member access",
|
label="Member access",
|
||||||
|
|
|
@ -15,26 +15,26 @@ function handlePortfolioPermissionFields(){
|
||||||
* Updates the visibility of portfolio permissions fields based on the selected role.
|
* Updates the visibility of portfolio permissions fields based on the selected role.
|
||||||
*
|
*
|
||||||
* This function checks the value of the role dropdown (`roleDropdown`):
|
* This function checks the value of the role dropdown (`roleDropdown`):
|
||||||
* - If the selected role is "organization_admin":
|
* - If the selected role is "organization_member":
|
||||||
* - Hides the domain permissions field (`domainPermissionsField`).
|
* - Shows the domain permissions field (`domainPermissionsField`).
|
||||||
* - Hides the domain request permissions field (`domainRequestPermissionsField`).
|
* - Shows the domain request permissions field (`domainRequestPermissionsField`).
|
||||||
* - Hides the member permissions field (`memberPermissionsField`).
|
* - Shows the member permissions field (`memberPermissionsField`).
|
||||||
* - Otherwise:
|
* - Otherwise:
|
||||||
* - Shows all the above fields.
|
* - Hides all the above fields.
|
||||||
*
|
*
|
||||||
* The function ensures that the appropriate fields are dynamically displayed
|
* The function ensures that the appropriate fields are dynamically displayed
|
||||||
* or hidden depending on the role selection in the form.
|
* or hidden depending on the role selection in the form.
|
||||||
*/
|
*/
|
||||||
function updatePortfolioPermissionsFormVisibility() {
|
function updatePortfolioPermissionsFormVisibility() {
|
||||||
if (roleDropdown && domainPermissionsField && domainRequestPermissionsField && memberPermissionsField) {
|
if (roleDropdown && domainPermissionsField && domainRequestPermissionsField && memberPermissionsField) {
|
||||||
if (roleDropdown.value === "organization_admin") {
|
if (roleDropdown.value === "organization_member") {
|
||||||
hideElement(domainPermissionsField);
|
|
||||||
hideElement(domainRequestPermissionsField);
|
|
||||||
hideElement(memberPermissionsField);
|
|
||||||
} else {
|
|
||||||
showElement(domainPermissionsField);
|
showElement(domainPermissionsField);
|
||||||
showElement(domainRequestPermissionsField);
|
showElement(domainRequestPermissionsField);
|
||||||
showElement(memberPermissionsField);
|
showElement(memberPermissionsField);
|
||||||
|
} else {
|
||||||
|
hideElement(domainPermissionsField);
|
||||||
|
hideElement(domainRequestPermissionsField);
|
||||||
|
hideElement(memberPermissionsField);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,7 +275,12 @@ class UserPortfolioPermission(TimeStampedModel):
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Extends clean method to perform additional validation, which can raise errors in django admin."""
|
"""Extends clean method to perform additional validation, which can raise errors in django admin."""
|
||||||
super().clean()
|
super().clean()
|
||||||
validate_user_portfolio_permission(self)
|
# Ensure user exists before running further validation
|
||||||
|
# In django admin, this clean method is called before form validation checks
|
||||||
|
# for required fields. Since validation below requires user, skip if user does
|
||||||
|
# not exist
|
||||||
|
if self.user_id:
|
||||||
|
validate_user_portfolio_permission(self)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue