mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-03 06:21:32 +00:00
import and unassocaite org idp
This commit is contained in:
@@ -2899,5 +2899,22 @@
|
|||||||
"httpDestUpdatedSuccess": "Destination updated successfully",
|
"httpDestUpdatedSuccess": "Destination updated successfully",
|
||||||
"httpDestCreatedSuccess": "Destination created successfully",
|
"httpDestCreatedSuccess": "Destination created successfully",
|
||||||
"httpDestUpdateFailed": "Failed to update destination",
|
"httpDestUpdateFailed": "Failed to update destination",
|
||||||
"httpDestCreateFailed": "Failed to create destination"
|
"httpDestCreateFailed": "Failed to create destination",
|
||||||
|
"idpAddActionCreateNew": "Create new identity provider",
|
||||||
|
"idpAddActionImportFromOrg": "Import from another organization",
|
||||||
|
"idpImportDialogTitle": "Import Identity Provider",
|
||||||
|
"idpImportDialogDescription": "Choose an identity provider from an organization where you are an admin. It will be linked to this organization.",
|
||||||
|
"idpImportSearchPlaceholder": "Search by organization or provider name...",
|
||||||
|
"idpImportEmpty": "No identity providers found.",
|
||||||
|
"idpImportedDescription": "Identity provider imported successfully.",
|
||||||
|
"idpDeleteGlobalQuestion": "Are you sure you want to permanently delete this identity provider?",
|
||||||
|
"idpDeleteGlobalDescription": "This will permanently delete the identity provider from all organizations it is associated with.",
|
||||||
|
"idpUnassociateTitle": "Unassociate Identity Provider",
|
||||||
|
"idpUnassociateQuestion": "Are you sure you want to unassociate this identity provider from this organization?",
|
||||||
|
"idpUnassociateDescription": "All users associated with this identity provider will be removed from this organization, but the identity provider will still continue to exist for other associated organizations.",
|
||||||
|
"idpUnassociateConfirm": "Confirm Unassociate Identity Provider",
|
||||||
|
"idpUnassociateWarning": "This cannot be undone for this organization.",
|
||||||
|
"idpUnassociatedDescription": "Identity provider unassociated from this organization successfully",
|
||||||
|
"idpUnassociateMenu": "Unassociate",
|
||||||
|
"idpDeleteAllOrgsMenu": "Delete"
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
public/idp/openid.png
Normal file
BIN
public/idp/openid.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
@@ -40,7 +40,9 @@ import {
|
|||||||
verifyRoleAccess,
|
verifyRoleAccess,
|
||||||
verifyUserAccess,
|
verifyUserAccess,
|
||||||
verifyUserCanSetUserOrgRoles,
|
verifyUserCanSetUserOrgRoles,
|
||||||
verifySiteProvisioningKeyAccess
|
verifySiteProvisioningKeyAccess,
|
||||||
|
verifyIsLoggedInUser,
|
||||||
|
verifyAdmin
|
||||||
} from "@server/middlewares";
|
} from "@server/middlewares";
|
||||||
import { ActionsEnum } from "@server/auth/actions";
|
import { ActionsEnum } from "@server/auth/actions";
|
||||||
import {
|
import {
|
||||||
@@ -94,6 +96,17 @@ authenticated.put(
|
|||||||
orgIdp.createOrgOidcIdp
|
orgIdp.createOrgOidcIdp
|
||||||
);
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/org/:orgId/idp/:idpId/import",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyValidSubscription(tierMatrix.orgOidc),
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyLimits,
|
||||||
|
verifyAdmin,
|
||||||
|
logActionAudit(ActionsEnum.createIdp),
|
||||||
|
orgIdp.importOrgIdp
|
||||||
|
);
|
||||||
|
|
||||||
authenticated.post(
|
authenticated.post(
|
||||||
"/org/:orgId/idp/:idpId/oidc",
|
"/org/:orgId/idp/:idpId/oidc",
|
||||||
verifyValidLicense,
|
verifyValidLicense,
|
||||||
@@ -116,6 +129,16 @@ authenticated.delete(
|
|||||||
orgIdp.deleteOrgIdp
|
orgIdp.deleteOrgIdp
|
||||||
);
|
);
|
||||||
|
|
||||||
|
authenticated.delete(
|
||||||
|
"/org/:orgId/idp/:idpId/association",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyOrgAccess,
|
||||||
|
verifyIdpAccess,
|
||||||
|
verifyUserHasAction(ActionsEnum.deleteIdp),
|
||||||
|
logActionAudit(ActionsEnum.deleteIdp),
|
||||||
|
orgIdp.unassociateOrgIdp
|
||||||
|
);
|
||||||
|
|
||||||
authenticated.get(
|
authenticated.get(
|
||||||
"/org/:orgId/idp/:idpId",
|
"/org/:orgId/idp/:idpId",
|
||||||
verifyValidLicense,
|
verifyValidLicense,
|
||||||
@@ -125,16 +148,14 @@ authenticated.get(
|
|||||||
orgIdp.getOrgIdp
|
orgIdp.getOrgIdp
|
||||||
);
|
);
|
||||||
|
|
||||||
authenticated.get(
|
|
||||||
"/org/:orgId/idp",
|
|
||||||
verifyValidLicense,
|
|
||||||
verifyOrgAccess,
|
|
||||||
verifyUserHasAction(ActionsEnum.listIdps),
|
|
||||||
orgIdp.listOrgIdps
|
|
||||||
);
|
|
||||||
|
|
||||||
authenticated.get("/org/:orgId/idp", orgIdp.listOrgIdps); // anyone can see this; it's just a list of idp names and ids
|
authenticated.get("/org/:orgId/idp", orgIdp.listOrgIdps); // anyone can see this; it's just a list of idp names and ids
|
||||||
|
|
||||||
|
authenticated.get(
|
||||||
|
"/user/:userId/admin-org-idps",
|
||||||
|
verifyIsLoggedInUser,
|
||||||
|
orgIdp.listUserAdminOrgIdps
|
||||||
|
);
|
||||||
|
|
||||||
authenticated.get(
|
authenticated.get(
|
||||||
"/org/:orgId/certificate/:domainId/:domain",
|
"/org/:orgId/certificate/:domainId/:domain",
|
||||||
verifyValidLicense,
|
verifyValidLicense,
|
||||||
|
|||||||
225
server/private/routers/orgIdp/importOrgIdp.ts
Normal file
225
server/private/routers/orgIdp/importOrgIdp.ts
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
import { idp, idpOrg, orgs, roles, userOrgs } from "@server/db";
|
||||||
|
import { and, eq, inArray } from "drizzle-orm";
|
||||||
|
import { CreateOrgIdpResponse } from "@server/routers/orgIdp/types";
|
||||||
|
import { generateOidcRedirectUrl } from "@server/lib/idp/generateRedirectUrl";
|
||||||
|
import privateConfig from "#private/lib/config";
|
||||||
|
import { checkOrgAccessPolicy } from "#dynamic/lib/checkOrgAccessPolicy";
|
||||||
|
import { getUserOrgRoleIds } from "@server/lib/userOrgRoles";
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
orgId: z.string().nonempty(),
|
||||||
|
idpId: z.coerce.number<number>().int().positive()
|
||||||
|
});
|
||||||
|
|
||||||
|
const bodySchema = z.strictObject({
|
||||||
|
sourceOrgId: z.string().nonempty()
|
||||||
|
});
|
||||||
|
|
||||||
|
async function userIsOrgAdmin(
|
||||||
|
userId: string,
|
||||||
|
orgId: string,
|
||||||
|
session: Request["session"]
|
||||||
|
): Promise<boolean> {
|
||||||
|
const [userOrgRow] = await db
|
||||||
|
.select()
|
||||||
|
.from(userOrgs)
|
||||||
|
.where(and(eq(userOrgs.userId, userId), eq(userOrgs.orgId, orgId)))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!userOrgRow) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const policyCheck = await checkOrgAccessPolicy({
|
||||||
|
orgId,
|
||||||
|
userId,
|
||||||
|
session
|
||||||
|
});
|
||||||
|
if (!policyCheck.allowed || policyCheck.error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const roleIds = await getUserOrgRoleIds(userId, orgId);
|
||||||
|
if (roleIds.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [adminRole] = await db
|
||||||
|
.select()
|
||||||
|
.from(roles)
|
||||||
|
.where(and(inArray(roles.roleId, roleIds), eq(roles.isAdmin, true)))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
return !!adminRole;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function importOrgIdp(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { orgId: targetOrgId, idpId } = parsedParams.data;
|
||||||
|
|
||||||
|
const parsedBody = bodySchema.safeParse(req.body);
|
||||||
|
if (!parsedBody.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedBody.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { sourceOrgId } = parsedBody.data;
|
||||||
|
|
||||||
|
if (
|
||||||
|
privateConfig.getRawPrivateConfig().app.identity_provider_mode !==
|
||||||
|
"org"
|
||||||
|
) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"Organization-specific IdP creation is not allowed in the current identity provider mode. Set app.identity_provider_mode to 'org' in the private configuration to enable this feature."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sourceOrgId === targetOrgId) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"Source and target organization must be different"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const userId = req.user!.userId;
|
||||||
|
|
||||||
|
const sourceLinked = await db
|
||||||
|
.select()
|
||||||
|
.from(idpOrg)
|
||||||
|
.where(and(eq(idpOrg.idpId, idpId), eq(idpOrg.orgId, sourceOrgId)))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (sourceLinked.length === 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
"IdP not found for the source organization"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceAdmin = await userIsOrgAdmin(
|
||||||
|
userId,
|
||||||
|
sourceOrgId,
|
||||||
|
req.session
|
||||||
|
);
|
||||||
|
if (!sourceAdmin) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.FORBIDDEN,
|
||||||
|
"You must be an organization admin in the source organization where this IdP is linked"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [targetOrg] = await db
|
||||||
|
.select({ orgId: orgs.orgId })
|
||||||
|
.from(orgs)
|
||||||
|
.where(eq(orgs.orgId, targetOrgId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!targetOrg) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
"Target organization not found"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [existingIdp] = await db
|
||||||
|
.select()
|
||||||
|
.from(idp)
|
||||||
|
.where(eq(idp.idpId, idpId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!existingIdp) {
|
||||||
|
return next(createHttpError(HttpCode.NOT_FOUND, "IdP not found"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const alreadyTarget = await db
|
||||||
|
.select()
|
||||||
|
.from(idpOrg)
|
||||||
|
.where(and(eq(idpOrg.idpId, idpId), eq(idpOrg.orgId, targetOrgId)))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (alreadyTarget.length > 0) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.CONFLICT,
|
||||||
|
"This IdP is already linked to the target organization"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.insert(idpOrg).values({
|
||||||
|
idpId,
|
||||||
|
orgId: targetOrgId,
|
||||||
|
roleMapping: null,
|
||||||
|
orgMapping: `'${targetOrgId}'`
|
||||||
|
});
|
||||||
|
|
||||||
|
const redirectUrl = await generateOidcRedirectUrl(idpId, targetOrgId);
|
||||||
|
|
||||||
|
return response<CreateOrgIdpResponse>(res, {
|
||||||
|
data: {
|
||||||
|
idpId,
|
||||||
|
redirectUrl
|
||||||
|
},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Org IdP imported successfully",
|
||||||
|
status: HttpCode.CREATED
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from "./createOrgOidcIdp";
|
export * from "./createOrgOidcIdp";
|
||||||
|
export * from "./importOrgIdp";
|
||||||
export * from "./getOrgIdp";
|
export * from "./getOrgIdp";
|
||||||
export * from "./listOrgIdps";
|
export * from "./listOrgIdps";
|
||||||
|
export * from "./listUserAdminOrgIdps";
|
||||||
export * from "./updateOrgOidcIdp";
|
export * from "./updateOrgOidcIdp";
|
||||||
export * from "./deleteOrgIdp";
|
export * from "./deleteOrgIdp";
|
||||||
|
export * from "./unassociateOrgIdp";
|
||||||
|
|||||||
160
server/private/routers/orgIdp/listUserAdminOrgIdps.ts
Normal file
160
server/private/routers/orgIdp/listUserAdminOrgIdps.ts
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db, idpOidcConfig } from "@server/db";
|
||||||
|
import { idp, idpOrg, orgs, roles, userOrgRoles } from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import { and, eq, inArray, sql } from "drizzle-orm";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
import { ListUserAdminOrgIdpsResponse } from "@server/routers/orgIdp/types";
|
||||||
|
|
||||||
|
const querySchema = z.strictObject({
|
||||||
|
limit: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.default("1000")
|
||||||
|
.transform(Number)
|
||||||
|
.pipe(z.int().nonnegative()),
|
||||||
|
offset: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.default("0")
|
||||||
|
.transform(Number)
|
||||||
|
.pipe(z.int().nonnegative())
|
||||||
|
});
|
||||||
|
|
||||||
|
const paramsSchema = z.strictObject({
|
||||||
|
userId: z.string().nonempty()
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getOrgIdsWhereUserIsAdmin(userId: string): Promise<string[]> {
|
||||||
|
const rows = await db
|
||||||
|
.select({ orgId: userOrgRoles.orgId })
|
||||||
|
.from(userOrgRoles)
|
||||||
|
.innerJoin(roles, eq(userOrgRoles.roleId, roles.roleId))
|
||||||
|
.where(and(eq(userOrgRoles.userId, userId), eq(roles.isAdmin, true)));
|
||||||
|
return [...new Set(rows.map((r) => r.orgId))];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function queryIdpsForOrgs(
|
||||||
|
orgIds: string[],
|
||||||
|
limit: number,
|
||||||
|
offset: number
|
||||||
|
) {
|
||||||
|
return db
|
||||||
|
.select({
|
||||||
|
idpId: idp.idpId,
|
||||||
|
orgId: idpOrg.orgId,
|
||||||
|
orgName: orgs.name,
|
||||||
|
name: idp.name,
|
||||||
|
type: idp.type,
|
||||||
|
variant: idpOidcConfig.variant,
|
||||||
|
tags: idp.tags
|
||||||
|
})
|
||||||
|
.from(idpOrg)
|
||||||
|
.where(inArray(idpOrg.orgId, orgIds))
|
||||||
|
.innerJoin(orgs, eq(orgs.orgId, idpOrg.orgId))
|
||||||
|
.innerJoin(idp, eq(idp.idpId, idpOrg.idpId))
|
||||||
|
.innerJoin(idpOidcConfig, eq(idpOidcConfig.idpId, idpOrg.idpId))
|
||||||
|
.orderBy(sql`idp.name DESC`)
|
||||||
|
.limit(limit)
|
||||||
|
.offset(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function countIdpsForOrgs(orgIds: string[]) {
|
||||||
|
const [{ count }] = await db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(idpOrg)
|
||||||
|
.innerJoin(idp, eq(idp.idpId, idpOrg.idpId))
|
||||||
|
.innerJoin(idpOidcConfig, eq(idpOidcConfig.idpId, idpOrg.idpId))
|
||||||
|
.where(inArray(idpOrg.orgId, orgIds));
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function listUserAdminOrgIdps(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { userId } = parsedParams.data;
|
||||||
|
|
||||||
|
const parsedQuery = querySchema.safeParse(req.query);
|
||||||
|
if (!parsedQuery.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedQuery.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const { limit, offset } = parsedQuery.data;
|
||||||
|
|
||||||
|
const adminOrgIds = await getOrgIdsWhereUserIsAdmin(userId);
|
||||||
|
|
||||||
|
if (adminOrgIds.length === 0) {
|
||||||
|
return response<ListUserAdminOrgIdpsResponse>(res, {
|
||||||
|
data: {
|
||||||
|
idps: [],
|
||||||
|
pagination: {
|
||||||
|
total: 0,
|
||||||
|
limit,
|
||||||
|
offset
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Org Idps retrieved successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const list = await queryIdpsForOrgs(adminOrgIds, limit, offset);
|
||||||
|
const total = await countIdpsForOrgs(adminOrgIds);
|
||||||
|
|
||||||
|
return response<ListUserAdminOrgIdpsResponse>(res, {
|
||||||
|
data: {
|
||||||
|
idps: list,
|
||||||
|
pagination: {
|
||||||
|
total,
|
||||||
|
limit,
|
||||||
|
offset
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Org Idps retrieved successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
109
server/private/routers/orgIdp/unassociateOrgIdp.ts
Normal file
109
server/private/routers/orgIdp/unassociateOrgIdp.ts
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of a proprietary work.
|
||||||
|
*
|
||||||
|
* Copyright (c) 2025-2026 Fossorial, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is licensed under the Fossorial Commercial License.
|
||||||
|
* You may not use this file except in compliance with the License.
|
||||||
|
* Unauthorized use, copying, modification, or distribution is strictly prohibited.
|
||||||
|
*
|
||||||
|
* This file is not licensed under the AGPLv3.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db, idpOrg } from "@server/db";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { and, eq, sql } from "drizzle-orm";
|
||||||
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
import privateConfig from "#private/lib/config";
|
||||||
|
|
||||||
|
const paramsSchema = z
|
||||||
|
.object({
|
||||||
|
orgId: z.string().nonempty(),
|
||||||
|
idpId: z.coerce.number<number>().int().positive()
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
|
export async function unassociateOrgIdp(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { orgId, idpId } = parsedParams.data;
|
||||||
|
|
||||||
|
if (
|
||||||
|
privateConfig.getRawPrivateConfig().app.identity_provider_mode !==
|
||||||
|
"org"
|
||||||
|
) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"Organization-specific IdP creation is not allowed in the current identity provider mode. Set app.identity_provider_mode to 'org' in the private configuration to enable this feature."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [association] = await db
|
||||||
|
.select()
|
||||||
|
.from(idpOrg)
|
||||||
|
.where(and(eq(idpOrg.idpId, idpId), eq(idpOrg.orgId, orgId)))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!association) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`IdP with ID ${idpId} is not associated with organization ${orgId}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [{ count }] = await db
|
||||||
|
.select({ count: sql<number>`count(*)` })
|
||||||
|
.from(idpOrg)
|
||||||
|
.where(eq(idpOrg.idpId, idpId));
|
||||||
|
|
||||||
|
if (count <= 1) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"This is the last organization associated with this identity provider. Delete it instead."
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db
|
||||||
|
.delete(idpOrg)
|
||||||
|
.where(and(eq(idpOrg.idpId, idpId), eq(idpOrg.orgId, orgId)));
|
||||||
|
|
||||||
|
return response<null>(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Org IdP unassociated successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.INTERNAL_SERVER_ERROR, "An error occurred")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,3 +25,22 @@ export type ListOrgIdpsResponse = {
|
|||||||
offset: number;
|
offset: number;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ListUserAdminOrgIdpsEntry = {
|
||||||
|
idpId: number;
|
||||||
|
orgId: string;
|
||||||
|
orgName: string;
|
||||||
|
name: string;
|
||||||
|
type: string;
|
||||||
|
variant: string;
|
||||||
|
tags: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ListUserAdminOrgIdpsResponse = {
|
||||||
|
idps: ListUserAdminOrgIdpsEntry[];
|
||||||
|
pagination: {
|
||||||
|
total: number;
|
||||||
|
limit: number;
|
||||||
|
offset: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ import { Checkbox } from "@app/components/ui/checkbox";
|
|||||||
import { ListIdpsResponse } from "@server/routers/idp";
|
import { ListIdpsResponse } from "@server/routers/idp";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import Image from "next/image";
|
import IdpTypeIcon from "@app/components/IdpTypeIcon";
|
||||||
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
||||||
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
import { tierMatrix } from "@server/lib/billing/tierMatrix";
|
||||||
import OrgRolesTagField from "@app/components/OrgRolesTagField";
|
import OrgRolesTagField from "@app/components/OrgRolesTagField";
|
||||||
@@ -152,31 +152,8 @@ export default function Page() {
|
|||||||
|
|
||||||
const getIdpIcon = (variant: string | null) => {
|
const getIdpIcon = (variant: string | null) => {
|
||||||
if (!variant) return null;
|
if (!variant) return null;
|
||||||
|
const type = variant.toLowerCase();
|
||||||
switch (variant.toLowerCase()) {
|
return <IdpTypeIcon type={type} size={24} />;
|
||||||
case "google":
|
|
||||||
return (
|
|
||||||
<Image
|
|
||||||
src="/idp/google.png"
|
|
||||||
alt={t("idpGoogleAlt")}
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
case "azure":
|
|
||||||
return (
|
|
||||||
<Image
|
|
||||||
src="/idp/azure.png"
|
|
||||||
alt={t("idpAzureAlt")}
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const validFor = [
|
const validFor = [
|
||||||
@@ -340,7 +317,8 @@ export default function Page() {
|
|||||||
|
|
||||||
const roleIds = values.roles.map((r) => parseInt(r.id, 10));
|
const roleIds = values.roles.map((r) => parseInt(r.id, 10));
|
||||||
|
|
||||||
const res = await api.post<AxiosResponse<InviteUserResponse>>(
|
const res = await api
|
||||||
|
.post<AxiosResponse<InviteUserResponse>>(
|
||||||
`/org/${orgId}/create-invite`,
|
`/org/${orgId}/create-invite`,
|
||||||
{
|
{
|
||||||
email: values.email,
|
email: values.email,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
import { Alert, AlertDescription } from "@app/components/ui/alert";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Image from "next/image";
|
import IdpTypeIcon from "@app/components/IdpTypeIcon";
|
||||||
import {
|
import {
|
||||||
generateOidcUrlProxy,
|
generateOidcUrlProxy,
|
||||||
type GenerateOidcUrlResponse
|
type GenerateOidcUrlResponse
|
||||||
@@ -135,24 +135,7 @@ export default function IdpLoginButtons({
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
>
|
>
|
||||||
{effectiveType === "google" && (
|
<IdpTypeIcon type={effectiveType} size={16} />
|
||||||
<Image
|
|
||||||
src="/idp/google.png"
|
|
||||||
alt="Google"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{effectiveType === "azure" && (
|
|
||||||
<Image
|
|
||||||
src="/idp/azure.png"
|
|
||||||
alt="Azure"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<span>{idp.name}</span>
|
<span>{idp.name}</span>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Badge } from "@app/components/ui/badge";
|
import { Badge } from "@app/components/ui/badge";
|
||||||
import Image from "next/image";
|
import IdpTypeIcon from "@app/components/IdpTypeIcon";
|
||||||
|
|
||||||
type IdpTypeBadgeProps = {
|
type IdpTypeBadgeProps = {
|
||||||
type: string;
|
type: string;
|
||||||
@@ -29,34 +29,8 @@ export default function IdpTypeBadge({
|
|||||||
variant="secondary"
|
variant="secondary"
|
||||||
className="inline-flex items-center space-x-1 w-fit"
|
className="inline-flex items-center space-x-1 w-fit"
|
||||||
>
|
>
|
||||||
{effectiveType === "google" && (
|
<IdpTypeIcon type={effectiveType} size={16} />
|
||||||
<>
|
|
||||||
<Image
|
|
||||||
src="/idp/google.png"
|
|
||||||
alt="Google"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
<span>{effectiveName}</span>
|
<span>{effectiveName}</span>
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{effectiveType === "azure" && (
|
|
||||||
<>
|
|
||||||
<Image
|
|
||||||
src="/idp/azure.png"
|
|
||||||
alt="Azure"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
<span>{effectiveName}</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{effectiveType === "oidc" && <span>{effectiveName}</span>}
|
|
||||||
{!["google", "azure", "oidc"].includes(effectiveType) && (
|
|
||||||
<span>{effectiveName}</span>
|
|
||||||
)}
|
|
||||||
</Badge>
|
</Badge>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
53
src/components/IdpTypeIcon.tsx
Normal file
53
src/components/IdpTypeIcon.tsx
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { cn } from "@app/lib/cn";
|
||||||
|
import Image from "next/image";
|
||||||
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
type?: string | null;
|
||||||
|
variant?: string | null;
|
||||||
|
size?: number;
|
||||||
|
className?: string;
|
||||||
|
alt?: string;
|
||||||
|
fallback?: ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function IdpTypeIcon({
|
||||||
|
type,
|
||||||
|
variant,
|
||||||
|
size = 16,
|
||||||
|
className,
|
||||||
|
alt,
|
||||||
|
fallback = null
|
||||||
|
}: Props) {
|
||||||
|
const effectiveType = (variant || type || "").toLowerCase();
|
||||||
|
|
||||||
|
let src: string | null = null;
|
||||||
|
let defaultAlt = "";
|
||||||
|
|
||||||
|
if (effectiveType === "google") {
|
||||||
|
src = "/idp/google.png";
|
||||||
|
defaultAlt = "Google";
|
||||||
|
} else if (effectiveType === "azure") {
|
||||||
|
src = "/idp/azure.png";
|
||||||
|
defaultAlt = "Azure";
|
||||||
|
} else if (effectiveType === "oidc") {
|
||||||
|
src = "/idp/openid.png";
|
||||||
|
defaultAlt = "OAuth2/OIDC";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!src) {
|
||||||
|
return <>{fallback}</>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Image
|
||||||
|
src={src}
|
||||||
|
alt={alt ?? defaultAlt}
|
||||||
|
width={size}
|
||||||
|
height={size}
|
||||||
|
className={cn("shrink-0 rounded", className)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -27,7 +27,6 @@ import { LockIcon } from "lucide-react";
|
|||||||
import SecurityKeyAuthButton from "@app/components/SecurityKeyAuthButton";
|
import SecurityKeyAuthButton from "@app/components/SecurityKeyAuthButton";
|
||||||
import { createApiClient } from "@app/lib/api";
|
import { createApiClient } from "@app/lib/api";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import Image from "next/image";
|
|
||||||
import { GenerateOidcUrlResponse } from "@server/routers/idp";
|
import { GenerateOidcUrlResponse } from "@server/routers/idp";
|
||||||
import { Separator } from "./ui/separator";
|
import { Separator } from "./ui/separator";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
@@ -37,6 +36,7 @@ import {
|
|||||||
} from "@app/actions/server";
|
} from "@app/actions/server";
|
||||||
import { redirect as redirectTo } from "next/navigation";
|
import { redirect as redirectTo } from "next/navigation";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import IdpTypeIcon from "@app/components/IdpTypeIcon";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { loadReoScript } from "reodotdev";
|
import { loadReoScript } from "reodotdev";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
@@ -393,24 +393,7 @@ export default function LoginForm({
|
|||||||
loginWithIdp(idp.idpId);
|
loginWithIdp(idp.idpId);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{effectiveType === "google" && (
|
<IdpTypeIcon type={effectiveType} size={16} />
|
||||||
<Image
|
|
||||||
src="/idp/google.png"
|
|
||||||
alt="Google"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{effectiveType === "azure" && (
|
|
||||||
<Image
|
|
||||||
src="/idp/azure.png"
|
|
||||||
alt="Azure"
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<span>{idp.name}</span>
|
<span>{idp.name}</span>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
import { DataTable } from "@app/components/ui/data-table";
|
import {
|
||||||
|
DataTable,
|
||||||
|
type DataTableAddAction
|
||||||
|
} from "@app/components/ui/data-table";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
|
|
||||||
interface DataTableProps<TData, TValue> {
|
interface DataTableProps<TData, TValue> {
|
||||||
columns: ColumnDef<TData, TValue>[];
|
columns: ColumnDef<TData, TValue>[];
|
||||||
data: TData[];
|
data: TData[];
|
||||||
onAdd?: () => void;
|
onAdd?: () => void;
|
||||||
|
addActions?: DataTableAddAction[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function IdpDataTable<TData, TValue>({
|
export function IdpDataTable<TData, TValue>({
|
||||||
columns,
|
columns,
|
||||||
data,
|
data,
|
||||||
onAdd
|
onAdd,
|
||||||
|
addActions
|
||||||
}: DataTableProps<TData, TValue>) {
|
}: DataTableProps<TData, TValue>) {
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
@@ -27,6 +32,7 @@ export function IdpDataTable<TData, TValue>({
|
|||||||
searchColumn="name"
|
searchColumn="name"
|
||||||
addButtonText={t("idpAdd")}
|
addButtonText={t("idpAdd")}
|
||||||
onAdd={onAdd}
|
onAdd={onAdd}
|
||||||
|
addActions={addActions}
|
||||||
enableColumnVisibility={true}
|
enableColumnVisibility={true}
|
||||||
stickyRightColumn="actions"
|
stickyRightColumn="actions"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,13 +4,37 @@ import { ColumnDef } from "@tanstack/react-table";
|
|||||||
import { ExtendedColumnDef } from "@app/components/ui/data-table";
|
import { ExtendedColumnDef } from "@app/components/ui/data-table";
|
||||||
import { IdpDataTable } from "@app/components/OrgIdpDataTable";
|
import { IdpDataTable } from "@app/components/OrgIdpDataTable";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import { ArrowRight, ArrowUpDown, MoreHorizontal } from "lucide-react";
|
import {
|
||||||
import { useState } from "react";
|
Command,
|
||||||
|
CommandEmpty,
|
||||||
|
CommandGroup,
|
||||||
|
CommandInput,
|
||||||
|
CommandItem,
|
||||||
|
CommandList
|
||||||
|
} from "@app/components/ui/command";
|
||||||
|
import {
|
||||||
|
Credenza,
|
||||||
|
CredenzaBody,
|
||||||
|
CredenzaClose,
|
||||||
|
CredenzaContent,
|
||||||
|
CredenzaDescription,
|
||||||
|
CredenzaFooter,
|
||||||
|
CredenzaHeader,
|
||||||
|
CredenzaTitle
|
||||||
|
} from "@app/components/Credenza";
|
||||||
|
import {
|
||||||
|
ArrowRight,
|
||||||
|
ArrowUpDown,
|
||||||
|
KeyRound,
|
||||||
|
MoreHorizontal
|
||||||
|
} from "lucide-react";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
import { formatAxiosError } from "@app/lib/api";
|
import { formatAxiosError } from "@app/lib/api";
|
||||||
import { createApiClient } from "@app/lib/api";
|
import { createApiClient } from "@app/lib/api";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
|
import { useUserContext } from "@app/hooks/useUserContext";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@@ -21,6 +45,11 @@ import {
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import IdpTypeBadge from "@app/components/IdpTypeBadge";
|
import IdpTypeBadge from "@app/components/IdpTypeBadge";
|
||||||
|
import IdpTypeIcon from "@app/components/IdpTypeIcon";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { useDebounce } from "use-debounce";
|
||||||
|
import type { ListUserAdminOrgIdpsResponse } from "@server/routers/orgIdp/types";
|
||||||
|
import { cn } from "@app/lib/cn";
|
||||||
|
|
||||||
export type IdpRow = {
|
export type IdpRow = {
|
||||||
idpId: number;
|
idpId: number;
|
||||||
@@ -29,6 +58,15 @@ export type IdpRow = {
|
|||||||
variant?: string;
|
variant?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type AdminIdpRow = ListUserAdminOrgIdpsResponse["idps"][number];
|
||||||
|
|
||||||
|
function IdpImportRowIcon({
|
||||||
|
type,
|
||||||
|
variant
|
||||||
|
}: Pick<AdminIdpRow, "type" | "variant">) {
|
||||||
|
return <IdpTypeIcon type={type} variant={variant} size={20} />;
|
||||||
|
}
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
idps: IdpRow[];
|
idps: IdpRow[];
|
||||||
orgId: string;
|
orgId: string;
|
||||||
@@ -37,10 +75,48 @@ type Props = {
|
|||||||
export default function IdpTable({ idps, orgId }: Props) {
|
export default function IdpTable({ idps, orgId }: Props) {
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
const [selectedIdp, setSelectedIdp] = useState<IdpRow | null>(null);
|
const [selectedIdp, setSelectedIdp] = useState<IdpRow | null>(null);
|
||||||
|
const [isUnassociateModalOpen, setIsUnassociateModalOpen] = useState(false);
|
||||||
|
const [selectedUnassociateIdp, setSelectedUnassociateIdp] =
|
||||||
|
useState<IdpRow | null>(null);
|
||||||
|
const [importDialogOpen, setImportDialogOpen] = useState(false);
|
||||||
|
const [importSearchQuery, setImportSearchQuery] = useState("");
|
||||||
|
const [importSubmitting, setImportSubmitting] = useState(false);
|
||||||
|
const [debouncedImportSearch] = useDebounce(importSearchQuery, 150);
|
||||||
|
|
||||||
const api = createApiClient(useEnvContext());
|
const api = createApiClient(useEnvContext());
|
||||||
|
const { user } = useUserContext();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
|
const { data: adminIdpsRaw = [] } = useQuery({
|
||||||
|
queryKey: ["admin-org-idps", user.userId],
|
||||||
|
queryFn: async () => {
|
||||||
|
const res = await api.get<{
|
||||||
|
data: ListUserAdminOrgIdpsResponse;
|
||||||
|
}>(`/user/${user.userId}/admin-org-idps`);
|
||||||
|
return res.data.data.idps;
|
||||||
|
},
|
||||||
|
enabled: importDialogOpen && !!user?.userId
|
||||||
|
});
|
||||||
|
|
||||||
|
const importableIdps = useMemo(() => {
|
||||||
|
const localIds = new Set(idps.map((i) => i.idpId));
|
||||||
|
return adminIdpsRaw.filter(
|
||||||
|
(row) => row.orgId !== orgId && !localIds.has(row.idpId)
|
||||||
|
);
|
||||||
|
}, [adminIdpsRaw, orgId, idps]);
|
||||||
|
|
||||||
|
const shownImportIdps = useMemo(() => {
|
||||||
|
const q = debouncedImportSearch.trim().toLowerCase();
|
||||||
|
if (!q) {
|
||||||
|
return importableIdps;
|
||||||
|
}
|
||||||
|
return importableIdps.filter((row) => {
|
||||||
|
const hay = `${row.orgName} ${row.name}`.toLowerCase();
|
||||||
|
return hay.includes(q);
|
||||||
|
});
|
||||||
|
}, [importableIdps, debouncedImportSearch]);
|
||||||
|
|
||||||
const deleteIdp = async (idpId: number) => {
|
const deleteIdp = async (idpId: number) => {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/org/${orgId}/idp/${idpId}`);
|
await api.delete(`/org/${orgId}/idp/${idpId}`);
|
||||||
@@ -59,6 +135,49 @@ export default function IdpTable({ idps, orgId }: Props) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const importIdp = async (row: AdminIdpRow) => {
|
||||||
|
setImportSubmitting(true);
|
||||||
|
try {
|
||||||
|
await api.post(`/org/${orgId}/idp/${row.idpId}/import`, {
|
||||||
|
sourceOrgId: row.orgId
|
||||||
|
});
|
||||||
|
toast({
|
||||||
|
title: t("success"),
|
||||||
|
description: t("idpImportedDescription")
|
||||||
|
});
|
||||||
|
setImportDialogOpen(false);
|
||||||
|
setImportSearchQuery("");
|
||||||
|
router.refresh();
|
||||||
|
router.push(`/${orgId}/settings/idp/${row.idpId}/general`);
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setImportSubmitting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const unassociateIdp = async (idpId: number) => {
|
||||||
|
try {
|
||||||
|
await api.delete(`/org/${orgId}/idp/${idpId}/association`);
|
||||||
|
toast({
|
||||||
|
title: t("success"),
|
||||||
|
description: t("idpUnassociatedDescription")
|
||||||
|
});
|
||||||
|
setIsUnassociateModalOpen(false);
|
||||||
|
router.refresh();
|
||||||
|
} catch (e) {
|
||||||
|
toast({
|
||||||
|
title: t("error"),
|
||||||
|
description: formatAxiosError(e),
|
||||||
|
variant: "destructive"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const columns: ExtendedColumnDef<IdpRow>[] = [
|
const columns: ExtendedColumnDef<IdpRow>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "idpId",
|
accessorKey: "idpId",
|
||||||
@@ -142,6 +261,14 @@ export default function IdpTable({ idps, orgId }: Props) {
|
|||||||
{t("viewSettings")}
|
{t("viewSettings")}
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</Link>
|
</Link>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedUnassociateIdp(siteRow);
|
||||||
|
setIsUnassociateModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("idpUnassociateMenu")}
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedIdp(siteRow);
|
setSelectedIdp(siteRow);
|
||||||
@@ -149,7 +276,7 @@ export default function IdpTable({ idps, orgId }: Props) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="text-red-500">
|
<span className="text-red-500">
|
||||||
{t("delete")}
|
{t("idpDeleteAllOrgsMenu")}
|
||||||
</span>
|
</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
@@ -179,8 +306,8 @@ export default function IdpTable({ idps, orgId }: Props) {
|
|||||||
}}
|
}}
|
||||||
dialog={
|
dialog={
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<p>{t("idpQuestionRemove")}</p>
|
<p>{t("idpDeleteGlobalQuestion")}</p>
|
||||||
<p>{t("idpMessageRemove")}</p>
|
<p>{t("idpDeleteGlobalDescription")}</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
buttonText={t("idpConfirmDelete")}
|
buttonText={t("idpConfirmDelete")}
|
||||||
@@ -189,11 +316,122 @@ export default function IdpTable({ idps, orgId }: Props) {
|
|||||||
title={t("idpDelete")}
|
title={t("idpDelete")}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{selectedUnassociateIdp && (
|
||||||
|
<ConfirmDeleteDialog
|
||||||
|
open={isUnassociateModalOpen}
|
||||||
|
setOpen={(val) => {
|
||||||
|
setIsUnassociateModalOpen(val);
|
||||||
|
setSelectedUnassociateIdp(null);
|
||||||
|
}}
|
||||||
|
dialog={
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p>{t("idpUnassociateQuestion")}</p>
|
||||||
|
<p>{t("idpUnassociateDescription")}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
buttonText={t("idpUnassociateConfirm")}
|
||||||
|
onConfirm={async () =>
|
||||||
|
unassociateIdp(selectedUnassociateIdp.idpId)
|
||||||
|
}
|
||||||
|
string={selectedUnassociateIdp.name}
|
||||||
|
title={t("idpUnassociateTitle")}
|
||||||
|
warningText={t("idpUnassociateWarning")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Credenza
|
||||||
|
open={importDialogOpen}
|
||||||
|
onOpenChange={(open) => {
|
||||||
|
setImportDialogOpen(open);
|
||||||
|
if (!open) {
|
||||||
|
setImportSearchQuery("");
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CredenzaContent className="sm:max-w-lg">
|
||||||
|
<CredenzaHeader>
|
||||||
|
<CredenzaTitle>
|
||||||
|
{t("idpImportDialogTitle")}
|
||||||
|
</CredenzaTitle>
|
||||||
|
<CredenzaDescription>
|
||||||
|
{t("idpImportDialogDescription")}
|
||||||
|
</CredenzaDescription>
|
||||||
|
</CredenzaHeader>
|
||||||
|
<CredenzaBody
|
||||||
|
className={cn(
|
||||||
|
importSubmitting && "pointer-events-none opacity-60"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Command shouldFilter={false}>
|
||||||
|
<CommandInput
|
||||||
|
placeholder={t("idpImportSearchPlaceholder")}
|
||||||
|
value={importSearchQuery}
|
||||||
|
onValueChange={setImportSearchQuery}
|
||||||
|
/>
|
||||||
|
<CommandList>
|
||||||
|
<CommandEmpty>
|
||||||
|
{t("idpImportEmpty")}
|
||||||
|
</CommandEmpty>
|
||||||
|
<CommandGroup>
|
||||||
|
{shownImportIdps.map((row) => (
|
||||||
|
<CommandItem
|
||||||
|
key={`${row.idpId}:${row.orgId}`}
|
||||||
|
className="items-start gap-3 py-2.5"
|
||||||
|
value={`${row.idpId}:${row.orgId}:${row.orgName}:${row.name}`}
|
||||||
|
onSelect={() => {
|
||||||
|
void importIdp(row);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div className="mt-0.5 shrink-0">
|
||||||
|
<IdpImportRowIcon
|
||||||
|
type={row.type}
|
||||||
|
variant={row.variant}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="min-w-0 flex-1 text-left">
|
||||||
|
<div className="truncate font-medium leading-tight">
|
||||||
|
{row.orgName}
|
||||||
|
</div>
|
||||||
|
<div className="truncate text-sm leading-tight text-muted-foreground">
|
||||||
|
{row.name}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CommandItem>
|
||||||
|
))}
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
</Command>
|
||||||
|
</CredenzaBody>
|
||||||
|
<CredenzaFooter>
|
||||||
|
<CredenzaClose asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
disabled={importSubmitting}
|
||||||
|
>
|
||||||
|
{t("cancel")}
|
||||||
|
</Button>
|
||||||
|
</CredenzaClose>
|
||||||
|
</CredenzaFooter>
|
||||||
|
</CredenzaContent>
|
||||||
|
</Credenza>
|
||||||
|
|
||||||
<IdpDataTable
|
<IdpDataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={idps}
|
data={idps}
|
||||||
onAdd={() => router.push(`/${orgId}/settings/idp/create`)}
|
addActions={[
|
||||||
|
{
|
||||||
|
label: t("idpAddActionCreateNew"),
|
||||||
|
onSelect: () => {
|
||||||
|
router.push(`/${orgId}/settings/idp/create`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t("idpAddActionImportFromOrg"),
|
||||||
|
onSelect: () => {
|
||||||
|
setImportDialogOpen(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import {
|
|||||||
} from "@app/components/StrategySelect";
|
} from "@app/components/StrategySelect";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
import type { IdpOidcProviderType } from "@app/lib/idp/oidcIdpProviderDefaults";
|
import type { IdpOidcProviderType } from "@app/lib/idp/oidcIdpProviderDefaults";
|
||||||
|
import IdpTypeIcon from "@app/components/IdpTypeIcon";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Image from "next/image";
|
|
||||||
import { useEffect, useMemo } from "react";
|
import { useEffect, useMemo } from "react";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -32,7 +32,8 @@ export function OidcIdpProviderTypeSelect({ value, onTypeChange }: Props) {
|
|||||||
{
|
{
|
||||||
id: "oidc",
|
id: "oidc",
|
||||||
title: "OAuth2/OIDC",
|
title: "OAuth2/OIDC",
|
||||||
description: t("idpOidcDescription")
|
description: t("idpOidcDescription"),
|
||||||
|
icon: <IdpTypeIcon type="oidc" size={24} />
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
if (hideTemplates) {
|
if (hideTemplates) {
|
||||||
@@ -44,29 +45,13 @@ export function OidcIdpProviderTypeSelect({ value, onTypeChange }: Props) {
|
|||||||
id: "google",
|
id: "google",
|
||||||
title: t("idpGoogleTitle"),
|
title: t("idpGoogleTitle"),
|
||||||
description: t("idpGoogleDescription"),
|
description: t("idpGoogleDescription"),
|
||||||
icon: (
|
icon: <IdpTypeIcon type="google" size={24} />
|
||||||
<Image
|
|
||||||
src="/idp/google.png"
|
|
||||||
alt={t("idpGoogleAlt")}
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "azure",
|
id: "azure",
|
||||||
title: t("idpAzureTitle"),
|
title: t("idpAzureTitle"),
|
||||||
description: t("idpAzureDescription"),
|
description: t("idpAzureDescription"),
|
||||||
icon: (
|
icon: <IdpTypeIcon type="azure" size={24} />
|
||||||
<Image
|
|
||||||
src="/idp/azure.png"
|
|
||||||
alt={t("idpAzureAlt")}
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
className="rounded"
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}, [hideTemplates, t]);
|
}, [hideTemplates, t]);
|
||||||
|
|||||||
@@ -18,12 +18,14 @@ import {
|
|||||||
TableRow
|
TableRow
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { DataTablePagination } from "@app/components/DataTablePagination";
|
import { DataTablePagination } from "@app/components/DataTablePagination";
|
||||||
|
import type { DataTableAddAction } from "@app/components/ui/data-table";
|
||||||
import { Button } from "@app/components/ui/button";
|
import { Button } from "@app/components/ui/button";
|
||||||
import { Card, CardContent, CardHeader } from "@app/components/ui/card";
|
import { Card, CardContent, CardHeader } from "@app/components/ui/card";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuCheckboxItem,
|
DropdownMenuCheckboxItem,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger
|
||||||
@@ -31,7 +33,14 @@ import {
|
|||||||
import { Input } from "@app/components/ui/input";
|
import { Input } from "@app/components/ui/input";
|
||||||
import { useStoredColumnVisibility } from "@app/hooks/useStoredColumnVisibility";
|
import { useStoredColumnVisibility } from "@app/hooks/useStoredColumnVisibility";
|
||||||
|
|
||||||
import { Columns, Filter, Plus, RefreshCw, Search } from "lucide-react";
|
import {
|
||||||
|
ChevronDown,
|
||||||
|
Columns,
|
||||||
|
Filter,
|
||||||
|
Plus,
|
||||||
|
RefreshCw,
|
||||||
|
Search
|
||||||
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
|
||||||
@@ -67,6 +76,8 @@ type ControlledDataTableProps<TData, TValue> = {
|
|||||||
tableId: string;
|
tableId: string;
|
||||||
addButtonText?: string;
|
addButtonText?: string;
|
||||||
onAdd?: () => void;
|
onAdd?: () => void;
|
||||||
|
addActions?: DataTableAddAction[];
|
||||||
|
addButtonDisabled?: boolean;
|
||||||
onRefresh?: () => void;
|
onRefresh?: () => void;
|
||||||
isRefreshing?: boolean;
|
isRefreshing?: boolean;
|
||||||
refreshButtonDisabled?: boolean;
|
refreshButtonDisabled?: boolean;
|
||||||
@@ -90,6 +101,8 @@ export function ControlledDataTable<TData, TValue>({
|
|||||||
rows,
|
rows,
|
||||||
addButtonText,
|
addButtonText,
|
||||||
onAdd,
|
onAdd,
|
||||||
|
addActions,
|
||||||
|
addButtonDisabled = false,
|
||||||
onRefresh,
|
onRefresh,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
refreshButtonDisabled = false,
|
refreshButtonDisabled = false,
|
||||||
@@ -348,16 +361,49 @@ export function ControlledDataTable<TData, TValue>({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{onAdd && addButtonText && (
|
{addActions && addActions.length > 0 && addButtonText ? (
|
||||||
|
<div>
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
disabled={
|
||||||
|
addButtonDisabled ||
|
||||||
|
isNavigatingToAddPage
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
|
{addButtonText}
|
||||||
|
<ChevronDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
{addActions.map((action, i) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={i}
|
||||||
|
onSelect={() =>
|
||||||
|
action.onSelect()
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{action.label}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
onAdd &&
|
||||||
|
addButtonText && (
|
||||||
<div>
|
<div>
|
||||||
<Button
|
<Button
|
||||||
onClick={onAdd}
|
onClick={onAdd}
|
||||||
loading={isNavigatingToAddPage}
|
loading={isNavigatingToAddPage}
|
||||||
|
disabled={addButtonDisabled}
|
||||||
>
|
>
|
||||||
<Plus className="mr-2 h-4 w-4" />
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
{addButtonText}
|
{addButtonText}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import { Button } from "@app/components/ui/button";
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Input } from "@app/components/ui/input";
|
import { Input } from "@app/components/ui/input";
|
||||||
import { DataTablePagination } from "@app/components/DataTablePagination";
|
import { DataTablePagination } from "@app/components/DataTablePagination";
|
||||||
import { Plus, Search, RefreshCw, Columns, Filter } from "lucide-react";
|
import { ChevronDown, Plus, Search, RefreshCw, Columns, Filter } from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@@ -46,6 +46,7 @@ import {
|
|||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuCheckboxItem,
|
DropdownMenuCheckboxItem,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger
|
DropdownMenuTrigger
|
||||||
@@ -165,12 +166,20 @@ export type DataTablePaginationState = PaginationState & {
|
|||||||
|
|
||||||
export type DataTablePaginationUpdateFn = (newPage: PaginationState) => void;
|
export type DataTablePaginationUpdateFn = (newPage: PaginationState) => void;
|
||||||
|
|
||||||
|
/** When set (non-empty), replaces the single add button with a dropdown; `onAdd` is not used. */
|
||||||
|
export type DataTableAddAction = {
|
||||||
|
label: string;
|
||||||
|
onSelect: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
type DataTableProps<TData, TValue> = {
|
type DataTableProps<TData, TValue> = {
|
||||||
columns: ExtendedColumnDef<TData, TValue>[];
|
columns: ExtendedColumnDef<TData, TValue>[];
|
||||||
data: TData[];
|
data: TData[];
|
||||||
title?: string;
|
title?: string;
|
||||||
addButtonText?: string;
|
addButtonText?: string;
|
||||||
onAdd?: () => void;
|
onAdd?: () => void;
|
||||||
|
/** Prefer over `onAdd` when non-empty. */
|
||||||
|
addActions?: DataTableAddAction[];
|
||||||
addButtonDisabled?: boolean;
|
addButtonDisabled?: boolean;
|
||||||
onRefresh?: () => void;
|
onRefresh?: () => void;
|
||||||
isRefreshing?: boolean;
|
isRefreshing?: boolean;
|
||||||
@@ -205,6 +214,7 @@ export function DataTable<TData, TValue>({
|
|||||||
title,
|
title,
|
||||||
addButtonText,
|
addButtonText,
|
||||||
onAdd,
|
onAdd,
|
||||||
|
addActions,
|
||||||
addButtonDisabled = false,
|
addButtonDisabled = false,
|
||||||
onRefresh,
|
onRefresh,
|
||||||
isRefreshing,
|
isRefreshing,
|
||||||
@@ -637,13 +647,45 @@ export function DataTable<TData, TValue>({
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{onAdd && addButtonText && (
|
{addActions && addActions.length > 0 && addButtonText ? (
|
||||||
<div>
|
<div>
|
||||||
<Button onClick={onAdd} disabled={addButtonDisabled}>
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
disabled={addButtonDisabled}
|
||||||
|
>
|
||||||
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
|
{addButtonText}
|
||||||
|
<ChevronDown className="ml-2 h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end">
|
||||||
|
{addActions.map((action, i) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={i}
|
||||||
|
onSelect={() =>
|
||||||
|
action.onSelect()
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{action.label}
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
onAdd &&
|
||||||
|
addButtonText && (
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
onClick={onAdd}
|
||||||
|
disabled={addButtonDisabled}
|
||||||
|
>
|
||||||
<Plus className="mr-2 h-4 w-4" />
|
<Plus className="mr-2 h-4 w-4" />
|
||||||
{addButtonText}
|
{addButtonText}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|||||||
Reference in New Issue
Block a user