Skip to content

Commit 388b127

Browse files
committed
Disable primary-contact editing in console
This is necessary because we'll use primary-contact emails as a way of resetting passwords. In the UI, don't allow editing of email address for primary contacts, and don't allow addition/removal of the primary contact field post-creation. In the backend, make sure that all emails previously added still exist.
1 parent dfef733 commit 388b127

File tree

7 files changed

+135
-110
lines changed

7 files changed

+135
-110
lines changed

console-webapp/src/app/settings/contact/contact.component.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ import { Component, effect, ViewEncapsulation } from '@angular/core';
1616
import { MatTableDataSource } from '@angular/material/table';
1717
import { take } from 'rxjs';
1818
import { RegistrarService } from 'src/app/registrar/registrar.service';
19-
import {
20-
ContactService,
21-
contactTypeToViewReadyContact,
22-
ViewReadyContact,
23-
} from './contact.service';
19+
import { ContactService, ViewReadyContact } from './contact.service';
2420

2521
@Component({
2622
selector: 'app-contact',

console-webapp/src/app/settings/contact/contactDetails.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ <h1>Contact Details</h1>
5656
[required]="true"
5757
[(ngModel)]="contactService.contactInEdit.emailAddress"
5858
[ngModelOptions]="{ standalone: true }"
59+
[disabled]="emailAddressIsDisabled()"
5960
/>
6061
</mat-form-field>
6162

console-webapp/src/app/settings/contact/contactDetails.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export class ContactDetailsComponent {
8989
}
9090

9191
checkboxIsDisabled(type: string) {
92+
if (!this.contactService.isContactNewView && type === 'ADMIN') {
93+
return true;
94+
}
9295
return (
9396
this.contactService.contactInEdit.types.length === 1 &&
9497
this.contactService.contactInEdit.types[0] === (type as contactType)
@@ -105,4 +108,11 @@ export class ContactDetailsComponent {
105108
);
106109
}
107110
}
111+
112+
emailAddressIsDisabled() {
113+
if (this.contactService.isContactNewView) {
114+
return true;
115+
}
116+
return this.contactService.contactInEdit.types.includes('ADMIN');
117+
}
108118
}

core/src/main/java/google/registry/ui/server/console/settings/ContactAction.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private static void checkContactRequirements(
169169
throw new ContactRequirementException(t);
170170
}
171171
}
172+
enforcePrimaryContactRestrictions(oldContactsByType, newContactsByType);
172173
ensurePhoneNumberNotRemovedForContactTypes(oldContactsByType, newContactsByType, Type.TECH);
173174
Optional<RegistrarPoc> domainWhoisAbuseContact =
174175
getDomainWhoisVisibleAbuseContact(updatedContacts);
@@ -187,6 +188,23 @@ private static void checkContactRequirements(
187188
checkContactRegistryLockRequirements(existingContacts, updatedContacts);
188189
}
189190

191+
private static void enforcePrimaryContactRestrictions(
192+
Multimap<Type, RegistrarPoc> oldContactsByType,
193+
Multimap<Type, RegistrarPoc> newContactsByType) {
194+
ImmutableSet<String> oldAdminEmails =
195+
oldContactsByType.get(Type.ADMIN).stream()
196+
.map(RegistrarPoc::getEmailAddress)
197+
.collect(toImmutableSet());
198+
ImmutableSet<String> newAdminEmails =
199+
newContactsByType.get(Type.ADMIN).stream()
200+
.map(RegistrarPoc::getEmailAddress)
201+
.collect(toImmutableSet());
202+
if (!newAdminEmails.containsAll(oldAdminEmails)) {
203+
throw new ContactRequirementException(
204+
"Cannot remove or change the email address of primary contacts");
205+
}
206+
}
207+
190208
private static void checkContactRegistryLockRequirements(
191209
ImmutableSet<RegistrarPoc> existingContacts, ImmutableSet<RegistrarPoc> updatedContacts) {
192210
// Any contact(s) with new passwords must be allowed to set them

0 commit comments

Comments
 (0)