frontend: Replace global preferences with security preferences in context model and service

This commit is contained in:
juancarmore 2025-03-28 18:56:05 +01:00
parent 2d82d6a96d
commit de9caec62a
3 changed files with 26 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import { import {
GlobalPreferences,
OpenViduMeetPermissions, OpenViduMeetPermissions,
ParticipantRole ParticipantRole,
SecurityPreferencesDTO
} from 'projects/shared-meet-components/src/public-api'; } from 'projects/shared-meet-components/src/public-api';
export interface ContextData { export interface ContextData {
@ -13,7 +13,7 @@ export interface ContextData {
participantPermissions: OpenViduMeetPermissions; participantPermissions: OpenViduMeetPermissions;
mode: ApplicationMode; mode: ApplicationMode;
edition: Edition; edition: Edition;
globalPreferences?: GlobalPreferences; securityPreferences?: SecurityPreferencesDTO;
leaveRedirectUrl: string; leaveRedirectUrl: string;
parentDomain: string; parentDomain: string;
version: string; version: string;

View File

@ -25,7 +25,7 @@ export class ContextService {
}, },
mode: ApplicationMode.STANDALONE, mode: ApplicationMode.STANDALONE,
edition: Edition.CE, edition: Edition.CE,
globalPreferences: undefined, securityPreferences: undefined,
leaveRedirectUrl: '', leaveRedirectUrl: '',
parentDomain: '', parentDomain: '',
version: '', version: '',
@ -167,18 +167,18 @@ export class ContextService {
} }
async canUsersCreateRooms(): Promise<boolean> { async canUsersCreateRooms(): Promise<boolean> {
await this.getGlobalPreferences(); await this.getSecurityPreferences();
return this.context.globalPreferences!.securityPreferences.roomCreationPolicy.allowRoomCreation; return this.context.securityPreferences!.roomCreationPolicy.allowRoomCreation;
} }
async isAuthRequiredToCreateRooms(): Promise<boolean> { async isAuthRequiredToCreateRooms(): Promise<boolean> {
await this.getGlobalPreferences(); await this.getSecurityPreferences();
return this.context.globalPreferences!.securityPreferences.roomCreationPolicy.requireAuthentication; return this.context.securityPreferences!.roomCreationPolicy.requireAuthentication;
} }
async getAuthModeToEnterRoom(): Promise<AuthMode> { async getAuthModeToEnterRoom(): Promise<AuthMode> {
await this.getGlobalPreferences(); await this.getSecurityPreferences();
return this.context.globalPreferences!.securityPreferences.authentication.authMode; return this.context.securityPreferences!.authentication.authMode;
} }
private getValidDecodedToken(token: string) { private getValidDecodedToken(token: string) {
@ -204,14 +204,13 @@ export class ContextService {
} }
} }
private async getGlobalPreferences() { private async getSecurityPreferences() {
if (!this.context.globalPreferences) { if (!this.context.securityPreferences) {
try { try {
// TODO: Retrieve only publicly available global preferences this.context.securityPreferences = await this.httpService.getSecurityPreferences();
this.context.globalPreferences = await this.httpService.getGlobalPreferences();
} catch (error) { } catch (error) {
this.log.e('Error getting global preferences', error); this.log.e('Error getting security preferences', error);
throw new Error('Error getting global preferences'); throw new Error('Error getting security preferences');
} }
} }
} }

View File

@ -1,7 +1,14 @@
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { OpenViduMeetRoom, OpenViduMeetRoomOptions } from 'projects/shared-meet-components/src/lib/typings/ce/room'; import { OpenViduMeetRoom, OpenViduMeetRoomOptions } from 'projects/shared-meet-components/src/lib/typings/ce/room';
import { GlobalPreferences, ParticipantRole, RoomPreferences, TokenOptions, User } from '@lib/typings/ce'; import {
GlobalPreferences,
ParticipantRole,
RoomPreferences,
SecurityPreferencesDTO,
TokenOptions,
User
} from '@lib/typings/ce';
import { RecordingInfo, Room } from 'openvidu-components-angular'; import { RecordingInfo, Room } from 'openvidu-components-angular';
import { lastValueFrom } from 'rxjs'; import { lastValueFrom } from 'rxjs';
@ -61,12 +68,12 @@ export class HttpService {
} }
/** /**
* Retrieves the global preferences. * Retrieves security preferences.
* *
* @returns {Promise<GlobalPreferences>} A promise that resolves to the global preferences. * @returns {Promise<GlobalPreferences>} A promise that resolves to the global preferences.
*/ */
getGlobalPreferences(): Promise<GlobalPreferences> { getSecurityPreferences(): Promise<SecurityPreferencesDTO> {
return this.getRequest(`${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/preferences`); return this.getRequest(`${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/preferences/security`);
} }
/** /**