Skip to content

Commit dc6abbb

Browse files
committed
refactor: New auth state management
1 parent 99922c7 commit dc6abbb

File tree

53 files changed

+762
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+762
-529
lines changed

projects/hslayers/assets/locales/cs.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2+
"AUTH": {
3+
"signingIn": "Přihlašování ...",
4+
"logoutSuccessful": "Byli jste velmi odhlášeni!",
5+
"loginSuccessful": "Úspěšně přihlášen",
6+
"authenticationFailed": "Chyba ověření",
7+
"userInfoFailed": "Chyba při načítání uživatelských údajů",
8+
"loginFailed": "Přihlášení se nezdařilo"
9+
},
210
"ADDDATA": {
311
"CATALOGUE": {
412
"DESC": {
@@ -322,7 +330,9 @@
322330
"base": "Podkladová mapa",
323331
"thematic": "Tematická mapa",
324332
"contains": "obsahuje",
325-
"property": "Atribut"
333+
"property": "Atribut",
334+
"error": "Chyba",
335+
"success": "Úspěch"
326336
},
327337
"COMPOSITIONS": {
328338
"addByAddress": "Přidat kompozici z adresy",

projects/hslayers/assets/locales/en.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
{
2+
"AUTH": {
3+
"signingIn": "Signing in...",
4+
"logoutSuccessful": "You have been sucesfully logged out!",
5+
"loginSuccessful": "Successfully logged in",
6+
"authenticationFailed": "Authentication failed",
7+
"userInfoFailed": "Failed to retrieve user information",
8+
"loginFailed": "Login failed",
9+
"Login": "Log in",
10+
"Logout": "Log out"
11+
},
212
"ADDDATA": {
313
"CATALOGUE": {
414
"DESC": {
@@ -219,8 +229,6 @@
219229
"lineColor": "Line color",
220230
"lineWidth": "Line width",
221231
"loading": "Loading",
222-
"Login": "Log in",
223-
"Logout": "Log out",
224232
"mapExtentFilterMissing": "Please enable Filter by map extent checkbox to be able to sort data by Bounding box",
225233
"menu": "Menu",
226234
"metadata": "Metadata",
@@ -322,7 +330,9 @@
322330
"base": "Basemap",
323331
"thematic": "Thematic map",
324332
"contains": "contains",
325-
"property": "Property"
333+
"property": "Property",
334+
"error": "Error",
335+
"success": "Success"
326336
},
327337
"COMPOSITIONS": {
328338
"addByAddress": "Add composition by address",

projects/hslayers/assets/locales/sk.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
{
2+
"AUTH": {
3+
"signingIn": "Prihlasovanie ...",
4+
"logoutSuccessful": "Boli ste úspešne odhlásený!",
5+
"loginSuccessful": "Úspešne prihlásený",
6+
"authenticationFailed": "Chyba prihlásenia",
7+
"userInfoFailed": "Chyba pri načítaní údajov o užívateľovi",
8+
"loginFailed": "Prihlasovanie nebolo úspešné"
9+
},
210
"ADDDATA": {
311
"CATALOGUE": {
412
"DESC": {
@@ -322,7 +330,9 @@
322330
"base": "Podkladová mapa",
323331
"thematic": "Tematická mapa",
324332
"contains": "obsahuje",
325-
"property": "Atribút"
333+
"property": "Atribút",
334+
"error": "Chyba",
335+
"success": "Úspech"
326336
},
327337
"COMPOSITIONS": {
328338
"addByAddress": "Pridať kompozíciu z adresy",

projects/hslayers/common/dialog-set-permissions/set-permissions.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class HsSetPermissionsDialogComponent
5757

5858
ngOnInit(): void {
5959
// Can set permission for Layman endpoint only
60-
this.endpoint = this.hsCommonLaymanService.layman;
60+
this.endpoint = this.hsCommonLaymanService.layman();
6161
if (!this.data.selectedRecord?.access_rights || !this.endpoint) {
6262
this.close();
6363
return;
@@ -70,7 +70,7 @@ export class HsSetPermissionsDialogComponent
7070
* so it can be used for Layman access rights component
7171
*/
7272
parseCurrentPermissions(): void {
73-
const currentUser = this.endpoint.user;
73+
const currentUser = this.hsCommonLaymanService.user();
7474
let read: string[] = this.data.selectedRecord.access_rights.read;
7575
let write: string[] = this.data.selectedRecord.access_rights.write;
7676
if (read.includes('EVERYONE')) {
@@ -105,7 +105,7 @@ export class HsSetPermissionsDialogComponent
105105
const layerDesc: UpsertLayerObject = {
106106
name: this.data.selectedRecord.name,
107107
title: this.data.selectedRecord.title,
108-
workspace: this.endpoint.user,
108+
workspace: this.hsCommonLaymanService.user(),
109109
access_rights: this.access_rights,
110110
};
111111
response = await this.hsLaymanService.makeUpsertLayerRequest(

projects/hslayers/common/layman/access-rights/layman-access-rights.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
<div class="hs-save-map-users-list p-1 my-1" [class.collapsed]="collapsed">
5757
@for (user of allUsers | filter: userFilter; track user) {
5858
<div class="d-flex flex-row justify-content-between align-items-start p-1"
59-
[class.bg-primary-subtle]="user.username === this.endpoint.user">
59+
[class.bg-primary-subtle]="user.username === hsCommonLaymanService.user()">
6060
<span class="w-50">{{user.hslDisplayName}}</span>
6161
@for (type of rightsOptions; track type) {
6262
<label style="cursor: pointer;"><input class="me-2" type="checkbox" [name]="'rightTo'+type"
63-
[disabled]="user.username === this.endpoint.user" [(ngModel)]="user[type]"
63+
[disabled]="user.username === hsCommonLaymanService.user()" [(ngModel)]="user[type]"
6464
(change)="accessRightsChanged(type, user.username, $event)">{{ type | translateHs :'SAVECOMPOSITION.form'
6565
}}</label>
6666
}

projects/hslayers/common/layman/access-rights/layman-access-rights.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit {
6868
userSearch: string;
6969
endpoint: HsEndpoint;
7070
constructor(
71-
private hsCommonLaymanService: HsCommonLaymanService,
71+
public hsCommonLaymanService: HsCommonLaymanService,
7272
private $http: HttpClient,
7373
private hsLog: HsLogService,
7474
) {}
7575
async ngOnInit(): Promise<void> {
76-
this.endpoint = this.hsCommonLaymanService.layman;
76+
this.endpoint = this.hsCommonLaymanService.layman();
7777
this.defaultAccessRights = JSON.parse(JSON.stringify(this.access_rights));
7878
this.setUpAccessRights();
7979
}
@@ -113,7 +113,7 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit {
113113
this.allUsers.length / 2 >= this.allUsers.filter((u) => u[type]).length;
114114

115115
this.allUsers.forEach((user) => {
116-
const isCurrentUser = user.name === this.endpoint.user;
116+
const isCurrentUser = user.name === this.hsCommonLaymanService.user();
117117
//Value for current user won't be changed
118118
user[type] = isCurrentUser ? user[type] : value;
119119
//In case write permission is being added make sure read is granted as well
@@ -199,7 +199,7 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit {
199199
: [
200200
...this.allRoles,
201201
//Add current user as he has got to retain both read and write rights
202-
{name: this.endpoint.user, read: true, write: true},
202+
{name: this.hsCommonLaymanService.user(), read: true, write: true},
203203
];
204204
this.access_rights[`access_rights.${type}`] = source
205205
.reduce((acc, curr) => {
@@ -291,7 +291,7 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit {
291291
* Get user roles
292292
*/
293293
async getRoles(access_rights?: AccessRightsModel): Promise<void> {
294-
if (this.endpoint?.authenticated) {
294+
if (this.hsCommonLaymanService.isAuthenticated()) {
295295
const url = `${this.endpoint.url}/rest/roles`;
296296

297297
access_rights ??= this.access_rights;
@@ -390,7 +390,7 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit {
390390
* Get all registered users from Layman's endpoint service
391391
*/
392392
async getAllUsers(access_rights?: AccessRightsModel): Promise<void> {
393-
if (this.endpoint?.authenticated) {
393+
if (this.hsCommonLaymanService.isAuthenticated()) {
394394
access_rights ??= this.access_rights;
395395
const read = access_rights[AccessRights.READ].split(',');
396396
const write = access_rights[AccessRights.WRITE].split(',');
@@ -403,7 +403,8 @@ export class HsCommonLaymanAccessRightsComponent implements OnInit {
403403
),
404404
map((res: LaymanUser[]) => {
405405
return res.map((user) => {
406-
const isCurrentUser = user.username === this.endpoint.user;
406+
const isCurrentUser =
407+
user.username === this.hsCommonLaymanService.user();
407408
const laymanUser: LaymanUser = {
408409
...user,
409410
name: user.username,
Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,53 @@
1-
@if ((inAppLogin | async) && endpoint) {
2-
<div style="margin-left: 1em; float: right; ">
3-
@if (!isAuthenticated() && sameDomain()) {
4-
<a class="btn btn-primary" style="border-radius: 0.25rem; color: #fff;" (click)="login();">
5-
<!-- TODO: Remove function call from template -->
6-
{{'COMPOSITIONS.loginToCatalogue' | translateHs }}
7-
</a>
8-
}
9-
@if (!isAuthenticated() && !sameDomain()) {
10-
<a class="btn btn-primary" style="border-radius: 0.25rem; color: #fff;" (click)="login();" [href]="authUrl()"
11-
target="_blank">
12-
<!-- TODO: Remove function call from template -->
13-
{{'COMPOSITIONS.loginToCatalogue' | translateHs }}
14-
</a>
15-
}
16-
@if (isAuthenticated()) {
17-
<a class="btn btn-primary text-truncate"
18-
style="border-radius: 0.25rem; color: #fff; max-width:25ch; white-space:nowrap" (click)="logout()">{{'COMMON.Logout'
19-
| translateHs }}
20-
{{endpoint.user}}</a>
21-
}<!-- TODO: Remove function call from template -->
22-
</div>
23-
}
1+
@if ((inAppLogin | async) && hsCommonLaymanService.layman()) {
2+
<div class="user-auth-container ms-3 float-end">
3+
@if (!hsCommonLaymanService.isAuthenticated()) {
4+
@if (hsCommonLaymanService.isAuthenticating()) {
5+
<button
6+
class="btn btn-outline-primary d-flex align-items-center"
7+
type="button"
8+
disabled>
9+
<span class="spinner-border spinner-border-sm me-2" role="status" aria-hidden="true"></span>
10+
<span>{{'AUTH.signingIn' | translateHs }}</span>
11+
</button>
12+
} @else {
13+
<button
14+
class="btn btn-outline-primary d-flex align-items-center"
15+
(click)="login()"
16+
type="button">
17+
<i class="fa-solid fa-sign-in-alt me-2"></i>
18+
{{'COMPOSITIONS.loginToCatalogue' | translateHs }}
19+
</button>
20+
}
21+
} @else {
22+
<div ngbDropdown placement="bottom-end" class="user-dropdown">
23+
<button
24+
class="btn btn-primary d-flex align-items-center"
25+
ngbDropdownToggle>
26+
<div class="user-avatar me-2">
27+
<i class="fa-solid fa-user"></i>
28+
</div>
29+
<span class="text-truncate" style="max-width: 8rem;">{{hsCommonLaymanService.user()}}</span>
30+
</button>
31+
<div ngbDropdownMenu class="user-dropdown-menu p-0">
32+
<div class="user-header p-3 bg-light border-bottom">
33+
<div class="d-flex align-items-center">
34+
<div class="user-avatar-large me-3">
35+
<i class="fa-solid fa-user"></i>
36+
</div>
37+
<div>
38+
<h6 class="mb-0">{{hsCommonLaymanService.user()}}</h6>
39+
<small class="text-muted">Logged in</small>
40+
</div>
41+
</div>
42+
</div>
43+
<div class="p-2">
44+
<button ngbDropdownItem (click)="logout()" class="text-danger">
45+
<i class="fa-solid fa-sign-out-alt me-2"></i>
46+
{{'AUTH.Logout' | translateHs }}
47+
</button>
48+
</div>
49+
</div>
50+
</div>
51+
}
52+
</div>
53+
}

0 commit comments

Comments
 (0)