Skip to content

Commit 548db3e

Browse files
committed
Merge branch 'main' into lmendoa/PD-14333-PD-14423-PD-14449-PD-14450-recovery-phone
2 parents 7326e82 + 60fd3f7 commit 548db3e

28 files changed

Lines changed: 1997 additions & 236 deletions

‎projects/orcid-ui-docs/src/app/pages/orcid-ui/alert-message-page.component.html‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<mat-label>Alert Type</mat-label>
1818
<mat-select [(ngModel)]="type" aria-label="Alert type">
1919
<mat-option value="notice">Notice</mat-option>
20+
<mat-option value="notice-important">Notice (important)</mat-option>
2021
<mat-option value="info">Info</mat-option>
2122
<mat-option value="warning">Warning</mat-option>
2223
<mat-option value="success">Success</mat-option>
@@ -58,8 +59,12 @@
5859
<ul>
5960
<li>
6061
<code>type</code>:
61-
<code>'notice' | 'info' | 'warning' | 'success'</code> (default
62-
<code>'notice'</code>)
62+
<code
63+
>'notice' | 'notice-important' | 'info' | 'warning' | 'success'</code
64+
>
65+
(default <code>'notice'</code>). <code>'notice-important'</code> is the
66+
design system's notice-important: an error glyph, a #ff9c00 border and
67+
links in the ordinary link colour, for a notice the user has to act on.
6368
</li>
6469
</ul>
6570

‎projects/orcid-ui/src/lib/components/alert-message/alert-message.component.html‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
class="alert-container"
33
[ngClass]="{
44
'alert-notice': type == 'notice',
5+
'alert-notice-important': type == 'notice-important',
56
'alert-info': type == 'info',
67
'alert-warning': type == 'warning',
78
'alert-success': type == 'success'
@@ -14,6 +15,12 @@
1415
role="presentation"
1516
>info_outline</mat-icon
1617
>
18+
<mat-icon
19+
*ngIf="type == 'notice-important'"
20+
class="large-material-icon"
21+
role="presentation"
22+
>error_outline</mat-icon
23+
>
1724
<mat-icon
1825
*ngIf="type == 'info'"
1926
class="large-material-icon"

‎projects/orcid-ui/src/lib/components/alert-message/alert-message.component.scss-theme.scss‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111
'link-darkest': 'brand-quad-darkest',
1212
'link-dark': 'brand-quad-dark',
1313
),
14+
// PD-5692: the notice the design system calls notice-important, drawn in
15+
// the frames as #ff9c00 on the notice background with an error glyph and
16+
// the ordinary link colour. A variant of its own rather than a change to
17+
// 'notice', which every existing consumer would repaint with.
18+
'alert-notice-important':
19+
(
20+
'border': 'state-notice-dark',
21+
'background': 'state-notice-lightest',
22+
'link-darkest': 'brand-secondary-dark',
23+
'link-dark': 'brand-secondary-darkest',
24+
),
1425
'alert-info': (
1526
'border': 'state-info-darkest',
1627
'background': 'state-info-lightest',

‎projects/orcid-ui/src/lib/components/alert-message/alert-message.component.spec.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('AlertMessageComponent', () => {
2727
* warning variant was already on the right border and is pinned here beside
2828
* it so a later palette change cannot move one without the other.
2929
*/
30-
const containerOf = (type: 'warning' | 'success') => {
30+
const containerOf = (type: 'warning' | 'success' | 'notice-important') => {
3131
component.type = type
3232
fixture.detectChanges()
3333
return fixture.nativeElement.querySelector(
@@ -57,4 +57,34 @@ describe('AlertMessageComponent', () => {
5757
expect(style.borderTopColor).toBe('rgb(211, 47, 47)')
5858
expect(style.backgroundColor).toBe('rgb(255, 235, 238)')
5959
})
60+
61+
/*
62+
* PD-5692. The mandatory password reset frames draw their notice in the
63+
* design system's notice-important: #ff9c00 on the notice background, an
64+
* error glyph, and links in the ordinary #085c77. The plain notice keeps its
65+
* own colours, so nothing that already uses it changes.
66+
*/
67+
it('draws a notice-important alert in the design system colours', () => {
68+
const container = containerOf('notice-important')
69+
const style = getComputedStyle(container)
70+
71+
expect(style.borderTopColor).toBe('rgb(255, 156, 0)')
72+
expect(style.backgroundColor).toBe('rgb(255, 251, 238)')
73+
expect(container.querySelector('mat-icon').textContent.trim()).toBe(
74+
'error_outline'
75+
)
76+
})
77+
78+
it('leaves the plain notice on its own colours', () => {
79+
component.type = 'notice'
80+
fixture.detectChanges()
81+
const container = fixture.nativeElement.querySelector(
82+
'.alert-container'
83+
) as HTMLElement
84+
85+
expect(getComputedStyle(container).borderTopColor).toBe('rgb(255, 100, 0)')
86+
expect(container.querySelector('mat-icon').textContent.trim()).toBe(
87+
'info_outline'
88+
)
89+
})
6090
})

‎projects/orcid-ui/src/lib/components/alert-message/alert-message.component.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ export class AlertMessageComponent {
3030
@Input() type: AlertType = 'notice'
3131
}
3232

33-
export type AlertType = 'notice' | 'info' | 'warning' | 'success'
33+
export type AlertType =
34+
| 'notice'
35+
| 'notice-important'
36+
| 'info'
37+
| 'warning'
38+
| 'success'

‎src/app/core/sign-in/sign-in.service.spec.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,64 @@ describe('SignInService', () => {
304304
expect(response.orcid).toBe('0000-0001-2345-6789')
305305
})
306306
})
307+
308+
describe('password reset status lookup (PD-5692)', () => {
309+
let service: SignInService
310+
let httpController: HttpTestingController
311+
312+
beforeEach(() => {
313+
service = TestBed.inject(SignInService)
314+
httpController = TestBed.inject(HttpTestingController)
315+
})
316+
317+
afterEach(() => {
318+
httpController.verify()
319+
})
320+
321+
it('asks the registry, with an iD in its canonical form', () => {
322+
let response: { passwordResetRequired: boolean }
323+
service
324+
.getPasswordResetStatus(' https://orcid.org/0000-0001-2345-6789 ')
325+
.subscribe((value) => (response = value))
326+
327+
const request = httpController.expectOne(
328+
API_WEB + 'signin/password-reset-status.json'
329+
)
330+
expect(request.request.method).toBe('POST')
331+
expect(request.request.withCredentials).toBeTrue()
332+
expect(request.request.body).toEqual({ username: '0000-0001-2345-6789' })
333+
334+
request.flush({ passwordResetRequired: true })
335+
expect(response.passwordResetRequired).toBeTrue()
336+
})
337+
338+
it('answers false when the lookup fails, so sign in is never blocked', () => {
339+
let response: { passwordResetRequired: boolean }
340+
service
341+
.getPasswordResetStatus('user@example.org')
342+
.subscribe((value) => (response = value))
343+
344+
httpController
345+
.expectOne(API_WEB + 'signin/password-reset-status.json')
346+
.flush('boom', { status: 500, statusText: 'Server Error' })
347+
348+
expect(response.passwordResetRequired).toBeFalse()
349+
})
350+
351+
it('lets the error through when asked not to fail open', () => {
352+
let failed = false
353+
let answered = false
354+
service.getPasswordResetStatus('user@example.org', false).subscribe({
355+
next: () => (answered = true),
356+
error: () => (failed = true),
357+
})
358+
359+
httpController
360+
.expectOne(API_WEB + 'signin/password-reset-status.json')
361+
.flush('boom', { status: 500, statusText: 'Server Error' })
362+
363+
expect(failed).toBeTrue()
364+
expect(answered).toBeFalse()
365+
})
366+
})
307367
})

