Skip to content

Commit 8ee9446

Browse files
mattjokeHejdaJakub
authored andcommitted
feat(user-profile): removed setMfaEnforced call
* removed setMfaEnforced call from user profile * refactored the loading process of settings * removed unnecessary margin in accordions DEPLOYMENT NOTE: value of the 'enable_detail_settings' is now ignored, accordion will appear based on the categories from the attribute
1 parent 05b4a03 commit 8ee9446

File tree

6 files changed

+17
-52
lines changed

6 files changed

+17
-52
lines changed

apps/user-profile/src/app/pages/settings-page/settings-authorization/mfa-settings/mfa-settings.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ <h1 class="page-subtitle">{{'AUTHENTICATION.MFA' | customTranslate | translate}}
2323
<mat-expansion-panel [disabled]="!mfaAvailable || !enableDetailSettings">
2424
<mat-expansion-panel-header>
2525
<mat-checkbox
26-
class="toggle-ellipsis mt-2 me-5"
26+
class="toggle-ellipsis me-5"
2727
[disabled]="!mfaAvailable"
2828
(click)="$event.stopPropagation()"
2929
[(ngModel)]="enforceMfa"
@@ -40,7 +40,7 @@ <h1 class="page-subtitle">{{'AUTHENTICATION.MFA' | customTranslate | translate}}
4040
<mat-expansion-panel-header
4141
[class.cursor-default]="allRpsKeysByCategory.get(category).length === 0">
4242
<mat-checkbox
43-
class="toggle-ellipsis mt-2 me-2"
43+
class="toggle-ellipsis me-2"
4444
(click)="$event.stopPropagation()"
4545
[checked]="categorySelection.isSelected(category)"
4646
[indeterminate]="categorySelection.isSelected(category) && rpsSelections.get(category).selected.length !== allRpsKeysByCategory.get(category).length"

