mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-08 07:25:22 +02:00
feat(git-provider): enhance sharing and permissions management
- Added functionality to toggle sharing of Git providers with the organization. - Introduced a new column "sharedWithOrganization" in the git_provider table to track sharing status. - Updated user permissions to include accessedGitProviders, allowing for more granular access control. - Enhanced API routes to support fetching accessible Git providers based on user roles and permissions. - Implemented UI components for managing Git provider sharing and permissions in the dashboard.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { db } from "@dokploy/server/db";
|
||||
import { gitProvider } from "@dokploy/server/db/schema";
|
||||
import { gitProvider, member } from "@dokploy/server/db/schema";
|
||||
import { hasValidLicense } from "@dokploy/server/services/proprietary/license-key";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
|
||||
export type GitProvider = typeof gitProvider.$inferSelect;
|
||||
|
||||
@@ -41,3 +42,51 @@ export const updateGitProvider = async (
|
||||
.returning()
|
||||
.then((response) => response[0]);
|
||||
};
|
||||
|
||||
export const getAccessibleGitProviderIds = async (session: {
|
||||
userId: string;
|
||||
activeOrganizationId: string;
|
||||
}): Promise<Set<string>> => {
|
||||
const { userId, activeOrganizationId } = session;
|
||||
|
||||
const allOrgProviders = await db.query.gitProvider.findMany({
|
||||
where: eq(gitProvider.organizationId, activeOrganizationId),
|
||||
columns: {
|
||||
gitProviderId: true,
|
||||
userId: true,
|
||||
sharedWithOrganization: true,
|
||||
},
|
||||
});
|
||||
|
||||
const memberRecord = await db.query.member.findFirst({
|
||||
where: and(
|
||||
eq(member.userId, userId),
|
||||
eq(member.organizationId, activeOrganizationId),
|
||||
),
|
||||
columns: { accessedGitProviders: true, role: true },
|
||||
});
|
||||
|
||||
if (
|
||||
memberRecord?.role === "owner" ||
|
||||
memberRecord?.role === "admin"
|
||||
) {
|
||||
return new Set(allOrgProviders.map((p) => p.gitProviderId));
|
||||
}
|
||||
|
||||
const licensed = await hasValidLicense(activeOrganizationId);
|
||||
const assignedSet = licensed
|
||||
? new Set(memberRecord?.accessedGitProviders ?? [])
|
||||
: new Set<string>();
|
||||
|
||||
const result = new Set<string>();
|
||||
for (const p of allOrgProviders) {
|
||||
if (
|
||||
p.userId === userId ||
|
||||
p.sharedWithOrganization ||
|
||||
assignedSet.has(p.gitProviderId)
|
||||
) {
|
||||
result.add(p.gitProviderId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user