Skip to content

Commit

Permalink
Refactor UserAuthorization and Realtime; update mock implementation a…
Browse files Browse the repository at this point in the history
…nd add validation for tenantId
  • Loading branch information
simlarsen committed Sep 27, 2024
1 parent a0d77ac commit d48b725
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Common/Tests/Server/Middleware/UserAuthorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
} from "@jest/globals";
import { getJestSpyOn } from "Common/Tests/Spy";
import getJestMockFunction from "Common/Tests/MockType";
import UserPermissionUtil from "../../../Server/Utils/UserPermission/UserPermission";

jest.mock("../../../Server/Utils/Logger");
jest.mock("../../../Server/Middleware/ProjectAuthorization");
Expand Down Expand Up @@ -718,7 +719,7 @@ describe("UserMiddleware", () => {

const spyGetDefaultUserTenantAccessPermission: jest.SpyInstance =
getJestSpyOn(
AccessTokenService,
UserPermissionUtil,
"getDefaultUserTenantAccessPermission",
).mockReturnValueOnce(mockedUserTenantAccessPermission);

Expand Down
7 changes: 7 additions & 0 deletions Common/UI/Utils/Realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import SocketIO, { Socket } from "socket.io-client";
import ModelEventType from "../../Types/Realtime/ModelEventType";
import ListenToModelEventJSON from "../../Types/Realtime/ListenToModelEventJSON";
import EventName from "../../Types/Realtime/EventName";
import BadDataException from "../../Types/Exception/BadDataException";

export interface ListenToModelEvent<
Model extends AnalyticsBaseModel | BaseModel,
Expand Down Expand Up @@ -42,6 +43,12 @@ export default abstract class Realtime {
this.init();
}

if (!listenToModelEvent.tenantId) {
throw new BadDataException(
"TenantId is required to listen to model event.",
);
}

const listenToModelEventJSON: ListenToModelEventJSON = {
eventType: listenToModelEvent.eventType,
modelType: DatabaseType.Database,
Expand Down

0 comments on commit d48b725

Please sign in to comment.