Skip to content
Merged

PD-5692 #2931

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<mat-label>Alert Type</mat-label>
<mat-select [(ngModel)]="type" aria-label="Alert type">
<mat-option value="notice">Notice</mat-option>
<mat-option value="notice-important">Notice (important)</mat-option>
<mat-option value="info">Info</mat-option>
<mat-option value="warning">Warning</mat-option>
<mat-option value="success">Success</mat-option>
Expand Down Expand Up @@ -58,8 +59,12 @@
<ul>
<li>
<code>type</code>:
<code>'notice' | 'info' | 'warning' | 'success'</code> (default
<code>'notice'</code>)
<code
>'notice' | 'notice-important' | 'info' | 'warning' | 'success'</code
>
(default <code>'notice'</code>). <code>'notice-important'</code> is the
design system's notice-important: an error glyph, a #ff9c00 border and
links in the ordinary link colour, for a notice the user has to act on.
</li>
</ul>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class="alert-container"
[ngClass]="{
'alert-notice': type == 'notice',
'alert-notice-important': type == 'notice-important',
'alert-info': type == 'info',
'alert-warning': type == 'warning',
'alert-success': type == 'success'
Expand All @@ -14,6 +15,12 @@
role="presentation"
>info_outline</mat-icon
>
<mat-icon
*ngIf="type == 'notice-important'"
class="large-material-icon"
role="presentation"
>error_outline</mat-icon
>
<mat-icon
*ngIf="type == 'info'"
class="large-material-icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
'link-darkest': 'brand-quad-darkest',
'link-dark': 'brand-quad-dark',
),
// PD-5692: the notice the design system calls notice-important, drawn in
// the frames as #ff9c00 on the notice background with an error glyph and
// the ordinary link colour. A variant of its own rather than a change to
// 'notice', which every existing consumer would repaint with.
'alert-notice-important':
(
'border': 'state-notice-dark',
'background': 'state-notice-lightest',
'link-darkest': 'brand-secondary-dark',
'link-dark': 'brand-secondary-darkest',
),
'alert-info': (
'border': 'state-info-darkest',
'background': 'state-info-lightest',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('AlertMessageComponent', () => {
* warning variant was already on the right border and is pinned here beside
* it so a later palette change cannot move one without the other.
*/
const containerOf = (type: 'warning' | 'success') => {
const containerOf = (type: 'warning' | 'success' | 'notice-important') => {
component.type = type
fixture.detectChanges()
return fixture.nativeElement.querySelector(
Expand Down Expand Up @@ -57,4 +57,34 @@ describe('AlertMessageComponent', () => {
expect(style.borderTopColor).toBe('rgb(211, 47, 47)')
expect(style.backgroundColor).toBe('rgb(255, 235, 238)')
})

/*
* PD-5692. The mandatory password reset frames draw their notice in the
* design system's notice-important: #ff9c00 on the notice background, an
* error glyph, and links in the ordinary #085c77. The plain notice keeps its
* own colours, so nothing that already uses it changes.
*/
it('draws a notice-important alert in the design system colours', () => {
const container = containerOf('notice-important')
const style = getComputedStyle(container)

expect(style.borderTopColor).toBe('rgb(255, 156, 0)')
expect(style.backgroundColor).toBe('rgb(255, 251, 238)')
expect(container.querySelector('mat-icon').textContent.trim()).toBe(
'error_outline'
)
})

it('leaves the plain notice on its own colours', () => {
component.type = 'notice'
fixture.detectChanges()
const container = fixture.nativeElement.querySelector(
'.alert-container'
) as HTMLElement

expect(getComputedStyle(container).borderTopColor).toBe('rgb(255, 100, 0)')
expect(container.querySelector('mat-icon').textContent.trim()).toBe(
'info_outline'
)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ export class AlertMessageComponent {
@Input() type: AlertType = 'notice'
}

export type AlertType = 'notice' | 'info' | 'warning' | 'success'
export type AlertType =
| 'notice'
| 'notice-important'
| 'info'
| 'warning'
| 'success'
60 changes: 60 additions & 0 deletions src/app/core/sign-in/sign-in.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,64 @@ describe('SignInService', () => {
expect(response.orcid).toBe('0000-0001-2345-6789')
})
})

describe('password reset status lookup (PD-5692)', () => {
let service: SignInService
let httpController: HttpTestingController

beforeEach(() => {
service = TestBed.inject(SignInService)
httpController = TestBed.inject(HttpTestingController)
})

afterEach(() => {
httpController.verify()
})

it('asks the registry, with an iD in its canonical form', () => {
let response: { passwordResetRequired: boolean }
service
.getPasswordResetStatus(' https://orcid.org/0000-0001-2345-6789 ')
.subscribe((value) => (response = value))

const request = httpController.expectOne(
API_WEB + 'signin/password-reset-status.json'
)
expect(request.request.method).toBe('POST')
expect(request.request.withCredentials).toBeTrue()
expect(request.request.body).toEqual({ username: '0000-0001-2345-6789' })

request.flush({ passwordResetRequired: true })
expect(response.passwordResetRequired).toBeTrue()
})

it('answers false when the lookup fails, so sign in is never blocked', () => {
let response: { passwordResetRequired: boolean }
service
.getPasswordResetStatus('user@example.org')
.subscribe((value) => (response = value))

httpController
.expectOne(API_WEB + 'signin/password-reset-status.json')
.flush('boom', { status: 500, statusText: 'Server Error' })

expect(response.passwordResetRequired).toBeFalse()
})

it('lets the error through when asked not to fail open', () => {
let failed = false
let answered = false
service.getPasswordResetStatus('user@example.org', false).subscribe({
next: () => (answered = true),
error: () => (failed = true),
})

httpController
.expectOne(API_WEB + 'signin/password-reset-status.json')
.flush('boom', { status: 500, statusText: 'Server Error' })

expect(failed).toBeTrue()
expect(answered).toBeFalse()
})
})
})
30 changes: 30 additions & 0 deletions src/app/core/sign-in/sign-in.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getOrcidNumber, isValidOrcidFormat } from '../../constants'
import { Claim } from '../../types/claim.endpoint'
import { Reactivation } from '../../types/reactivation.endpoint'
import {
PasswordResetStatusResponse,
RecoveryPhoneSignInSendResponse,
RecoveryPhoneSignInVerifyResponse,
SignIn,
Expand Down Expand Up @@ -203,6 +204,35 @@ export class SignInService {
)
}

/**
* Asks the Registry whether the record behind an email address or ORCID iD
* has to reset its password before it can sign in (PD-5692), so the form
* can say so before a password is typed.
*
* Always the Registry, like the recovery phone calls: the flag lives on the
* record and the lookup is not part of either sign-in implementation. A
* failure answers false and reports nothing: this is a hint, and the sign-in
* itself reports the same state once the password is right. A caller that
* has to tell "no reset owed" from "could not ask" passes `failOpen` false
* and gets the error instead.
*/
getPasswordResetStatus(
username: string,
failOpen = true
): Observable<PasswordResetStatusResponse> {
const request = this._http.post<PasswordResetStatusResponse>(
runtimeEnvironment.API_WEB + 'signin/password-reset-status.json',
{ username: getOrcidNumber((username || '').trim()) },
{
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
withCredentials: true,
}
)
return failOpen
? request.pipe(catchError(() => of({ passwordResetRequired: false })))
: request
}

/**
* Reports sign-in HTTP/network failures with flow context for NR dashboards.
* Application-level failures (200 + success: false) use {@link AppEventName.SignInFailure}.
Expand Down
39 changes: 39 additions & 0 deletions src/app/record/components/top-bar/top-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,45 @@
[justRegistered]="justRegistered"
></app-top-bar-verification-email>
<ng-container *ngIf="!isPublicRecord && !recordWithIssues">
<!--
PD-5692: the record has to reset its password. Its user got here through a
linked institutional or social account, since a password sign in is
refused, so the action goes straight to the Account password panel.
-->
<app-alert-message
type="notice-important"
*ngIf="userInfo?.FORCE_PASSWORD_RESET === 'true'"
class="force-password-reset"
id="cy-force-password-reset-notice"
>
<div content>
<p class="force-password-reset-title">
<strong i18n="@@topBar.passwordResetRequired.title"
>Your ORCID account password needs to be reset</strong
>
</p>
<p>
<ng-container i18n="@@topBar.passwordResetRequired.body"
>To help maintain the security of your ORCID account please reset your
account password.</ng-container
>&nbsp;<i i18n="@@topBar.passwordResetRequired.cannotSignIn"
>You will not be able to sign in to ORCID until your password has been
reset.</i
>
</p>
<p class="force-password-reset-action">
<a
class="underline"
routerLink="/account"
fragment="password"
id="cy-force-password-reset-link"
i18n="@@topBar.passwordResetRequired.resetNow"
>Reset your account password now</a
>
</p>
</div>
</app-alert-message>

<orcid-registry-permission-notifications
*ngIf="permissionPanelNotifications?.length && userInfo?.LOCKED !== 'true'"
[title]="permissionPanelTitle"
Expand Down
21 changes: 21 additions & 0 deletions src/app/record/components/top-bar/top-bar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,24 @@ app-warning-message,
orcid-registry-permission-notifications {
margin-bottom: 16px;
}

// PD-5692: 8px from the title to the body and one blank line before the
// action, as the design draws it; 32px from the printable version link above
// (whose button box already holds 24px of it) and 32px to the names panel below
app-alert-message.force-password-reset {
display: block;
margin-top: 8px;
margin-bottom: 32px;

p {
margin: 0;
}

.force-password-reset-title {
margin-bottom: 8px;
}

.force-password-reset-action {
margin-top: 21px;
}
}
63 changes: 63 additions & 0 deletions src/app/record/components/top-bar/top-bar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,67 @@ describe('TopBarComponent', () => {
)
})
})

/*
* PD-5692. A record that has to reset its password gets here through a
* linked institutional account, and the notice takes it straight to the
* Account password panel.
*/
describe('mandatory password reset notice', () => {
const notice = (): HTMLElement =>
fixture.nativeElement.querySelector(
'[id="cy-force-password-reset-notice"]'
)

it('shows above everything else and links to the password panel', () => {
component.userInfo = { FORCE_PASSWORD_RESET: 'true' } as any
component.userRecord = {
names: {
givenNames: { value: 'Given' },
familyName: { value: 'Family' },
visibility: { visibility: 'PUBLIC' },
},
} as any
fixture.detectChanges()

expect(notice()).toBeTruthy()
const link: HTMLAnchorElement = notice().querySelector(
'#cy-force-password-reset-link'
)
expect(link.getAttribute('href')).toBe('/account#password')
expect(link.textContent.trim()).toBe('Reset your account password now')
// The first thing in the signed-in part of the page, ahead of every
// other notice and of the names panel, as the frame draws it
const host: HTMLElement = fixture.nativeElement
const children = Array.from(host.children)
const previous = children[children.indexOf(notice()) - 1]
expect(previous.tagName.toLowerCase()).toBe(
'app-top-bar-verification-email'
)
const names = host.querySelector('#names')
expect(names).toBeTruthy()
expect(
notice().compareDocumentPosition(names) &
Node.DOCUMENT_POSITION_FOLLOWING
).toBeTruthy()
})

it('is absent when no reset is owed', () => {
component.userInfo = { FORCE_PASSWORD_RESET: 'false' } as any
fixture.detectChanges()
expect(notice()).toBeNull()

component.userInfo = {} as any
fixture.detectChanges()
expect(notice()).toBeNull()
})

it('is absent on a public record', () => {
component.isPublicRecord = 'true' as any
component.userInfo = { FORCE_PASSWORD_RESET: 'true' } as any
fixture.detectChanges()

expect(notice()).toBeNull()
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ <h3 i18n="@@register.yourPasswords" class="orc-font-body no-top-margin">
[ngClass]="{ error: passwordTouched && form.controls.password.errors }"
/>
</mat-form-field>
<mat-error *ngIf="passwordTouched && form.hasError('required', 'password')">
<mat-error
*ngIf="
passwordTouched &&
form.hasError('required', 'password') &&
!form.hasError('passwordPreviouslyUsed', 'password')
"
>
{{ passwordIsRequired }}
</mat-error>
<mat-error
Expand All @@ -47,6 +53,17 @@ <h3 i18n="@@register.yourPasswords" class="orc-font-body no-top-margin">
>
Password must not be the same as your email address
</mat-error>
<!-- PD-5692: only the password reset sets this, from the registry's answer -->
<mat-error
*ngIf="
passwordTouched && form.hasError('passwordPreviouslyUsed', 'password')
"
id="cy-password-previously-used-error"
role="alert"
i18n="@@register.passwordPreviouslyUsed"
>Please enter a new password. Previous passwords cannot be
reused.</mat-error
>
<mat-error
*ngIf="
passwordTouched &&
Expand Down
Loading
Loading