apps/user-profile/src/app/pages/settings-page/settings-authorization/mfa-settings/mfa-settings.component.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class MfaSettingsComponent implements OnInit {
2828

2929
enforceMfa: boolean;
3030
originalMfa = false;
31-
enableDetailSettings: boolean;
31+
enableDetailSettings = true;
3232
loadingCategories = false;
3333
unchangedSettings = true;
3434
categorySelection: SelectionModel<string>;
@@ -62,7 +62,6 @@ export class MfaSettingsComponent implements OnInit {
6262

6363
this.mfaUrl = this.translate.currentLang === 'en' ? mfa.url_en : mfa.url_cs;
6464
this.categorySelection = new SelectionModel<string>(true, []);
65-
this.enableDetailSettings = this.store.getProperty('mfa').enable_detail_settings;
6665
this.mfaApiService.isMfaAvailable().subscribe({
6766
next: (isAvailable) => {
6867
this.mfaAvailable = isAvailable;
@@ -89,16 +88,10 @@ export class MfaSettingsComponent implements OnInit {
8988
const mfaRoute = sessionStorage.getItem('mfa_route');
9089
if (mfaRoute) {
9190
const enforceMfa = sessionStorage.getItem('enforce_mfa');
91+
// This should propagate unfinished PUT action
9292
if (enforceMfa) {
93-
this.mfaApiService.changeEnforceMfa(enforceMfa === 'true').subscribe({
94-
next: () => {
95-
this.loadingMfa = false;
96-
},
97-
error: () => {
98-
this.loadingMfa = false;
99-
this.loadingCategories = false;
100-
},
101-
});
93+
const body = JSON.stringify({ all: enforceMfa === 'true' });
94+
sessionStorage.setItem('settings_mfa', body);
10295
}
10396
const settingsMfa = sessionStorage.getItem('settings_mfa');
10497
if (settingsMfa) {
@@ -153,9 +146,13 @@ export class MfaSettingsComponent implements OnInit {
153146
}
154147

155148
setSelections(): void {
149+
// Check if the settings have categories
150+
this.enableDetailSettings =
151+
this.settings.categories && Object.keys(this.settings.categories).length > 0;
156152
this.categorySelection = new SelectionModel<string>(true, this.settings.includedCategories);
157153
this.allCategoriesKeys = Object.keys(this.settings.categories);
158-
this.enforceMfa = this.settings.includedCategories.length > 0;
154+
// Select if 'allEnforced' is true
155+
this.enforceMfa = this.settings.includedCategories.length > 0 || this.settings.allEnforced;
159156
for (const category in this.settings.categories) {
160157
this.allRpsKeysByCategory.set(
161158
category,
@@ -227,7 +224,7 @@ export class MfaSettingsComponent implements OnInit {
227224
}
228225

229226
/**
230-
* This method fires logic for setting new values of enforceMfa and settings
227+
* This method fires logic for setting new values of settings
231228
*/
232229
saveSettings(enforceFirstMfa = false): void {
233230
this.loadingMfa = true;

apps/user-profile/src/assets/config/defaultConfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
"api_url": "https://id.muni.cz/mfaapi/",
7777
"enable_security_image": true,
7878
"enable_security_text": true,
79-
"enable_detail_settings": false,
8079
"security_image_attribute": "urn:perun:user:attribute-def:def:securityImage:mu",
8180
"security_text_attribute": "urn:perun:user:attribute-def:def:securityText:mu",
8281
"enforce_mfa_attribute": "urn:perun:user:attribute-def:def:mfaEnforced:mu",

libs/perun/models/src/lib/ConfigProperties.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ interface ProfileMFA {
119119
api_url: string;
120120
enable_security_image: boolean;
121121
enable_security_text: boolean;
122-
enable_detail_settings: boolean;
123122
security_image_attribute: string;
124123
security_text_attribute: string;
125124
enforce_mfa_attribute: string;

libs/perun/models/src/lib/MfaSettings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface MfaSettings {
2+
allEnforced: boolean;
23
categories: object;
34
includedCategories: string[];
45
excludedRps: string[];

libs/perun/services/src/lib/mfa-api.service.ts

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class MfaApiService {
5050
*/
5151
getSettings(): Observable<MfaSettings> {
5252
const result: MfaSettings = {
53+
allEnforced: false,
5354
categories: {},
5455
includedCategories: [],
5556
excludedRps: [],
@@ -76,6 +77,7 @@ export class MfaApiService {
7677
next: (settings) => {
7778
if (settings.length !== 0) {
7879
if (settings.all) {
80+
result.allEnforced = settings.all;
7981
result.includedCategories = Object.keys(result.categories);
8082
for (const category in result.categories) {
8183
result.includedRpsByCategory[category] = Object.keys(
@@ -148,48 +150,15 @@ export class MfaApiService {
148150
}
149151
sessionStorage.setItem('settings_mfa', body);
150152
}
151-
152-
changeEnforceMfa(enforceMfa: boolean): Observable<any> {
153-
const body = `value=${String(enforceMfa)}`;
154-
return new Observable<any>((res) => {
155-
this.httpClient
156-
.put(this.mfaApiUrl + 'mfaEnforced', body, {
157-
headers: { Authorization: 'Bearer ' + this.oauthService.getAccessToken() },
158-
})
159-
.subscribe({
160-
next: () => {
161-
sessionStorage.removeItem('enforce_mfa');
162-
sessionStorage.removeItem('mfa_route');
163-
res.next();
164-
},
165-
error: (err) => {
166-
// when token is valid, but user is logged in without MFA -> enforce MFA
167-
if (err.error.error === 'MFA is required') {
168-
this.saveSettings(null, true).subscribe();
169-
} else {
170-
res.error(err);
171-
}
172-
},
173-
});
174-
});
175-
}
176-
177153
/**
178154
* This method fires logic for setting new values of enforceMfa and settings
179155
*/
180156
saveSettings(newEnforce: boolean, enforceFirstMfa = false): Observable<any> {
181157
return new Observable<any>((res) => {
182158
if (this.oauthService.getIdTokenExpiration() - now() > 0 && !enforceFirstMfa) {
183-
this.changeEnforceMfa(newEnforce).subscribe({
159+
this.updateDetailSettings().subscribe({
184160
next: () => {
185-
this.updateDetailSettings().subscribe({
186-
next: () => {
187-
res.next();
188-
},
189-
error: (e) => {
190-
res.error(e);
191-
},
192-
});
161+
res.next();
193162
},
194163
error: (e) => {
195164
res.error(e);

0 commit comments

Comments
 (0)