mirror of
https://github.com/andwati/dokploy.git
synced 2026-10-22 13:02:20 +00:00
feat(organization): allow setting a default role for new members
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { db } from "@dokploy/server/db";
|
||||
import { user } from "@dokploy/server/db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import {
|
||||
organization,
|
||||
organizationRole,
|
||||
user,
|
||||
} from "@dokploy/server/db/schema";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { getOrganizationOwnerId } from "./sso";
|
||||
|
||||
export const hasValidLicense = async (organizationId: string) => {
|
||||
@@ -22,3 +26,35 @@ export const hasValidLicense = async (organizationId: string) => {
|
||||
currentUser?.isValidEnterpriseLicense
|
||||
);
|
||||
};
|
||||
|
||||
export const resolveOrganizationDefaultRole = async (
|
||||
organizationId: string,
|
||||
) => {
|
||||
const org = await db.query.organization.findFirst({
|
||||
where: eq(organization.id, organizationId),
|
||||
columns: { defaultRole: true },
|
||||
});
|
||||
const defaultRole = org?.defaultRole;
|
||||
|
||||
if (!defaultRole || defaultRole === "owner") {
|
||||
return "member";
|
||||
}
|
||||
|
||||
if (defaultRole === "admin" || defaultRole === "member") {
|
||||
return defaultRole;
|
||||
}
|
||||
|
||||
const customRole = await db.query.organizationRole.findFirst({
|
||||
where: and(
|
||||
eq(organizationRole.organizationId, organizationId),
|
||||
eq(organizationRole.role, defaultRole),
|
||||
),
|
||||
columns: { id: true },
|
||||
});
|
||||
|
||||
if (!customRole || !(await hasValidLicense(organizationId))) {
|
||||
return "member";
|
||||
}
|
||||
|
||||
return defaultRole;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user