From 3ad821fda48e3dd5b803f28ebb0dff8e4ec2c9be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Mau=C3=9F?= <lukas.mauss@mni.thm.de> Date: Mon, 6 Jan 2020 15:47:25 +0100 Subject: [PATCH] Set and check access for participants which access directly via url --- .../room-creator-page/room-creator-page.component.ts | 6 ++---- .../room-moderator-page.component.ts | 7 ++----- .../room-participant-page.component.ts | 8 +++++--- .../components/shared/room-page/room-page.component.ts | 6 +----- src/app/services/http/authentication.service.ts | 10 ++++++---- 5 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/app/components/creator/room-creator-page/room-creator-page.component.ts b/src/app/components/creator/room-creator-page/room-creator-page.component.ts index 12466193f..fd8716845 100644 --- a/src/app/components/creator/room-creator-page/room-creator-page.component.ts +++ b/src/app/components/creator/room-creator-page/room-creator-page.component.ts @@ -21,7 +21,6 @@ import { LiveAnnouncer } from '@angular/cdk/a11y'; import { EventService } from '../../../services/util/event.service'; import { KeyboardUtils } from '../../../utils/keyboard'; import { KeyboardKey } from '../../../utils/keyboard/keys'; -import { AuthenticationService } from '../../../services/http/authentication.service'; @Component({ selector: 'app-room-creator-page', @@ -49,9 +48,8 @@ export class RoomCreatorPageComponent extends RoomPageComponent implements OnIni protected commentService: CommentService, private liveAnnouncer: LiveAnnouncer, private _r: Renderer2, - public eventService: EventService, - protected authenticationService: AuthenticationService) { - super(roomService, route, location, wsCommentService, commentService, eventService, authenticationService); + public eventService: EventService) { + super(roomService, route, location, wsCommentService, commentService, eventService); langService.langEmitter.subscribe(lang => translateService.use(lang)); } diff --git a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts index 45e302e80..89bde2ce3 100644 --- a/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts +++ b/src/app/components/moderator/room-moderator-page/room-moderator-page.component.ts @@ -14,7 +14,6 @@ import { LiveAnnouncer } from '@angular/cdk/a11y'; import { EventService } from '../../../services/util/event.service'; import { KeyboardUtils } from '../../../utils/keyboard'; import { KeyboardKey } from '../../../utils/keyboard/keys'; -import { AuthenticationService } from '../../../services/http/authentication.service'; @Component({ selector: 'app-room-moderator-page', @@ -39,15 +38,13 @@ export class RoomModeratorPageComponent extends RoomPageComponent implements OnI protected notification: NotificationService, public eventService: EventService, private liveAnnouncer: LiveAnnouncer, - private _r: Renderer2, - protected authenticationService: AuthenticationService) { - super(roomService, route, location, wsCommentService, commentService, eventService, authenticationService); + private _r: Renderer2) { + super(roomService, route, location, wsCommentService, commentService, eventService); langService.langEmitter.subscribe(lang => translateService.use(lang)); } initializeRoom(id: string): void { this.roomService.getRoomByShortId(id).subscribe(room => { - this.authenticationService.checkAccess(id); this.room = room; this.isLoading = false; if (this.room.extensions && this.room.extensions['comments']) { diff --git a/src/app/components/participant/room-participant-page/room-participant-page.component.ts b/src/app/components/participant/room-participant-page/room-participant-page.component.ts index a2010a249..db969f9fc 100644 --- a/src/app/components/participant/room-participant-page/room-participant-page.component.ts +++ b/src/app/components/participant/room-participant-page/room-participant-page.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, OnDestroy, Renderer2, AfterContentInit } from '@angular/core'; +import { AfterContentInit, Component, OnDestroy, OnInit, Renderer2 } from '@angular/core'; import { Room } from '../../../models/room'; import { User } from '../../../models/user'; import { UserRole } from '../../../models/user-roles.enum'; @@ -39,7 +39,7 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O private liveAnnouncer: LiveAnnouncer, private _r: Renderer2, public eventService: EventService) { - super(roomService, route, location, wsCommentService, commentService, eventService, authenticationService); + super(roomService, route, location, wsCommentService, commentService, eventService); langService.langEmitter.subscribe(lang => translateService.use(lang)); } @@ -83,9 +83,11 @@ export class RoomParticipantPageComponent extends RoomPageComponent implements O afterRoomLoadHook() { this.authenticationService.watchUser.subscribe( user => this.user = user); if (!this.user) { - this.authenticationService.guestLogin(UserRole.PARTICIPANT).subscribe(guestUser => { + this.authenticationService.guestLogin(UserRole.PARTICIPANT).subscribe(() => { this.roomService.addToHistory(this.room.id); }); } + this.authenticationService.setAccess(this.room.shortId, UserRole.PARTICIPANT); + this.authenticationService.checkAccess(this.room.shortId); } } diff --git a/src/app/components/shared/room-page/room-page.component.ts b/src/app/components/shared/room-page/room-page.component.ts index 94d6de3dd..9385a1cc9 100644 --- a/src/app/components/shared/room-page/room-page.component.ts +++ b/src/app/components/shared/room-page/room-page.component.ts @@ -8,8 +8,6 @@ import { CommentService } from '../../../services/http/comment.service'; import { EventService } from '../../../services/util/event.service'; import { Message, IMessage } from '@stomp/stompjs'; import { Observable, Subscription } from 'rxjs'; -import { AuthenticationService } from '../../../services/http/authentication.service'; -import { UserRole } from '../../../models/user-roles.enum'; @Component({ selector: 'app-room-page', @@ -30,8 +28,7 @@ export class RoomPageComponent implements OnInit, OnDestroy { protected location: Location, protected wsCommentService: WsCommentServiceService, protected commentService: CommentService, - protected eventService: EventService, - protected authenticationService: AuthenticationService + protected eventService: EventService ) { } @@ -55,7 +52,6 @@ export class RoomPageComponent implements OnInit, OnDestroy { initializeRoom(id: string): void { this.roomService.getRoomByShortId(id).subscribe(room => { - this.authenticationService.checkAccess(id); this.room = room; this.isLoading = false; if (this.room.extensions && this.room.extensions['comments']) { diff --git a/src/app/services/http/authentication.service.ts b/src/app/services/http/authentication.service.ts index 71552f3b7..b17d50f37 100644 --- a/src/app/services/http/authentication.service.ts +++ b/src/app/services/http/authentication.service.ts @@ -1,13 +1,12 @@ import { catchError, map, tap } from 'rxjs/operators'; import { Injectable } from '@angular/core'; import { User } from '../../models/user'; -import { Observable , of , BehaviorSubject } from 'rxjs'; +import { BehaviorSubject, Observable, of } from 'rxjs'; import { UserRole } from '../../models/user-roles.enum'; import { DataStoreService } from '../util/data-store.service'; import { EventService } from '../util/event.service'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { ClientAuthentication } from '../../models/client-authentication'; -import { AuthProvider } from '../../models/auth-provider'; import { BaseHttpService } from './base-http.service'; @Injectable() @@ -255,7 +254,10 @@ export class AuthenticationService extends BaseHttpService { hasAccess(shortId: string, role: UserRole): boolean { const usersRole = this.roomAccess.get(shortId); - return (usersRole && (usersRole >= role)); + if (usersRole === undefined) { + return false; + } + return usersRole >= role; } setAccess(shortId: string, role: UserRole): void { @@ -276,7 +278,7 @@ export class AuthenticationService extends BaseHttpService { this.assignRole(UserRole.CREATOR); } else if (this.hasAccess(shortId, UserRole.EXECUTIVE_MODERATOR)) { this.assignRole(UserRole.EXECUTIVE_MODERATOR); - } else { + } else if (this.hasAccess(shortId, UserRole.PARTICIPANT)) { this.assignRole(UserRole.PARTICIPANT); } } -- GitLab