Skip to content

Commit 41614ec

Browse files
committed
feat: use token roles
1 parent f581bf2 commit 41614ec

File tree

65 files changed

+320
-779
lines changed

Some content is hidden

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

65 files changed

+320
-779
lines changed

src/app/account/account.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export class AccountComponent {
3737
readonly #forumsClient = inject(ForumsClient);
3838

3939
protected readonly items$: Observable<SidebarItem[]> = combineLatest([
40-
this.#auth.getUser$(),
41-
this.#auth.getUser$().pipe(
42-
switchMap((user) => {
43-
if (!user) {
40+
this.#auth.user$,
41+
this.#auth.authenticated$.pipe(
42+
switchMap((authenticated) => {
43+
if (!authenticated) {
4444
return of(null);
4545
}
4646
return this.#forumsClient.getUserSummary(new Empty());

src/app/account/contacts/contacts.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {LanguageService} from '@services/language';
1010
import {PageEnvService} from '@services/page-env.service';
1111
import {TimeAgoPipe} from '@utils/time-ago.pipe';
1212
import Keycloak from 'keycloak-js';
13-
import {BehaviorSubject, EMPTY, Observable} from 'rxjs';
13+
import {BehaviorSubject, EMPTY, Observable, of} from 'rxjs';
1414
import {catchError, map, switchMap} from 'rxjs/operators';
1515

1616
import {ToastsService} from '../../toasts/toasts.service';
@@ -32,16 +32,16 @@ export class AccountContactsComponent implements OnInit {
3232

3333
readonly #reload$ = new BehaviorSubject<void>(void 0);
3434

35-
protected readonly items$: Observable<Contact[]> = this.#auth.getUser$().pipe(
36-
map((user) => {
37-
if (!user) {
35+
protected readonly items$: Observable<Contact[]> = this.#auth.authenticated$.pipe(
36+
switchMap((authenticated) => {
37+
if (!authenticated) {
3838
this.#keycloak.login({
3939
locale: this.#languageService.language,
4040
redirectUri: window.location.href,
4141
});
4242
return EMPTY;
4343
}
44-
return user;
44+
return of(authenticated);
4545
}),
4646
switchMap(() => this.#reload$),
4747
switchMap(() => this.#contactsService.getContacts$()),

src/app/account/delete/delete.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ export class AccountDeleteComponent implements OnInit {
3636
}
3737

3838
protected submit() {
39-
this.#auth
40-
.getUser$()
39+
this.#auth.user$
4140
.pipe(
4241
switchMap((user) =>
4342
user
@@ -59,7 +58,7 @@ export class AccountDeleteComponent implements OnInit {
5958
}
6059
},
6160
next: () => {
62-
this.#auth.signOut$();
61+
this.#auth.signOut$().subscribe();
6362
this.#router.navigate(['/account/delete/deleted']);
6463
},
6564
});

src/app/account/inbox-pictures/inbox-pictures.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class AccountInboxPicturesComponent implements OnInit {
3232
distinctUntilChanged(),
3333
debounceTime(10),
3434
),
35-
this.#auth.getUser$(),
35+
this.#auth.user$,
3636
]).pipe(
3737
switchMap(([page, user]) =>
3838
user

src/app/account/profile/profile.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ export class AccountProfileComponent implements OnDestroy, OnInit {
6363
ngOnInit(): void {
6464
setTimeout(() => this.#pageEnv.set({pageId: 129}), 0);
6565

66-
this.#sub = this.#auth
67-
.getUser$()
66+
this.#sub = this.#auth.user$
6867
.pipe(
6968
switchMap((user) => {
7069
if (!user) {

src/app/account/specs-conflicts/specs-conflicts.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ <h1 i18n id="header">Conflicts</h1>
33
</div>
44

55
@if (user$ | async; as user) {
6-
@if (user.specsWeight !== null) {
6+
@if (user.specsWeight !== 0) {
77
<p class="float-end"><ng-container i18n>Weight</ng-container>: {{ user.specsWeight.toFixed(2) }}</p>
88
}
99
} @else {

src/app/account/specs-conflicts/specs-conflicts.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class AccountSpecsConflictsComponent implements OnInit {
8181
map((filter) => mapFilter(filter)),
8282
);
8383

84-
protected readonly user$: Observable<APIUser | null> = this.auth.getUser$();
84+
protected readonly user$: Observable<APIUser | null> = this.auth.user$;
8585

8686
readonly #itemsCache = new Map<string, Observable<APIItem>>();
8787

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,32 @@
11
import {inject, Injectable} from '@angular/core';
22
import {GetMessagesRequest, ModeratorAttention} from '@grpc/spec.pb';
33
import {CommentsClient} from '@grpc/spec.pbsc';
4-
import {ACLService, Privilege, Resource} from '@services/acl.service';
4+
import {AuthService, Role} from '@services/auth.service';
55
import {Observable, of} from 'rxjs';
66
import {map, shareReplay, switchMap} from 'rxjs/operators';
77

88
@Injectable({
99
providedIn: 'root',
1010
})
1111
export class APICommentsService {
12-
readonly #acl = inject(ACLService);
12+
readonly #auth = inject(AuthService);
1313
readonly #commentsClient = inject(CommentsClient);
1414

15-
public readonly attentionCommentsCount$: Observable<null | number> = this.#acl
16-
.isAllowed$(Resource.GLOBAL, Privilege.MODERATE)
17-
.pipe(
18-
switchMap((isModer) => {
19-
if (!isModer) {
20-
return of(null);
21-
}
15+
public readonly attentionCommentsCount$: Observable<null | number> = this.#auth.hasRole$(Role.MODER).pipe(
16+
switchMap((isModer) => {
17+
if (!isModer) {
18+
return of(null);
19+
}
2220

23-
return this.#commentsClient
24-
.getMessages(
25-
new GetMessagesRequest({
26-
limit: 0,
27-
moderatorAttention: ModeratorAttention.REQUIRED,
28-
}),
29-
)
30-
.pipe(map((response) => (response.paginator ? response.paginator.totalItemCount : null)));
31-
}),
32-
shareReplay({bufferSize: 1, refCount: false}),
33-
);
21+
return this.#commentsClient
22+
.getMessages(
23+
new GetMessagesRequest({
24+
limit: 0,
25+
moderatorAttention: ModeratorAttention.REQUIRED,
26+
}),
27+
)
28+
.pipe(map((response) => (response.paginator ? response.paginator.totalItemCount : null)));
29+
}),
30+
shareReplay({bufferSize: 1, refCount: false}),
31+
);
3432
}

src/app/api/picture-moder-vote-template/picture-moder-vote-template.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class APIPictureModerVoteTemplateService {
2121
readonly #change$ = new BehaviorSubject<void>(void 0);
2222

2323
public getTemplates$(): Observable<ModerVoteTemplate[]> {
24-
return combineLatest([this.#change$, this.#auth.getUser$()]).pipe(
24+
return combineLatest([this.#change$, this.#auth.authenticated$]).pipe(
2525
switchMap(() => this.#pictures.getModerVoteTemplates(new Empty({}))),
2626
map((response) => (response.items ? response.items : [])),
2727
shareReplay({bufferSize: 1, refCount: false}),

src/app/app.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
</form>
7878
}
7979
<ul class="nav navbar-nav navbar-right">
80-
@if (user$ | async) {
80+
@if (authenticated$ | async) {
8181
<li class="nav-item">
8282
<a class="nav-link" routerLink="/account/messages" routerLinkActive="active">
8383
<i class="bi bi-chat-fill" aria-hidden="true"></i>
@@ -120,7 +120,7 @@
120120
<i class="bi bi-people-fill" aria-hidden="true"></i>
121121
<ng-container i18n>Who is online?</ng-container>
122122
</a>
123-
@if (user$ | async) {
123+
@if (authenticated$ | async) {
124124
<a routerLink="/account/contacts" class="dropdown-item" routerLinkActive="active">
125125
<i class="bi bi-people-fill" aria-hidden="true"></i>
126126
<ng-container i18n>Contacts</ng-container>
@@ -134,7 +134,7 @@
134134
<i class="bi bi-info" aria-hidden="true"></i>
135135
<ng-container i18n>About us</ng-container>
136136
</a>
137-
@if (user$ | async) {
137+
@if (authenticated$ | async) {
138138
<a href="#" (click)="signOut()" class="dropdown-item">
139139
<i class="bi bi-box-arrow-right" aria-hidden="true"></i>
140140
<ng-container i18n>Sign out</ng-container>

0 commit comments

Comments
 (0)