mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-29 11:05:33 +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.
121 lines
2.9 KiB
TypeScript
121 lines
2.9 KiB
TypeScript
import {
|
|
createBitbucket,
|
|
findBitbucketById,
|
|
getAccessibleGitProviderIds,
|
|
getBitbucketBranches,
|
|
getBitbucketRepositories,
|
|
testBitbucketConnection,
|
|
updateBitbucket,
|
|
} 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 {
|
|
apiBitbucketTestConnection,
|
|
apiCreateBitbucket,
|
|
apiFindBitbucketBranches,
|
|
apiFindOneBitbucket,
|
|
apiUpdateBitbucket,
|
|
} from "@/server/db/schema";
|
|
|
|
export const bitbucketRouter = createTRPCRouter({
|
|
create: withPermission("gitProviders", "create")
|
|
.input(apiCreateBitbucket)
|
|
.mutation(async ({ input, ctx }) => {
|
|
try {
|
|
const result = await createBitbucket(
|
|
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 Bitbucket provider",
|
|
cause: error,
|
|
});
|
|
}
|
|
}),
|
|
one: protectedProcedure
|
|
.input(apiFindOneBitbucket)
|
|
.query(async ({ input }) => {
|
|
return await findBitbucketById(input.bitbucketId);
|
|
}),
|
|
bitbucketProviders: protectedProcedure.query(async ({ ctx }) => {
|
|
const accessibleIds = await getAccessibleGitProviderIds(ctx.session);
|
|
|
|
let result = await db.query.bitbucket.findMany({
|
|
with: {
|
|
gitProvider: true,
|
|
},
|
|
columns: {
|
|
bitbucketId: true,
|
|
},
|
|
});
|
|
|
|
result = result.filter((provider) => {
|
|
return (
|
|
provider.gitProvider.organizationId ===
|
|
ctx.session.activeOrganizationId &&
|
|
accessibleIds.has(provider.gitProvider.gitProviderId)
|
|
);
|
|
});
|
|
return result;
|
|
}),
|
|
|
|
getBitbucketRepositories: protectedProcedure
|
|
.input(apiFindOneBitbucket)
|
|
.query(async ({ input }) => {
|
|
return await getBitbucketRepositories(input.bitbucketId);
|
|
}),
|
|
getBitbucketBranches: protectedProcedure
|
|
.input(apiFindBitbucketBranches)
|
|
.query(async ({ input }) => {
|
|
return await getBitbucketBranches(input);
|
|
}),
|
|
testConnection: protectedProcedure
|
|
.input(apiBitbucketTestConnection)
|
|
.mutation(async ({ input }) => {
|
|
try {
|
|
const result = await testBitbucketConnection(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(apiUpdateBitbucket)
|
|
.mutation(async ({ input, ctx }) => {
|
|
const result = await updateBitbucket(input.bitbucketId, {
|
|
...input,
|
|
organizationId: ctx.session.activeOrganizationId,
|
|
});
|
|
|
|
await audit(ctx, {
|
|
action: "update",
|
|
resourceType: "gitProvider",
|
|
resourceId: input.bitbucketId,
|
|
resourceName: input.name,
|
|
});
|
|
|
|
return result;
|
|
}),
|
|
});
|