feat: add canCreateEnvironments permission for environment creation - Add database field and API validation - Implement permission checking in environment creation - Add UI toggle in user permissions modal - Hide create button for unauthorized users Fixes #2593

This commit is contained in:
HarikrishnanD
2025-09-12 17:56:02 +05:30
parent 24729f35ec
commit 30b28afbac
11 changed files with 13275 additions and 23 deletions
+10 -3
View File
@@ -1,6 +1,7 @@
import {
addNewEnvironment,
checkEnvironmentAccess,
checkEnvironmentCreationPermission,
createEnvironment,
deleteEnvironment,
duplicateEnvironment,
@@ -54,9 +55,12 @@ export const environmentRouter = createTRPCRouter({
.input(apiCreateEnvironment)
.mutation(async ({ input, ctx }) => {
try {
// Check if user has access to the project
// This would typically involve checking project ownership/membership
// For now, we'll use a basic organization check
// Check if user has permission to create environments
await checkEnvironmentCreationPermission(
ctx.user.id,
input.projectId,
ctx.session.activeOrganizationId,
);
if (input.name === "production") {
throw new TRPCError({
@@ -76,6 +80,9 @@ export const environmentRouter = createTRPCRouter({
}
return environment;
} catch (error) {
if (error instanceof TRPCError) {
throw error;
}
throw new TRPCError({
code: "BAD_REQUEST",
message: `Error creating the environment: ${error instanceof Error ? error.message : error}`,