Skip to content

Commit f26070d

Browse files
authored
Merge pull request #1274 from ORCID/allow-admins-to-disable-2fa
Allow admins to disable 2fa
2 parents a94c58d + 93f707f commit f26070d

31 files changed

+926
-259
lines changed

ui/cypress/e2e/retention/add-user.cy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ describe("Add new user", () => {
3838
cy.get("#field_mainContact").click();
3939
// Admin checkbox should not exist
4040
cy.get("#field_isAdmin").should("not.exist");
41+
// Disable 2fa should not exist
42+
cy.get("#field_twoFactorAuthentication").should("not.exist");
4143
// save
4244
cy.get("#save-entity").click();
4345
cy.get(".alert-success").should("exist");

ui/cypress/e2e/retention/edit-user.cy.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ describe("Test the edit user form", () => {
3939
cy.get("#field_salesforceId").invoke("attr", "disabled").should("exist");
4040
// Admin checkbox should not exist
4141
cy.get("#field_isAdmin").should("not.exist");
42+
// Disable 2fa should not exist
43+
cy.get("#field_twoFactorAuthentication").should("not.exist");
4244
// 'Activated' checkbox is missing the 'disabled' attr
4345
/*cy.get('#field_activated')
4446
.invoke('attr', 'disabled')

ui/src/app/account/login/login.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('LoginComponent', () => {
4545
loginService.login.and.returnValue(of(mockLoginResult))
4646
accountService.getAccountData.and.returnValue(
4747
of({
48+
id: 'id',
4849
activated: true,
4950
authorities: ['test', 'test'],
5051
email: 'email@email.com',

ui/src/app/account/model/account.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface IAccount {
2+
id: string
23
activated: boolean
34
authorities: string[]
45
email: string

ui/src/app/account/service/account.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export class AccountService {
8989
)
9090
}
9191

92-
disableMfa(): Observable<boolean> {
93-
return this.http.post('/services/userservice/api/account/mfa/off', null, { observe: 'response' }).pipe(
92+
disableMfa(userId: string): Observable<boolean> {
93+
return this.http.post(`/services/userservice/api/account/${userId}/mfa/off`, null, { observe: 'response' }).pipe(
9494
map((res: HttpResponse<any>) => this.isSuccess(res)),
9595
catchError(() => {
9696
return of(false)

ui/src/app/account/settings/settings.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('SettingsComponent', () => {
6363
it('should create', () => {
6464
accountServiceSpy.getAccountData.and.returnValue(
6565
of({
66+
id: 'id',
6667
activated: true,
6768
authorities: ['test', 'test'],
6869
email: 'email@email.com',
@@ -84,6 +85,7 @@ describe('SettingsComponent', () => {
8485
it('should flip mfa fields when mfa state changed', () => {
8586
accountServiceSpy.getAccountData.and.returnValue(
8687
of({
88+
id: 'id',
8789
activated: true,
8890
authorities: ['test', 'test'],
8991
email: 'email@email.com',
@@ -115,6 +117,7 @@ describe('SettingsComponent', () => {
115117
it('should flip mfa fields when mfa state changed', () => {
116118
accountServiceSpy.getAccountData.and.returnValue(
117119
of({
120+
id: 'id',
118121
activated: true,
119122
authorities: ['test', 'test'],
120123
email: 'email@email.com',
@@ -141,6 +144,7 @@ describe('SettingsComponent', () => {
141144
it('save mfa enabled should call account service enable', () => {
142145
accountServiceSpy.getAccountData.and.returnValue(
143146
of({
147+
id: 'id',
144148
activated: true,
145149
authorities: ['test', 'test'],
146150
email: 'email@email.com',
@@ -169,6 +173,7 @@ describe('SettingsComponent', () => {
169173
it('save mfa enabled should call account service disable', () => {
170174
accountServiceSpy.getAccountData.and.returnValue(
171175
of({
176+
id: 'id',
172177
activated: true,
173178
authorities: ['test', 'test'],
174179
email: 'email@email.com',
@@ -185,6 +190,7 @@ describe('SettingsComponent', () => {
185190
)
186191
accountServiceSpy.getMfaSetup.and.returnValue(of({ secret: 'test', otp: 'test', qrCode: ['test'] }))
187192
accountServiceSpy.disableMfa.and.returnValue(of(true))
193+
fixture.detectChanges()
188194

189195
component.mfaForm.patchValue({ mfaEnabled: false, verificationCode: 'test' })
190196
component.saveMfa()
@@ -197,6 +203,7 @@ describe('SettingsComponent', () => {
197203
accountServiceSpy.save.and.returnValue(of(true))
198204
accountServiceSpy.getAccountData.and.returnValue(
199205
of({
206+
id: 'id',
200207
activated: true,
201208
authorities: ['test', 'test'],
202209
email: 'email@email.com',
@@ -222,6 +229,7 @@ describe('SettingsComponent', () => {
222229
accountServiceSpy.save.and.returnValue(of(false))
223230
accountServiceSpy.getAccountData.and.returnValue(
224231
of({
232+
id: 'id',
225233
activated: true,
226234
authorities: ['test', 'test'],
227235
email: 'email@email.com',

ui/src/app/account/settings/settings.component.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,17 @@ export class SettingsComponent implements OnInit {
118118
}
119119
})
120120
} else {
121-
this.accountService.disableMfa().subscribe({
122-
next: () => {
123-
this.showMfaUpdated = true
124-
this.accountService.getMfaSetup().subscribe((res) => {
125-
this.mfaSetup = res
126-
})
127-
},
128-
error: (err) => console.log('error disabling mfa'),
129-
})
121+
if (this.account && this.account.id) {
122+
this.accountService.disableMfa(this.account.id).subscribe({
123+
next: () => {
124+
this.showMfaUpdated = true
125+
this.accountService.getMfaSetup().subscribe((res) => {
126+
this.mfaSetup = res
127+
})
128+
},
129+
error: (err) => console.log('error disabling mfa'),
130+
})
131+
}
130132
}
131133
}
132134

ui/src/app/affiliation/affiliations.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('AffiliationsComponent', () => {
6363

6464
accountService.getAccountData.and.returnValue(
6565
of({
66+
id: 'id',
6667
activated: true,
6768
authorities: ['ROLE_USER', 'ROLE_ADMIN'],
6869
email: 'email@email.com',

ui/src/app/affiliation/send-notifications-dialog.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ describe('SendNotificationsDialogComponent', () => {
6868
it('should create', () => {
6969
accountServiceSpy.getAccountData.and.returnValue(
7070
of({
71+
id: 'id',
7172
activated: true,
7273
authorities: ['test', 'test'],
7374
email: 'email@email.com',

ui/src/app/home/consortium/add-consortium-member.component.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe('AddConsortiumMemberComponent', () => {
4848

4949
accountServiceSpy.getAccountData.and.returnValue(
5050
of({
51+
id: 'id',
5152
activated: true,
5253
authorities: ['test', 'test'],
5354
email: 'email@email.com',

0 commit comments

Comments
 (0)