diff --git a/src/server/accessors/LivechatRead.ts b/src/server/accessors/LivechatRead.ts index 0b4c7425d..7f4734987 100644 --- a/src/server/accessors/LivechatRead.ts +++ b/src/server/accessors/LivechatRead.ts @@ -13,11 +13,11 @@ export class LivechatRead implements ILivechatRead { public isOnline(departmentId?: string): boolean { console.warn('The `LivechatRead.isOnline` method is deprecated and won\'t behave as intended. Please use `LivechatRead.isOnlineAsync` instead'); - return this.livechatBridge.isOnline(departmentId); + return this.livechatBridge.isOnline(departmentId, this.appId); } public isOnlineAsync(departmentId?: string): Promise { - return this.livechatBridge.isOnlineAsync(departmentId); + return this.livechatBridge.isOnlineAsync(departmentId, this.appId); } public getLivechatRooms(visitor: IVisitor, departmentId?: string): Promise> { diff --git a/src/server/bridges/ILivechatBridge.ts b/src/server/bridges/ILivechatBridge.ts index 905dc8de3..33a21762a 100644 --- a/src/server/bridges/ILivechatBridge.ts +++ b/src/server/bridges/ILivechatBridge.ts @@ -6,8 +6,8 @@ export interface ILivechatBridge { * @deprecated please use the `isOnlineAsync` method instead. * In the next major, this method will be `async` */ - isOnline(departmentId?: string): boolean; - isOnlineAsync(departmentId?: string): Promise; + isOnline(departmentId?: string, appId?: string): boolean; + isOnlineAsync(departmentId?: string, appId?: string): Promise; createMessage(message: ILivechatMessage, appId: string): Promise; getMessageById(messageId: string, appId: string): Promise; updateMessage(message: ILivechatMessage, appId: string): Promise; diff --git a/src/server/permissions/checkers/AppLivechatBridge.ts b/src/server/permissions/checkers/AppLivechatBridge.ts index d661d2a2d..445fbac3e 100644 --- a/src/server/permissions/checkers/AppLivechatBridge.ts +++ b/src/server/permissions/checkers/AppLivechatBridge.ts @@ -5,6 +5,22 @@ import { AppPermissionManager } from '../../managers/AppPermissionManager'; import { AppPermissions } from '../AppPermissions'; export const AppLivechatBridge = { + isOnline(departmentId?: string, appId?: string): void { + if (!AppPermissionManager.hasPermission(appId, AppPermissions['livechat-status'].read)) { + throw new PermissionDeniedError({ + appId, + missingPermissions: [AppPermissions['livechat-status'].read], + }); + } + }, + isOnlineAsync(departmentId?: string, appId?: string): void { + if (!AppPermissionManager.hasPermission(appId, AppPermissions['livechat-status'].read)) { + throw new PermissionDeniedError({ + appId, + missingPermissions: [AppPermissions['livechat-status'].read], + }); + } + }, updateMessage(message: ILivechatMessage, appId: string): void { if (!AppPermissionManager.hasPermission(appId, AppPermissions['livechat-message'].write)) { throw new PermissionDeniedError({ @@ -13,6 +29,14 @@ export const AppLivechatBridge = { }); } }, + createMessage(message: ILivechatMessage, appId: string): void { + if (!AppPermissionManager.hasPermission(appId, AppPermissions['livechat-message'].write)) { + throw new PermissionDeniedError({ + appId, + missingPermissions: [AppPermissions['livechat-message'].write], + }); + } + }, createVisitor(visitor: IVisitor, appId: string): void { if (!AppPermissionManager.hasPermission(appId, AppPermissions['livechat-visitor'].write)) { throw new PermissionDeniedError({