feat: v2 managed organizations (#19341)
* refactor: allow non unique PlatformBilling customerId * feat: add PlatformBilling managed organizations fields * feat: ManagedOrganization table * refactor: bill overdue based on teamId * refactor: restructure organizations module * wip: organizations endpoints * Revert "wip: organizations endpoints" This reverts commit 0e9e66fc74f31da436f12930c1b6597c650ed621. * refactor: unique index for managed organizations * wip: organizations endpoints * wip: create managed organization * remove unecessary membership check because we have guard * feat: create managed org * feat: get managed org and orgs * feat: update and delete managed orgs * wip: api key logic * feat: allow variable api key length * feat: refresh managed org api key * feat: create managed org OAuth clients using api key * finish merge main * chore: bump platform libraries * tests: fix and add more tests to api-auth.strategy.e2e * refactor: dont request managed org slug and handle metadata as object * revert: billing service and repository update overdue based on sub and customer ids * refactor: v2 OAuth client permissions (#19501) * refactor: v2 permissions as string array * refactor: frontend work with permissions as string * tests: test '*' permissions * fix:managed org creator have profile & test can fetch oauth client * fix: tests * fix: OAuthClientCard on frontend * fix: tests
This commit is contained in:
1 parent
e4ab8d87c4
commit
a44bcafcf2
192 files changed
+9103
-619
No files matched your search
@@ -1,12 +1,12 @@
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
import type { PlatformOAuthClient } from "@calcom/prisma/client";
|
||||
import type { PlatformOAuthClientDto } from "@calcom/platform-types";
|
||||
import { EmptyScreen, Button } from "@calcom/ui";
|
||||
|
||||
import { OAuthClientCard } from "@components/settings/platform/oauth-clients/OAuthClientCard";
|
||||
|
||||
type OAuthClientsListProps = {
|
||||
oauthClients: PlatformOAuthClient[];
|
||||
oauthClients: PlatformOAuthClientDto[];
|
||||
isDeleting: boolean;
|
||||
handleDelete: (id: string) => Promise<void>;
|
||||
};
|
||||
|
||||
@@ -2,21 +2,20 @@ import { useRouter } from "next/navigation";
|
||||
import React from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import type { PERMISSION_MAP } from "@calcom/platform-constants";
|
||||
import { PERMISSIONS_GROUPED_MAP } from "@calcom/platform-constants";
|
||||
import type { Avatar } from "@calcom/prisma/client";
|
||||
import { Button, Icon, showToast } from "@calcom/ui";
|
||||
|
||||
import { hasPermission } from "../../../../../../packages/platform/utils/permissions";
|
||||
|
||||
type OAuthClientCardProps = {
|
||||
name: string;
|
||||
logo?: Avatar;
|
||||
redirectUris: string[];
|
||||
bookingRedirectUri: string | null;
|
||||
bookingCancelRedirectUri: string | null;
|
||||
bookingRescheduleRedirectUri: string | null;
|
||||
areEmailsEnabled: boolean;
|
||||
permissions: number;
|
||||
bookingRedirectUri: string | null | undefined;
|
||||
bookingCancelRedirectUri: string | null | undefined;
|
||||
bookingRescheduleRedirectUri: string | null | undefined;
|
||||
areEmailsEnabled: boolean | undefined;
|
||||
permissions: Array<keyof typeof PERMISSION_MAP>;
|
||||
lastItem: boolean;
|
||||
id: string;
|
||||
secret: string;
|
||||
@@ -43,26 +42,36 @@ export const OAuthClientCard = ({
|
||||
}: OAuthClientCardProps) => {
|
||||
const router = useRouter();
|
||||
|
||||
const clientPermissions = Object.values(PERMISSIONS_GROUPED_MAP).map((value, index) => {
|
||||
let permissionsMessage = "";
|
||||
const hasReadPermission = hasPermission(permissions, value.read);
|
||||
const hasWritePermission = hasPermission(permissions, value.write);
|
||||
const groupedPermissions = permissions.reduce<Record<string, { read: boolean; write: boolean }>>(
|
||||
(acc, permission) => {
|
||||
const [resource] = permission.split("_READ") as [string] | [string, string];
|
||||
const isRead = permission.endsWith("_READ");
|
||||
const isWrite = permission.endsWith("_WRITE");
|
||||
const key = resource.replace("_WRITE", "");
|
||||
|
||||
if (hasReadPermission || hasWritePermission) {
|
||||
permissionsMessage = hasReadPermission ? "read" : "write";
|
||||
}
|
||||
if (!acc[key]) acc[key] = { read: false, write: false };
|
||||
if (isRead) acc[key].read = true;
|
||||
if (isWrite) acc[key].write = true;
|
||||
|
||||
if (hasReadPermission && hasWritePermission) {
|
||||
permissionsMessage = "read/write";
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
const clientPermissions = Object.entries(groupedPermissions).map(([resource, { read, write }], index) => {
|
||||
const permissionTypes = [];
|
||||
if (read) permissionTypes.push("read");
|
||||
if (write) permissionTypes.push("write");
|
||||
|
||||
const permissionsMessage = permissionTypes.join("/");
|
||||
const groupedPermission = PERMISSIONS_GROUPED_MAP[resource as keyof typeof PERMISSIONS_GROUPED_MAP];
|
||||
const isLastItem = index === Object.keys(groupedPermissions).length - 1;
|
||||
|
||||
return (
|
||||
!!permissionsMessage && (
|
||||
<div key={value.read} className="relative text-sm">
|
||||
{permissionsMessage} {`${value.label}s`.toLocaleLowerCase()}
|
||||
{Object.values(PERMISSIONS_GROUPED_MAP).length === index + 1 ? " " : ", "}
|
||||
</div>
|
||||
)
|
||||
<div key={resource} className="relative text-sm">
|
||||
{permissionsMessage} {groupedPermission?.label.toLowerCase()}
|
||||
{!isLastItem && ", "}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user