mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-21 22:05:23 +02:00
- 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.
138 lines
3.3 KiB
TypeScript
138 lines
3.3 KiB
TypeScript
import {
|
|
createGitlab,
|
|
findGitlabById,
|
|
getAccessibleGitProviderIds,
|
|
getGitlabBranches,
|
|
getGitlabRepositories,
|
|
haveGitlabRequirements,
|
|
testGitlabConnection,
|
|
updateGitlab,
|
|
updateGitProvider,
|
|
} from "@dokploy/server";
|
|
import { db } from "@dokploy/server/db";
|
|
import { TRPCError } from "@trpc/server";
|
|
import {
|
|
createTRPCRouter,
|
|
protectedProcedure,
|
|
withPermission,
|
|
} from "@/server/api/trpc";
|
|
import { audit } from "@/server/api/utils/audit";
|
|
import {
|
|
apiCreateGitlab,
|
|
apiFindGitlabBranches,
|
|
apiFindOneGitlab,
|
|
apiGitlabTestConnection,
|
|
apiUpdateGitlab,
|
|
} from "@/server/db/schema";
|
|
|
|
export const gitlabRouter = createTRPCRouter({
|
|
create: withPermission("gitProviders", "create")
|
|
.input(apiCreateGitlab)
|
|
.mutation(async ({ input, ctx }) => {
|
|
try {
|
|
const result = await createGitlab(
|
|
input,
|
|
ctx.session.activeOrganizationId,
|
|
ctx.session.userId,
|
|
);
|
|
|
|
await audit(ctx, {
|
|
action: "create",
|
|
resourceType: "gitProvider",
|
|
resourceName: input.name,
|
|
});
|
|
|
|
return result;
|
|
} catch (error) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: "Error creating this Gitlab provider",
|
|
cause: error,
|
|
});
|
|
}
|
|
}),
|
|
one: protectedProcedure.input(apiFindOneGitlab).query(async ({ input }) => {
|
|
return await findGitlabById(input.gitlabId);
|
|
}),
|
|
gitlabProviders: protectedProcedure.query(async ({ ctx }) => {
|
|
const accessibleIds = await getAccessibleGitProviderIds(ctx.session);
|
|
|
|
let result = await db.query.gitlab.findMany({
|
|
with: {
|
|
gitProvider: true,
|
|
},
|
|
});
|
|
|
|
result = result.filter((provider) => {
|
|
return (
|
|
provider.gitProvider.organizationId ===
|
|
ctx.session.activeOrganizationId &&
|
|
accessibleIds.has(provider.gitProvider.gitProviderId)
|
|
);
|
|
});
|
|
const filtered = result
|
|
.filter((provider) => haveGitlabRequirements(provider))
|
|
.map((provider) => {
|
|
return {
|
|
gitlabId: provider.gitlabId,
|
|
gitProvider: {
|
|
...provider.gitProvider,
|
|
},
|
|
gitlabUrl: provider.gitlabUrl,
|
|
};
|
|
});
|
|
|
|
return filtered;
|
|
}),
|
|
getGitlabRepositories: protectedProcedure
|
|
.input(apiFindOneGitlab)
|
|
.query(async ({ input }) => {
|
|
return await getGitlabRepositories(input.gitlabId);
|
|
}),
|
|
|
|
getGitlabBranches: protectedProcedure
|
|
.input(apiFindGitlabBranches)
|
|
.query(async ({ input }) => {
|
|
return await getGitlabBranches(input);
|
|
}),
|
|
testConnection: protectedProcedure
|
|
.input(apiGitlabTestConnection)
|
|
.mutation(async ({ input }) => {
|
|
try {
|
|
const result = await testGitlabConnection(input);
|
|
|
|
return `Found ${result} repositories`;
|
|
} catch (error) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message: error instanceof Error ? error?.message : `Error: ${error}`,
|
|
});
|
|
}
|
|
}),
|
|
update: withPermission("gitProviders", "create")
|
|
.input(apiUpdateGitlab)
|
|
.mutation(async ({ input, ctx }) => {
|
|
if (input.name) {
|
|
await updateGitProvider(input.gitProviderId, {
|
|
name: input.name,
|
|
organizationId: ctx.session.activeOrganizationId,
|
|
});
|
|
|
|
await updateGitlab(input.gitlabId, {
|
|
...input,
|
|
});
|
|
} else {
|
|
await updateGitlab(input.gitlabId, {
|
|
...input,
|
|
});
|
|
}
|
|
|
|
await audit(ctx, {
|
|
action: "update",
|
|
resourceType: "gitProvider",
|
|
resourceId: input.gitProviderId,
|
|
resourceName: input.name,
|
|
});
|
|
}),
|
|
});
|