mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
Refactor user role handling in TRPC context and routers
- Updated the user role property from `rol` to `role` across multiple TRPC context and router files to ensure consistency and clarity in role management. - Adjusted conditional checks for user roles in various procedures to reflect the updated property name, enhancing code readability and maintainability.
This commit is contained in:
parent
c13a68dab4
commit
1c73dab719
@ -163,7 +163,7 @@ export const aiRouter = createTRPCRouter({
|
|||||||
deploy: protectedProcedure
|
deploy: protectedProcedure
|
||||||
.input(deploySuggestionSchema)
|
.input(deploySuggestionSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -216,7 +216,7 @@ export const aiRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
ctx.user.ownerId,
|
ctx.user.ownerId,
|
||||||
|
@ -62,7 +62,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
.input(apiCreateApplication)
|
.input(apiCreateApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -87,7 +87,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const newApplication = await createApplication(input);
|
const newApplication = await createApplication(input);
|
||||||
|
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newApplication.applicationId,
|
newApplication.applicationId,
|
||||||
@ -109,7 +109,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.applicationId,
|
input.applicationId,
|
||||||
@ -168,7 +168,7 @@ export const applicationRouter = createTRPCRouter({
|
|||||||
delete: protectedProcedure
|
delete: protectedProcedure
|
||||||
.input(apiFindOneApplication)
|
.input(apiFindOneApplication)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.applicationId,
|
input.applicationId,
|
||||||
|
@ -62,7 +62,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
.input(apiCreateCompose)
|
.input(apiCreateCompose)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -86,7 +86,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
const newService = await createCompose(input);
|
const newService = await createCompose(input);
|
||||||
|
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newService.composeId,
|
newService.composeId,
|
||||||
@ -103,7 +103,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindCompose)
|
.input(apiFindCompose)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.composeId,
|
input.composeId,
|
||||||
@ -137,7 +137,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
delete: protectedProcedure
|
delete: protectedProcedure
|
||||||
.input(apiDeleteCompose)
|
.input(apiDeleteCompose)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.composeId,
|
input.composeId,
|
||||||
@ -408,7 +408,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -455,7 +455,7 @@ export const composeRouter = createTRPCRouter({
|
|||||||
isolatedDeployment: true,
|
isolatedDeployment: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
compose.composeId,
|
compose.composeId,
|
||||||
|
@ -41,7 +41,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
.input(apiCreateMariaDB)
|
.input(apiCreateMariaDB)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -65,7 +65,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const newMariadb = await createMariadb(input);
|
const newMariadb = await createMariadb(input);
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newMariadb.mariadbId,
|
newMariadb.mariadbId,
|
||||||
@ -92,7 +92,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneMariaDB)
|
.input(apiFindOneMariaDB)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.mariadbId,
|
input.mariadbId,
|
||||||
@ -219,7 +219,7 @@ export const mariadbRouter = createTRPCRouter({
|
|||||||
remove: protectedProcedure
|
remove: protectedProcedure
|
||||||
.input(apiFindOneMariaDB)
|
.input(apiFindOneMariaDB)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.mariadbId,
|
input.mariadbId,
|
||||||
|
@ -41,7 +41,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
.input(apiCreateMongo)
|
.input(apiCreateMongo)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -65,7 +65,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const newMongo = await createMongo(input);
|
const newMongo = await createMongo(input);
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newMongo.mongoId,
|
newMongo.mongoId,
|
||||||
@ -96,7 +96,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneMongo)
|
.input(apiFindOneMongo)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.mongoId,
|
input.mongoId,
|
||||||
@ -261,7 +261,7 @@ export const mongoRouter = createTRPCRouter({
|
|||||||
remove: protectedProcedure
|
remove: protectedProcedure
|
||||||
.input(apiFindOneMongo)
|
.input(apiFindOneMongo)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.mongoId,
|
input.mongoId,
|
||||||
|
@ -44,7 +44,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
.input(apiCreateMySql)
|
.input(apiCreateMySql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -69,7 +69,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newMysql = await createMysql(input);
|
const newMysql = await createMysql(input);
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newMysql.mysqlId,
|
newMysql.mysqlId,
|
||||||
@ -100,7 +100,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneMySql)
|
.input(apiFindOneMySql)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.mysqlId,
|
input.mysqlId,
|
||||||
@ -260,7 +260,7 @@ export const mysqlRouter = createTRPCRouter({
|
|||||||
remove: protectedProcedure
|
remove: protectedProcedure
|
||||||
.input(apiFindOneMySql)
|
.input(apiFindOneMySql)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.mysqlId,
|
input.mysqlId,
|
||||||
|
@ -15,7 +15,7 @@ export const organizationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
if (ctx.user.rol !== "owner" && !IS_CLOUD) {
|
if (ctx.user.role !== "owner" && !IS_CLOUD) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "FORBIDDEN",
|
code: "FORBIDDEN",
|
||||||
message: "Only the organization owner can create an organization",
|
message: "Only the organization owner can create an organization",
|
||||||
@ -86,7 +86,7 @@ export const organizationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
if (ctx.user.rol !== "owner" && !IS_CLOUD) {
|
if (ctx.user.role !== "owner" && !IS_CLOUD) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "FORBIDDEN",
|
code: "FORBIDDEN",
|
||||||
message: "Only the organization owner can update it",
|
message: "Only the organization owner can update it",
|
||||||
@ -109,7 +109,7 @@ export const organizationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
if (ctx.user.rol !== "owner" && !IS_CLOUD) {
|
if (ctx.user.role !== "owner" && !IS_CLOUD) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "FORBIDDEN",
|
code: "FORBIDDEN",
|
||||||
message: "Only the organization owner can delete it",
|
message: "Only the organization owner can delete it",
|
||||||
|
@ -41,7 +41,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
.input(apiCreatePostgres)
|
.input(apiCreatePostgres)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -65,7 +65,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const newPostgres = await createPostgres(input);
|
const newPostgres = await createPostgres(input);
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newPostgres.postgresId,
|
newPostgres.postgresId,
|
||||||
@ -96,7 +96,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOnePostgres)
|
.input(apiFindOnePostgres)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.postgresId,
|
input.postgresId,
|
||||||
@ -244,7 +244,7 @@ export const postgresRouter = createTRPCRouter({
|
|||||||
remove: protectedProcedure
|
remove: protectedProcedure
|
||||||
.input(apiFindOnePostgres)
|
.input(apiFindOnePostgres)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.postgresId,
|
input.postgresId,
|
||||||
|
@ -57,7 +57,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
.input(apiCreateProject)
|
.input(apiCreateProject)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkProjectAccess(
|
await checkProjectAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
"create",
|
"create",
|
||||||
@ -78,7 +78,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
input,
|
input,
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
);
|
);
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewProject(
|
await addNewProject(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
project.projectId,
|
project.projectId,
|
||||||
@ -99,7 +99,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneProject)
|
.input(apiFindOneProject)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
const { accessedServices } = await findMemberById(
|
const { accessedServices } = await findMemberById(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
@ -118,15 +118,15 @@ export const projectRouter = createTRPCRouter({
|
|||||||
eq(projects.organizationId, ctx.session.activeOrganizationId),
|
eq(projects.organizationId, ctx.session.activeOrganizationId),
|
||||||
),
|
),
|
||||||
with: {
|
with: {
|
||||||
compose: {
|
|
||||||
where: buildServiceFilter(compose.composeId, accessedServices),
|
|
||||||
},
|
|
||||||
applications: {
|
applications: {
|
||||||
where: buildServiceFilter(
|
where: buildServiceFilter(
|
||||||
applications.applicationId,
|
applications.applicationId,
|
||||||
accessedServices,
|
accessedServices,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
compose: {
|
||||||
|
where: buildServiceFilter(compose.composeId, accessedServices),
|
||||||
|
},
|
||||||
mariadb: {
|
mariadb: {
|
||||||
where: buildServiceFilter(mariadb.mariadbId, accessedServices),
|
where: buildServiceFilter(mariadb.mariadbId, accessedServices),
|
||||||
},
|
},
|
||||||
@ -164,8 +164,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
return project;
|
return project;
|
||||||
}),
|
}),
|
||||||
all: protectedProcedure.query(async ({ ctx }) => {
|
all: protectedProcedure.query(async ({ ctx }) => {
|
||||||
// console.log(ctx.user);
|
if (ctx.user.role === "member") {
|
||||||
if (ctx.user.rol === "member") {
|
|
||||||
const { accessedProjects, accessedServices } = await findMemberById(
|
const { accessedProjects, accessedServices } = await findMemberById(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
@ -175,7 +174,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = await db.query.projects.findMany({
|
return await db.query.projects.findMany({
|
||||||
where: and(
|
where: and(
|
||||||
sql`${projects.projectId} IN (${sql.join(
|
sql`${projects.projectId} IN (${sql.join(
|
||||||
accessedProjects.map((projectId) => sql`${projectId}`),
|
accessedProjects.map((projectId) => sql`${projectId}`),
|
||||||
@ -213,8 +212,6 @@ export const projectRouter = createTRPCRouter({
|
|||||||
},
|
},
|
||||||
orderBy: desc(projects.createdAt),
|
orderBy: desc(projects.createdAt),
|
||||||
});
|
});
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return await db.query.projects.findMany({
|
return await db.query.projects.findMany({
|
||||||
@ -244,7 +241,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
.input(apiRemoveProject)
|
.input(apiRemoveProject)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkProjectAccess(
|
await checkProjectAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
"delete",
|
"delete",
|
||||||
@ -316,7 +313,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkProjectAccess(
|
await checkProjectAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
"create",
|
"create",
|
||||||
@ -581,7 +578,7 @@ export const projectRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewProject(
|
await addNewProject(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newProject.projectId,
|
newProject.projectId,
|
||||||
@ -604,10 +601,10 @@ function buildServiceFilter(
|
|||||||
fieldName: AnyPgColumn,
|
fieldName: AnyPgColumn,
|
||||||
accessedServices: string[],
|
accessedServices: string[],
|
||||||
) {
|
) {
|
||||||
return accessedServices.length > 0
|
return accessedServices.length === 0
|
||||||
? sql`${fieldName} IN (${sql.join(
|
? sql`false`
|
||||||
|
: sql`${fieldName} IN (${sql.join(
|
||||||
accessedServices.map((serviceId) => sql`${serviceId}`),
|
accessedServices.map((serviceId) => sql`${serviceId}`),
|
||||||
sql`, `,
|
sql`, `,
|
||||||
)})`
|
)})`;
|
||||||
: sql`1 = 0`;
|
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiCreateRedis)
|
.input(apiCreateRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.projectId,
|
input.projectId,
|
||||||
@ -65,7 +65,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const newRedis = await createRedis(input);
|
const newRedis = await createRedis(input);
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await addNewService(
|
await addNewService(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
newRedis.redisId,
|
newRedis.redisId,
|
||||||
@ -89,7 +89,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneRedis)
|
.input(apiFindOneRedis)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.redisId,
|
input.redisId,
|
||||||
@ -251,7 +251,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
remove: protectedProcedure
|
remove: protectedProcedure
|
||||||
.input(apiFindOneRedis)
|
.input(apiFindOneRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
await checkServiceAccess(
|
await checkServiceAccess(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
input.redisId,
|
input.redisId,
|
||||||
|
@ -407,7 +407,7 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
.input(apiServerSchema)
|
.input(apiServerSchema)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
try {
|
try {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
const canAccess = await canAccessToTraefikFiles(
|
const canAccess = await canAccessToTraefikFiles(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
@ -428,7 +428,7 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
updateTraefikFile: protectedProcedure
|
updateTraefikFile: protectedProcedure
|
||||||
.input(apiModifyTraefikConfig)
|
.input(apiModifyTraefikConfig)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
const canAccess = await canAccessToTraefikFiles(
|
const canAccess = await canAccessToTraefikFiles(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
@ -449,7 +449,7 @@ export const settingsRouter = createTRPCRouter({
|
|||||||
readTraefikFile: protectedProcedure
|
readTraefikFile: protectedProcedure
|
||||||
.input(apiReadTraefikConfig)
|
.input(apiReadTraefikConfig)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
if (ctx.user.rol === "member") {
|
if (ctx.user.role === "member") {
|
||||||
const canAccess = await canAccessToTraefikFiles(
|
const canAccess = await canAccessToTraefikFiles(
|
||||||
ctx.user.id,
|
ctx.user.id,
|
||||||
ctx.session.activeOrganizationId,
|
ctx.session.activeOrganizationId,
|
||||||
|
@ -30,7 +30,7 @@ import { ZodError } from "zod";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
interface CreateContextOptions {
|
interface CreateContextOptions {
|
||||||
user: (User & { rol: "member" | "admin" | "owner"; ownerId: string }) | null;
|
user: (User & { role: "member" | "admin" | "owner"; ownerId: string }) | null;
|
||||||
session: (Session & { activeOrganizationId: string }) | null;
|
session: (Session & { activeOrganizationId: string }) | null;
|
||||||
req: CreateNextContextOptions["req"];
|
req: CreateNextContextOptions["req"];
|
||||||
res: CreateNextContextOptions["res"];
|
res: CreateNextContextOptions["res"];
|
||||||
@ -83,7 +83,7 @@ export const createTRPCContext = async (opts: CreateNextContextOptions) => {
|
|||||||
? {
|
? {
|
||||||
...user,
|
...user,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
rol: user.role as "owner" | "member" | "admin",
|
role: user.role as "owner" | "member" | "admin",
|
||||||
id: user.id,
|
id: user.id,
|
||||||
ownerId: user.ownerId,
|
ownerId: user.ownerId,
|
||||||
}
|
}
|
||||||
@ -180,7 +180,7 @@ export const uploadProcedure = async (opts: any) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const cliProcedure = t.procedure.use(({ ctx, next }) => {
|
export const cliProcedure = t.procedure.use(({ ctx, next }) => {
|
||||||
if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") {
|
if (!ctx.session || !ctx.user || ctx.user.role !== "owner") {
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||||
}
|
}
|
||||||
return next({
|
return next({
|
||||||
@ -194,7 +194,7 @@ export const cliProcedure = t.procedure.use(({ ctx, next }) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const adminProcedure = t.procedure.use(({ ctx, next }) => {
|
export const adminProcedure = t.procedure.use(({ ctx, next }) => {
|
||||||
if (!ctx.session || !ctx.user || ctx.user.rol !== "owner") {
|
if (!ctx.session || !ctx.user || ctx.user.role !== "owner") {
|
||||||
throw new TRPCError({ code: "UNAUTHORIZED" });
|
throw new TRPCError({ code: "UNAUTHORIZED" });
|
||||||
}
|
}
|
||||||
return next({
|
return next({
|
||||||
|
Loading…
Reference in New Issue
Block a user