backend: update security preferences to allow optional requireAuthentication; enhance validation for room creation and recording preferences
This commit is contained in:
parent
9ea7bac71c
commit
44fbb25841
@ -15,7 +15,13 @@ export const updateSecurityPreferences = async (req: Request, res: Response) =>
|
|||||||
const globalPreferences = await globalPrefService.getGlobalPreferences();
|
const globalPreferences = await globalPrefService.getGlobalPreferences();
|
||||||
|
|
||||||
if (securityPreferences.roomCreationPolicy) {
|
if (securityPreferences.roomCreationPolicy) {
|
||||||
globalPreferences.securityPreferences.roomCreationPolicy = securityPreferences.roomCreationPolicy;
|
globalPreferences.securityPreferences.roomCreationPolicy = {
|
||||||
|
allowRoomCreation: securityPreferences.roomCreationPolicy.allowRoomCreation,
|
||||||
|
requireAuthentication:
|
||||||
|
securityPreferences.roomCreationPolicy.requireAuthentication === undefined
|
||||||
|
? globalPreferences.securityPreferences.roomCreationPolicy.requireAuthentication
|
||||||
|
: securityPreferences.roomCreationPolicy.requireAuthentication
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (securityPreferences.authentication) {
|
if (securityPreferences.authentication) {
|
||||||
|
|||||||
@ -116,7 +116,7 @@ export const withCanDeleteRecordingsPermission = async (req: Request, res: Respo
|
|||||||
export const configureRecordingMediaAuth = async (req: Request, res: Response, next: NextFunction) => {
|
export const configureRecordingMediaAuth = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const storageService = container.get(MeetStorageService);
|
const storageService = container.get(MeetStorageService);
|
||||||
|
|
||||||
let recordingAccess: MeetRecordingAccess;
|
let recordingAccess: MeetRecordingAccess | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const roomId = extractRoomIdFromRequest(req);
|
const roomId = extractRoomIdFromRequest(req);
|
||||||
|
|||||||
@ -47,10 +47,21 @@ const AuthenticationPreferencesDTOSchema: z.ZodType<AuthenticationPreferencesDTO
|
|||||||
method: ValidAuthMethodDTOSchema
|
method: ValidAuthMethodDTOSchema
|
||||||
});
|
});
|
||||||
|
|
||||||
const RoomCreationPolicySchema: z.ZodType<RoomCreationPolicy> = z.object({
|
const RoomCreationPolicySchema: z.ZodType<RoomCreationPolicy> = z
|
||||||
allowRoomCreation: z.boolean(),
|
.object({
|
||||||
requireAuthentication: z.boolean()
|
allowRoomCreation: z.boolean(),
|
||||||
});
|
requireAuthentication: z.boolean().optional()
|
||||||
|
})
|
||||||
|
.refine(
|
||||||
|
(data) => {
|
||||||
|
// If allowRoomCreation is true, requireAuthentication must be provided
|
||||||
|
return !data.allowRoomCreation || data.requireAuthentication !== undefined;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: 'requireAuthentication is required when allowRoomCreation is true',
|
||||||
|
path: ['requireAuthentication']
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const UpdateSecurityPreferencesDTOSchema: z.ZodType<UpdateSecurityPreferencesDTO> = z
|
const UpdateSecurityPreferencesDTOSchema: z.ZodType<UpdateSecurityPreferencesDTO> = z
|
||||||
.object({
|
.object({
|
||||||
|
|||||||
@ -64,10 +64,21 @@ const RecordingAccessSchema: z.ZodType<MeetRecordingAccess> = z.enum([
|
|||||||
MeetRecordingAccess.PUBLIC
|
MeetRecordingAccess.PUBLIC
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const RecordingPreferencesSchema: z.ZodType<MeetRecordingPreferences> = z.object({
|
const RecordingPreferencesSchema: z.ZodType<MeetRecordingPreferences> = z
|
||||||
enabled: z.boolean(),
|
.object({
|
||||||
allowAccessTo: RecordingAccessSchema
|
enabled: z.boolean(),
|
||||||
});
|
allowAccessTo: RecordingAccessSchema.optional()
|
||||||
|
})
|
||||||
|
.refine(
|
||||||
|
(data) => {
|
||||||
|
// If recording is enabled, allowAccessTo must be provided
|
||||||
|
return !data.enabled || data.allowAccessTo !== undefined;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
message: 'allowAccessTo is required when recording is enabled',
|
||||||
|
path: ['allowAccessTo']
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const ChatPreferencesSchema: z.ZodType<MeetChatPreferences> = z.object({
|
const ChatPreferencesSchema: z.ZodType<MeetChatPreferences> = z.object({
|
||||||
enabled: z.boolean()
|
enabled: z.boolean()
|
||||||
|
|||||||
@ -20,7 +20,7 @@ import { allowAnonymous, apiKeyValidator, tokenAndRoleValidator, withAuth } from
|
|||||||
export const configureCreateRoomAuth = async (req: Request, res: Response, next: NextFunction) => {
|
export const configureCreateRoomAuth = async (req: Request, res: Response, next: NextFunction) => {
|
||||||
const globalPrefService = container.get(MeetStorageService);
|
const globalPrefService = container.get(MeetStorageService);
|
||||||
let allowRoomCreation: boolean;
|
let allowRoomCreation: boolean;
|
||||||
let requireAuthentication: boolean;
|
let requireAuthentication: boolean | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { securityPreferences } = await globalPrefService.getGlobalPreferences();
|
const { securityPreferences } = await globalPrefService.getGlobalPreferences();
|
||||||
@ -104,7 +104,7 @@ export const configureRecordingTokenAuth = async (req: Request, res: Response, n
|
|||||||
|
|
||||||
const recordingAccess = room.preferences!.recordingPreferences.allowAccessTo;
|
const recordingAccess = room.preferences!.recordingPreferences.allowAccessTo;
|
||||||
|
|
||||||
if (recordingAccess === MeetRecordingAccess.ADMIN) {
|
if (!recordingAccess || recordingAccess === MeetRecordingAccess.ADMIN) {
|
||||||
// Deny request if the room is configured to allow access to recordings only for admins
|
// Deny request if the room is configured to allow access to recordings only for admins
|
||||||
throw errorInsufficientPermissions();
|
throw errorInsufficientPermissions();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -173,7 +173,8 @@ export class ContextService {
|
|||||||
|
|
||||||
async isAuthRequiredToCreateRooms(): Promise<boolean> {
|
async isAuthRequiredToCreateRooms(): Promise<boolean> {
|
||||||
await this.getSecurityPreferences();
|
await this.getSecurityPreferences();
|
||||||
return this.context.securityPreferences!.roomCreationPolicy.requireAuthentication;
|
const requireAuthentication = this.context.securityPreferences!.roomCreationPolicy.requireAuthentication;
|
||||||
|
return requireAuthentication !== undefined && requireAuthentication;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAuthModeToEnterRoom(): Promise<AuthMode> {
|
async getAuthModeToEnterRoom(): Promise<AuthMode> {
|
||||||
|
|||||||
@ -24,7 +24,7 @@ export interface SecurityPreferences {
|
|||||||
|
|
||||||
export interface RoomCreationPolicy {
|
export interface RoomCreationPolicy {
|
||||||
allowRoomCreation: boolean;
|
allowRoomCreation: boolean;
|
||||||
requireAuthentication: boolean;
|
requireAuthentication?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DTOs
|
// DTOs
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export interface MeetRoomPreferences {
|
|||||||
*/
|
*/
|
||||||
export interface MeetRecordingPreferences {
|
export interface MeetRecordingPreferences {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
allowAccessTo: MeetRecordingAccess;
|
allowAccessTo?: MeetRecordingAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum MeetRecordingAccess {
|
export const enum MeetRecordingAccess {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user