fix entitlements on login
This commit is contained in:
1 parent
53355cad04
commit
30d7b3d258
17 files changed
+100
-46
No files matched your search
@@ -9,7 +9,8 @@ import { useAppSelector } from "@/hooks/AppHooks";
|
|||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { Tooltip } from "@/components/design-elements";
|
import { Tooltip } from "@/components/design-elements";
|
||||||
const DEPLOYMENT_MODE = import.meta.env.VITE_APP_DEPLOYMENT_MODE;
|
import { config } from "@/config/index";
|
||||||
|
const DEPLOYMENT_MODE = config.DEPLOYMENT_MODE;
|
||||||
const IS_SAAS = DEPLOYMENT_MODE === "saas";
|
const IS_SAAS = DEPLOYMENT_MODE === "saas";
|
||||||
|
|
||||||
export const SettingsSwitch = () => {
|
export const SettingsSwitch = () => {
|
||||||
|
|||||||
@@ -1,32 +1,34 @@
|
|||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { ExternalLink } from "lucide-react";
|
import { ExternalLink } from "lucide-react";
|
||||||
|
import Link from "@mui/material/Link";
|
||||||
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
||||||
import { useTheme } from "@mui/material/styles";
|
const HOST = config.HOST;
|
||||||
const HOST = import.meta.env.VITE_APP_HOST;
|
|
||||||
|
|
||||||
export const NameHeader = ({
|
export const NameHeader = ({
|
||||||
statusPage,
|
statusPage,
|
||||||
}: {
|
}: {
|
||||||
statusPage: IStatusPageWithMonitors;
|
statusPage: IStatusPageWithMonitors;
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
return (
|
||||||
<Stack direction={"row"} alignItems={"flex-end"} spacing={theme.spacing(4)}>
|
<Stack direction={"row"} alignItems={"flex-end"} spacing={4}>
|
||||||
<Typography variant="h1">{statusPage?.name}</Typography>
|
<Typography variant="h1">{statusPage?.name}</Typography>
|
||||||
{statusPage?.isPublished && (
|
{statusPage?.isPublished && (
|
||||||
<Stack
|
<Link
|
||||||
component={"a"}
|
href={`${HOST ?? ""}/status-pages/public/${statusPage?.url}`}
|
||||||
href={`${HOST}/status-pages/public/${statusPage?.url}`}
|
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
direction={"row"}
|
underline="none"
|
||||||
sx={{ textDecoration: "none", color: "inherit" }}
|
color="inherit"
|
||||||
|
sx={{ display: "inline-flex" }}
|
||||||
>
|
>
|
||||||
<Typography>Public link</Typography>
|
<Stack direction="row" alignItems="center" spacing={1}>
|
||||||
<ExternalLink size={16} strokeWidth={1.5} />
|
<Typography>Public link</Typography>
|
||||||
</Stack>
|
<ExternalLink size={16} strokeWidth={1.5} />
|
||||||
|
</Stack>
|
||||||
|
</Link>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import type { DeploymentMode } from "@/types/env";
|
||||||
|
|
||||||
|
export interface IEnvConfig {
|
||||||
|
HOST: string;
|
||||||
|
GLOBAL_REFRESH: number;
|
||||||
|
API_BASE_URL: string;
|
||||||
|
DEPLOYMENT_MODE: DeploymentMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawRefresh = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
||||||
|
const parsedRefresh = Number(rawRefresh);
|
||||||
|
const GLOBAL_REFRESH = Number.isFinite(parsedRefresh) ? parsedRefresh : 60000;
|
||||||
|
|
||||||
|
const rawMode = import.meta.env.VITE_APP_DEPLOYMENT_MODE as
|
||||||
|
| DeploymentMode
|
||||||
|
| string
|
||||||
|
| undefined;
|
||||||
|
const DEPLOYMENT_MODE: DeploymentMode =
|
||||||
|
rawMode === "saas" || rawMode === "self_hosted" ? (rawMode as DeploymentMode) : "self_hosted";
|
||||||
|
|
||||||
|
export const config: IEnvConfig = {
|
||||||
|
HOST: import.meta.env.VITE_APP_HOST || "http://localhost:5173",
|
||||||
|
GLOBAL_REFRESH,
|
||||||
|
API_BASE_URL:
|
||||||
|
import.meta.env.VITE_APP_API_BASE_URL || "http://localhost:52345/api/v1",
|
||||||
|
DEPLOYMENT_MODE,
|
||||||
|
};
|
||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
/// <reference types="vite/client" />
|
||||||
|
import type { DeploymentMode } from "@/types/env";
|
||||||
|
interface ImportMetaEnv {
|
||||||
|
readonly VITE_APP_HOST?: string;
|
||||||
|
readonly VITE_APP_GLOBAL_REFRESH?: string;
|
||||||
|
readonly VITE_APP_API_BASE_URL?: string;
|
||||||
|
readonly VITE_APP_DEPLOYMENT_MODE?: DeploymentMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ImportMeta {
|
||||||
|
readonly env: ImportMetaEnv;
|
||||||
|
}
|
||||||
@@ -14,7 +14,8 @@ import { useForm, Controller } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useGet, usePost } from "@/hooks/UseApi";
|
import { useGet, usePost } from "@/hooks/UseApi";
|
||||||
import type { ApiResponse } from "@/hooks/UseApi";
|
import type { ApiResponse } from "@/hooks/UseApi";
|
||||||
const host = import.meta.env.VITE_APP_HOST;
|
import { config } from "@/config/index";
|
||||||
|
const HOST = config.HOST;
|
||||||
|
|
||||||
type FormValues = z.infer<typeof inviteSchema>;
|
type FormValues = z.infer<typeof inviteSchema>;
|
||||||
|
|
||||||
@@ -202,7 +203,7 @@ const Invite = () => {
|
|||||||
{token && (
|
{token && (
|
||||||
<Stack>
|
<Stack>
|
||||||
<Typography variant="h2">Invite link:</Typography>
|
<Typography variant="h2">Invite link:</Typography>
|
||||||
<Typography>{`${host}/register/${token}`}</Typography>
|
<Typography>{`${HOST}/register/${token}`}</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
<Box flex={1}>
|
<Box flex={1}>
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ import {
|
|||||||
getOsAndPlatform,
|
getOsAndPlatform,
|
||||||
} from "@/pages/infrastructure/InfraUtils";
|
} from "@/pages/infrastructure/InfraUtils";
|
||||||
import { InfraDetailsGauges } from "./InfraDetailsGauges";
|
import { InfraDetailsGauges } from "./InfraDetailsGauges";
|
||||||
|
import { config } from "@/config/index";
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
|
|
||||||
const InfraDetailsPage = () => {
|
const InfraDetailsPage = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import { useState } from "react";
|
|||||||
import { useDelete } from "@/hooks/UseApi";
|
import { useDelete } from "@/hooks/UseApi";
|
||||||
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
||||||
import { useAppSelector } from "@/hooks/AppHooks";
|
import { useAppSelector } from "@/hooks/AppHooks";
|
||||||
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
|
|
||||||
const PageSpeedMonitorsPage = () => {
|
const PageSpeedMonitorsPage = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ import type { IMonitor, IMonitorWithMonitorStats } from "@/types/monitor";
|
|||||||
import { getStatusPalette } from "@/utils/MonitorUtils";
|
import { getStatusPalette } from "@/utils/MonitorUtils";
|
||||||
import prettyMilliseconds from "pretty-ms";
|
import prettyMilliseconds from "pretty-ms";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
const PageSpeedDetailsPage = () => {
|
const PageSpeedDetailsPage = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ import { useState } from "react";
|
|||||||
import { useDelete } from "@/hooks/UseApi";
|
import { useDelete } from "@/hooks/UseApi";
|
||||||
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
import { InitializingStatusBox } from "@/components/design-elements/StatusBox";
|
||||||
import { useAppSelector } from "@/hooks/AppHooks";
|
import { useAppSelector } from "@/hooks/AppHooks";
|
||||||
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
|
|
||||||
const PageSpeedMonitorsPage = () => {
|
const PageSpeedMonitorsPage = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|||||||
@@ -10,8 +10,9 @@ import type { ApiResponse } from "@/hooks/UseApi";
|
|||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
||||||
import { NameHeader } from "@/components/status-pages/NameHeader";
|
import { NameHeader } from "@/components/status-pages/NameHeader";
|
||||||
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
const StatusPages = () => {
|
const StatusPages = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ import type { ApiResponse } from "@/hooks/UseApi";
|
|||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
import type { IStatusPageWithMonitors } from "@/types/status-page";
|
||||||
import { NameHeader } from "@/components/status-pages/NameHeader";
|
import { NameHeader } from "@/components/status-pages/NameHeader";
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
const StatusPages = () => {
|
const StatusPages = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { url } = useParams();
|
const { url } = useParams();
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ import { useGet, usePatch, type ApiResponse } from "@/hooks/UseApi";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { getStatusPalette } from "@/utils/MonitorUtils";
|
import { getStatusPalette } from "@/utils/MonitorUtils";
|
||||||
import prettyMilliseconds from "pretty-ms";
|
import prettyMilliseconds from "pretty-ms";
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
|
|
||||||
const UptimeDetailsPage = () => {
|
const UptimeDetailsPage = () => {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ import useMediaQuery from "@mui/material/useMediaQuery";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useDelete } from "@/hooks/UseApi";
|
import { useDelete } from "@/hooks/UseApi";
|
||||||
import { useAppSelector } from "@/hooks/AppHooks";
|
import { useAppSelector } from "@/hooks/AppHooks";
|
||||||
|
import { config } from "@/config/index";
|
||||||
|
|
||||||
const GLOBAL_REFRESH = import.meta.env.VITE_APP_GLOBAL_REFRESH;
|
const GLOBAL_REFRESH = config.GLOBAL_REFRESH;
|
||||||
|
|
||||||
const UptimeMonitors = () => {
|
const UptimeMonitors = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|||||||
Vendored
-17
@@ -1,17 +0,0 @@
|
|||||||
/// <reference types="vite/client" />
|
|
||||||
|
|
||||||
interface ImportMetaEnv {
|
|
||||||
readonly VITE_APP_API_V2_BASE_URL?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ImportMeta {
|
|
||||||
readonly env: ImportMetaEnv;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module "*.svg?react" {
|
|
||||||
import * as React from "react";
|
|
||||||
const ReactComponent: React.FunctionComponent<
|
|
||||||
React.SVGProps<SVGSVGElement> & { title?: string }
|
|
||||||
>;
|
|
||||||
export default ReactComponent;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export type DeploymentMode = "saas" | "self_hosted";
|
||||||
@@ -22,6 +22,8 @@ import { IJobQueue } from "../infrastructure/JobQueue.js";
|
|||||||
import { hashPassword } from "@/utils/JWTUtils.js";
|
import { hashPassword } from "@/utils/JWTUtils.js";
|
||||||
import { Plans } from "@/types/entitlements.js";
|
import { Plans } from "@/types/entitlements.js";
|
||||||
import { PERMISSIONS } from "@/types/permissions.js";
|
import { PERMISSIONS } from "@/types/permissions.js";
|
||||||
|
import { EntitlementsFactory } from "@/services/system/EntitlementsService.js";
|
||||||
|
import type { Entitlements } from "@/types/entitlements.js";
|
||||||
|
|
||||||
const SERVICE_NAME = "AuthService";
|
const SERVICE_NAME = "AuthService";
|
||||||
|
|
||||||
@@ -255,6 +257,11 @@ class AuthService implements IAuthService {
|
|||||||
permissions: roles[2]?.permissions || [],
|
permissions: roles[2]?.permissions || [],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const provider = EntitlementsFactory.create();
|
||||||
|
const entitlements: Entitlements = await provider.getForOrg(
|
||||||
|
org._id.toString()
|
||||||
|
);
|
||||||
|
|
||||||
const returnableUser: IUserReturnable = {
|
const returnableUser: IUserReturnable = {
|
||||||
id: user._id.toString(),
|
id: user._id.toString(),
|
||||||
email: user.email,
|
email: user.email,
|
||||||
@@ -266,7 +273,7 @@ class AuthService implements IAuthService {
|
|||||||
permissions: roles[0]?.permissions || [],
|
permissions: roles[0]?.permissions || [],
|
||||||
},
|
},
|
||||||
teams: [returnableTeam],
|
teams: [returnableTeam],
|
||||||
entitlements: org.entitlements,
|
entitlements,
|
||||||
};
|
};
|
||||||
|
|
||||||
return { tokenizedUser, returnableUser };
|
return { tokenizedUser, returnableUser };
|
||||||
@@ -392,6 +399,10 @@ class AuthService implements IAuthService {
|
|||||||
const orgRole = await Role.findById(orgMembership.roleId);
|
const orgRole = await Role.findById(orgMembership.roleId);
|
||||||
const orgPermissions = orgRole?.permissions || [];
|
const orgPermissions = orgRole?.permissions || [];
|
||||||
|
|
||||||
|
const provider = EntitlementsFactory.create();
|
||||||
|
const entitlements: Entitlements = await provider.getForOrg(
|
||||||
|
org._id.toString()
|
||||||
|
);
|
||||||
const returnableUser: IUserReturnable = {
|
const returnableUser: IUserReturnable = {
|
||||||
id: user._id.toString(),
|
id: user._id.toString(),
|
||||||
email: user.email,
|
email: user.email,
|
||||||
@@ -403,7 +414,7 @@ class AuthService implements IAuthService {
|
|||||||
permissions: orgPermissions,
|
permissions: orgPermissions,
|
||||||
},
|
},
|
||||||
teams: returnableTeams,
|
teams: returnableTeams,
|
||||||
entitlements: org.entitlements,
|
entitlements,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -499,6 +510,11 @@ class AuthService implements IAuthService {
|
|||||||
orgId: orgMembership.orgId.toString(),
|
orgId: orgMembership.orgId.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const provider = EntitlementsFactory.create();
|
||||||
|
const entitlements: Entitlements = await provider.getForOrg(
|
||||||
|
org._id.toString()
|
||||||
|
);
|
||||||
|
|
||||||
const returnableUser: IUserReturnable = {
|
const returnableUser: IUserReturnable = {
|
||||||
id: user._id.toString(),
|
id: user._id.toString(),
|
||||||
email: user.email,
|
email: user.email,
|
||||||
@@ -510,7 +526,7 @@ class AuthService implements IAuthService {
|
|||||||
permissions: orgRoles?.permissions || [],
|
permissions: orgRoles?.permissions || [],
|
||||||
},
|
},
|
||||||
teams: returnableTeams,
|
teams: returnableTeams,
|
||||||
entitlements: org.entitlements,
|
entitlements,
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Entitlements, Plans } from "@/types/entitlements.js";
|
import { Entitlements, Plans } from "@/types/entitlements.js";
|
||||||
import { Org } from "@/db/models/index.js";
|
import { Org } from "@/db/models/index.js";
|
||||||
|
import { DeploymentMode } from "@/utils/FeatureFlags.js";
|
||||||
|
import { config } from "@/config/index.js";
|
||||||
|
|
||||||
export interface IEntitlementsProvider {
|
export interface IEntitlementsProvider {
|
||||||
getForOrg(orgId: string): Promise<Entitlements>;
|
getForOrg(orgId: string): Promise<Entitlements>;
|
||||||
@@ -31,8 +33,8 @@ export class SelfHostedEntitlementsProvider implements IEntitlementsProvider {
|
|||||||
|
|
||||||
export class EntitlementsFactory {
|
export class EntitlementsFactory {
|
||||||
static create(): IEntitlementsProvider {
|
static create(): IEntitlementsProvider {
|
||||||
const mode = (process.env.DEPLOYMENT_MODE || "saas").toLowerCase();
|
const mode: DeploymentMode = config.DEPLOYMENT_MODE || "self_hosted";
|
||||||
if (mode === "self") return new SelfHostedEntitlementsProvider();
|
if (mode === "self_hosted") return new SelfHostedEntitlementsProvider();
|
||||||
return new SaaSEntitlementsProvider();
|
return new SaaSEntitlementsProvider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user