‎src/app/core/sign-in/sign-in.service.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { getOrcidNumber, isValidOrcidFormat } from '../../constants'
1919
import { Claim } from '../../types/claim.endpoint'
2020
import { Reactivation } from '../../types/reactivation.endpoint'
2121
import {
22+
PasswordResetStatusResponse,
2223
RecoveryPhoneSignInSendResponse,
2324
RecoveryPhoneSignInStatusResponse,
2425
RecoveryPhoneSignInVerifyResponse,
@@ -263,6 +264,35 @@ export class SignInService {
263264
)
264265
}
265266

267+
/**
268+
* Asks the Registry whether the record behind an email address or ORCID iD
269+
* has to reset its password before it can sign in (PD-5692), so the form
270+
* can say so before a password is typed.
271+
*
272+
* Always the Registry, like the recovery phone calls: the flag lives on the
273+
* record and the lookup is not part of either sign-in implementation. A
274+
* failure answers false and reports nothing: this is a hint, and the sign-in
275+
* itself reports the same state once the password is right. A caller that
276+
* has to tell "no reset owed" from "could not ask" passes `failOpen` false
277+
* and gets the error instead.
278+
*/
279+
getPasswordResetStatus(
280+
username: string,
281+
failOpen = true
282+
): Observable<PasswordResetStatusResponse> {
283+
const request = this._http.post<PasswordResetStatusResponse>(
284+
runtimeEnvironment.API_WEB + 'signin/password-reset-status.json',
285+
{ username: getOrcidNumber((username || '').trim()) },
286+
{
287+
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
288+
withCredentials: true,
289+
}
290+
)
291+
return failOpen
292+
? request.pipe(catchError(() => of({ passwordResetRequired: false })))
293+
: request
294+
}
295+
266296
/**
267297
* Reports sign-in HTTP/network failures with flow context for NR dashboards.
268298
* Application-level failures (200 + success: false) use {@link AppEventName.SignInFailure}.

‎src/app/record/components/top-bar/top-bar.component.html‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,45 @@
1212
[justRegistered]="justRegistered"
1313
></app-top-bar-verification-email>
1414
<ng-container *ngIf="!isPublicRecord && !recordWithIssues">
15+
<!--
16+
PD-5692: the record has to reset its password. Its user got here through a
17+
linked institutional or social account, since a password sign in is
18+
refused, so the action goes straight to the Account password panel.
19+
-->
20+
<app-alert-message
21+
type="notice-important"
22+
*ngIf="userInfo?.FORCE_PASSWORD_RESET === 'true'"
23+
class="force-password-reset"
24+
id="cy-force-password-reset-notice"
25+
>
26+
<div content>
27+
<p class="force-password-reset-title">
28+
<strong i18n="@@topBar.passwordResetRequired.title"
29+
>Your ORCID account password needs to be reset</strong
30+
>
31+
</p>
32+
<p>
33+
<ng-container i18n="@@topBar.passwordResetRequired.body"
34+
>To help maintain the security of your ORCID account please reset your
35+
account password.</ng-container
36+
>&nbsp;<i i18n="@@topBar.passwordResetRequired.cannotSignIn"
37+
>You will not be able to sign in to ORCID until your password has been
38+
reset.</i
39+
>
40+
</p>
41+
<p class="force-password-reset-action">
42+
<a
43+
class="underline"
44+
routerLink="/account"
45+
fragment="password"
46+
id="cy-force-password-reset-link"
47+
i18n="@@topBar.passwordResetRequired.resetNow"
48+
>Reset your account password now</a
49+
>
50+
</p>
51+
</div>
52+
</app-alert-message>
53+
1554
<orcid-registry-permission-notifications
1655
*ngIf="permissionPanelNotifications?.length && userInfo?.LOCKED !== 'true'"
1756
[title]="permissionPanelTitle"

‎src/app/record/components/top-bar/top-bar.component.scss‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,24 @@ app-warning-message,
189189
orcid-registry-permission-notifications {
190190
margin-bottom: 16px;
191191
}
192+
193+
// PD-5692: 8px from the title to the body and one blank line before the
194+
// action, as the design draws it; 32px from the printable version link above
195+
// (whose button box already holds 24px of it) and 32px to the names panel below
196+
app-alert-message.force-password-reset {
197+
display: block;
198+
margin-top: 8px;
199+
margin-bottom: 32px;
200+
201+
p {
202+
margin: 0;
203+
}
204+
205+
.force-password-reset-title {
206+
margin-bottom: 8px;
207+
}
208+
209+
.force-password-reset-action {
210+
margin-top: 21px;
211+
}
212+
}

‎src/app/record/components/top-bar/top-bar.component.spec.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,67 @@ describe('TopBarComponent', () => {
151151
)
152152
})
153153
})
154+
155+
/*
156+
* PD-5692. A record that has to reset its password gets here through a
157+
* linked institutional account, and the notice takes it straight to the
158+
* Account password panel.
159+
*/
160+
describe('mandatory password reset notice', () => {
161+
const notice = (): HTMLElement =>
162+
fixture.nativeElement.querySelector(
163+
'[id="cy-force-password-reset-notice"]'
164+
)
165+
166+
it('shows above everything else and links to the password panel', () => {
167+
component.userInfo = { FORCE_PASSWORD_RESET: 'true' } as any
168+
component.userRecord = {
169+
names: {
170+
givenNames: { value: 'Given' },
171+
familyName: { value: 'Family' },
172+
visibility: { visibility: 'PUBLIC' },
173+
},
174+
} as any
175+
fixture.detectChanges()
176+
177+
expect(notice()).toBeTruthy()
178+
const link: HTMLAnchorElement = notice().querySelector(
179+
'#cy-force-password-reset-link'
180+
)
181+
expect(link.getAttribute('href')).toBe('/account#password')
182+
expect(link.textContent.trim()).toBe('Reset your account password now')
183+
// The first thing in the signed-in part of the page, ahead of every
184+
// other notice and of the names panel, as the frame draws it
185+
const host: HTMLElement = fixture.nativeElement
186+
const children = Array.from(host.children)
187+
const previous = children[children.indexOf(notice()) - 1]
188+
expect(previous.tagName.toLowerCase()).toBe(
189+
'app-top-bar-verification-email'
190+
)
191+
const names = host.querySelector('#names')
192+
expect(names).toBeTruthy()
193+
expect(
194+
notice().compareDocumentPosition(names) &
195+
Node.DOCUMENT_POSITION_FOLLOWING
196+
).toBeTruthy()
197+
})
198+
199+
it('is absent when no reset is owed', () => {
200+
component.userInfo = { FORCE_PASSWORD_RESET: 'false' } as any
201+
fixture.detectChanges()
202+
expect(notice()).toBeNull()
203+
204+
component.userInfo = {} as any
205+
fixture.detectChanges()
206+
expect(notice()).toBeNull()
207+
})
208+
209+
it('is absent on a public record', () => {
210+
component.isPublicRecord = 'true' as any
211+
component.userInfo = { FORCE_PASSWORD_RESET: 'true' } as any
212+
fixture.detectChanges()
213+
214+
expect(notice()).toBeNull()
215+
})
216+
})
154217
})

0 commit comments

Comments
 (0)