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 12466193f44a7ab13ce52bdc9da0e05fb21454e4..fd87168452da96c285cab523ed11c112e53be5bb 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 45e302e8074b4581c3cfe752f4bd4693048cfae6..89bde2ce3a88eac86a61a6dff2f784bc1c547fbd 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 a2010a2492db53bde19d0788f59f94ddf7181290..db969f9fca0ba171a67eed69bca2265579fb073c 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 94d6de3dd38ec89d81f6c13d16051c105bede881..9385a1cc90c1d9ba7e07a2f9858d66fc1754f172 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 71552f3b78eef5fcdd8ad93ec5f9fbd064b80b46..b17d50f377e57caa350000d6e089011b5c61653b 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); } }