mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor(cloud): add validation to prevent access to resources from another admin
This commit is contained in:
@@ -20,9 +20,9 @@ import { TRPCError } from "@trpc/server";
|
|||||||
export const bitbucketRouter = createTRPCRouter({
|
export const bitbucketRouter = createTRPCRouter({
|
||||||
create: protectedProcedure
|
create: protectedProcedure
|
||||||
.input(apiCreateBitbucket)
|
.input(apiCreateBitbucket)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createBitbucket(input);
|
return await createBitbucket(input, ctx.user.adminId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -74,7 +74,10 @@ export const bitbucketRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(apiUpdateBitbucket)
|
.input(apiUpdateBitbucket)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
return await updateBitbucket(input.bitbucketId, input);
|
return await updateBitbucket(input.bitbucketId, {
|
||||||
|
...input,
|
||||||
|
adminId: ctx.user.adminId,
|
||||||
|
});
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,9 +15,18 @@ import {
|
|||||||
} from "@dokploy/builders";
|
} from "@dokploy/builders";
|
||||||
|
|
||||||
export const githubRouter = createTRPCRouter({
|
export const githubRouter = createTRPCRouter({
|
||||||
one: protectedProcedure.input(apiFindOneGithub).query(async ({ input }) => {
|
one: protectedProcedure
|
||||||
return await findGithubById(input.githubId);
|
.input(apiFindOneGithub)
|
||||||
}),
|
.query(async ({ input, ctx }) => {
|
||||||
|
const githubProvider = await findGithubById(input.githubId);
|
||||||
|
// if (githubProvider.gitProvider.adminId !== ctx.user.adminId) { //TODO: Remove this line when the cloud version is ready
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not allowed to access this github provider",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
return githubProvider;
|
||||||
|
}),
|
||||||
getGithubRepositories: protectedProcedure
|
getGithubRepositories: protectedProcedure
|
||||||
.input(apiFindOneGithub)
|
.input(apiFindOneGithub)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
@@ -64,9 +73,17 @@ export const githubRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(apiUpdateGithub)
|
.input(apiUpdateGithub)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
|
const githubProvider = await findGithubById(input.githubId);
|
||||||
|
// if (githubProvider.gitProvider.adminId !== ctx.user.adminId) { //TODO: Remove this line when the cloud version is ready
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not allowed to access this github provider",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
await updateGitProvider(input.gitProviderId, {
|
await updateGitProvider(input.gitProviderId, {
|
||||||
name: input.name,
|
name: input.name,
|
||||||
|
adminId: ctx.user.adminId,
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ import {
|
|||||||
export const gitlabRouter = createTRPCRouter({
|
export const gitlabRouter = createTRPCRouter({
|
||||||
create: protectedProcedure
|
create: protectedProcedure
|
||||||
.input(apiCreateGitlab)
|
.input(apiCreateGitlab)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createGitlab(input);
|
return await createGitlab(input, ctx.user.adminId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -83,13 +83,16 @@ export const gitlabRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(apiUpdateGitlab)
|
.input(apiUpdateGitlab)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
if (input.name) {
|
if (input.name) {
|
||||||
await updateGitProvider(input.gitProviderId, {
|
await updateGitProvider(input.gitProviderId, {
|
||||||
name: input.name,
|
name: input.name,
|
||||||
|
adminId: ctx.user.adminId,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await updateGitlab(input.gitlabId, input);
|
await updateGitlab(input.gitlabId, {
|
||||||
|
...input,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
notifications,
|
notifications,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { desc } from "drizzle-orm";
|
import { desc, eq } from "drizzle-orm";
|
||||||
import {
|
import {
|
||||||
createDiscordNotification,
|
createDiscordNotification,
|
||||||
createEmailNotification,
|
createEmailNotification,
|
||||||
@@ -39,14 +39,14 @@ import {
|
|||||||
sendTelegramNotification,
|
sendTelegramNotification,
|
||||||
} from "@dokploy/builders";
|
} from "@dokploy/builders";
|
||||||
|
|
||||||
|
// TODO: Uncomment the validations when is cloud ready
|
||||||
export const notificationRouter = createTRPCRouter({
|
export const notificationRouter = createTRPCRouter({
|
||||||
createSlack: adminProcedure
|
createSlack: adminProcedure
|
||||||
.input(apiCreateSlack)
|
.input(apiCreateSlack)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createSlackNotification(input);
|
return await createSlackNotification(input, ctx.user.adminId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Error to create the notification",
|
message: "Error to create the notification",
|
||||||
@@ -56,15 +56,21 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
updateSlack: adminProcedure
|
updateSlack: adminProcedure
|
||||||
.input(apiUpdateSlack)
|
.input(apiUpdateSlack)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await updateSlackNotification(input);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
} catch (error) {
|
// if (notification.adminId !== ctx.user.adminId) {
|
||||||
throw new TRPCError({
|
// throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
// code: "UNAUTHORIZED",
|
||||||
message: "Error to update the notification",
|
// message: "You are not authorized to update this notification",
|
||||||
cause: error,
|
// });
|
||||||
|
// }
|
||||||
|
return await updateSlackNotification({
|
||||||
|
...input,
|
||||||
|
adminId: ctx.user.adminId,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
testSlackConnection: adminProcedure
|
testSlackConnection: adminProcedure
|
||||||
@@ -86,9 +92,9 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
createTelegram: adminProcedure
|
createTelegram: adminProcedure
|
||||||
.input(apiCreateTelegram)
|
.input(apiCreateTelegram)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createTelegramNotification(input);
|
return await createTelegramNotification(input, ctx.user.adminId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -100,9 +106,19 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
|
|
||||||
updateTelegram: adminProcedure
|
updateTelegram: adminProcedure
|
||||||
.input(apiUpdateTelegram)
|
.input(apiUpdateTelegram)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await updateTelegramNotification(input);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
|
// if (notification.adminId !== ctx.user.adminId) {
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not authorized to update this notification",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
return await updateTelegramNotification({
|
||||||
|
...input,
|
||||||
|
adminId: ctx.user.adminId,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -127,7 +143,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
createDiscord: adminProcedure
|
createDiscord: adminProcedure
|
||||||
.input(apiCreateDiscord)
|
.input(apiCreateDiscord)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
// go to your discord server
|
// go to your discord server
|
||||||
// go to settings
|
// go to settings
|
||||||
@@ -135,7 +151,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
// add a new integration
|
// add a new integration
|
||||||
// select webhook
|
// select webhook
|
||||||
// copy the webhook url
|
// copy the webhook url
|
||||||
return await createDiscordNotification(input);
|
return await createDiscordNotification(input, ctx.user.adminId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -147,9 +163,19 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
|
|
||||||
updateDiscord: adminProcedure
|
updateDiscord: adminProcedure
|
||||||
.input(apiUpdateDiscord)
|
.input(apiUpdateDiscord)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await updateDiscordNotification(input);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
|
// if (notification.adminId !== ctx.user.adminId) {
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not authorized to update this notification",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
return await updateDiscordNotification({
|
||||||
|
...input,
|
||||||
|
adminId: ctx.user.adminId,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -178,11 +204,10 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
createEmail: adminProcedure
|
createEmail: adminProcedure
|
||||||
.input(apiCreateEmail)
|
.input(apiCreateEmail)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await createEmailNotification(input);
|
return await createEmailNotification(input, ctx.user.adminId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Error to create the notification",
|
message: "Error to create the notification",
|
||||||
@@ -192,9 +217,19 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
updateEmail: adminProcedure
|
updateEmail: adminProcedure
|
||||||
.input(apiUpdateEmail)
|
.input(apiUpdateEmail)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
return await updateEmailNotification(input);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
|
// if (notification.adminId !== ctx.user.adminId) {
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not authorized to update this notification",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
return await updateEmailNotification({
|
||||||
|
...input,
|
||||||
|
adminId: ctx.user.adminId,
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
@@ -223,8 +258,15 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
remove: adminProcedure
|
remove: adminProcedure
|
||||||
.input(apiFindOneNotification)
|
.input(apiFindOneNotification)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
|
const notification = await findNotificationById(input.notificationId);
|
||||||
|
// if (notification.adminId !== ctx.user.adminId) {
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not authorized to delete this notification",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
return await removeNotificationById(input.notificationId);
|
return await removeNotificationById(input.notificationId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -235,11 +277,17 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneNotification)
|
.input(apiFindOneNotification)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
const notification = await findNotificationById(input.notificationId);
|
const notification = await findNotificationById(input.notificationId);
|
||||||
|
// if (notification.adminId !== ctx.user.adminId) {
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not authorized to access this notification",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
return notification;
|
return notification;
|
||||||
}),
|
}),
|
||||||
all: adminProcedure.query(async () => {
|
all: adminProcedure.query(async ({ ctx }) => {
|
||||||
return await db.query.notifications.findMany({
|
return await db.query.notifications.findMany({
|
||||||
with: {
|
with: {
|
||||||
slack: true,
|
slack: true,
|
||||||
@@ -248,6 +296,7 @@ export const notificationRouter = createTRPCRouter({
|
|||||||
email: true,
|
email: true,
|
||||||
},
|
},
|
||||||
orderBy: desc(notifications.createdAt),
|
orderBy: desc(notifications.createdAt),
|
||||||
|
// where: eq(notifications.adminId, ctx.user.adminId),
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ export const serverRouter = createTRPCRouter({
|
|||||||
const project = await createServer(input, ctx.user.adminId);
|
const project = await createServer(input, ctx.user.adminId);
|
||||||
return project;
|
return project;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "BAD_REQUEST",
|
code: "BAD_REQUEST",
|
||||||
message: "Error to create the server",
|
message: "Error to create the server",
|
||||||
@@ -47,7 +46,15 @@ export const serverRouter = createTRPCRouter({
|
|||||||
one: protectedProcedure
|
one: protectedProcedure
|
||||||
.input(apiFindOneServer)
|
.input(apiFindOneServer)
|
||||||
.query(async ({ input, ctx }) => {
|
.query(async ({ input, ctx }) => {
|
||||||
return await findServerById(input.serverId);
|
const server = await findServerById(input.serverId);
|
||||||
|
if (server.adminId !== ctx.user.adminId) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You are not authorized to access this server",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return server;
|
||||||
}),
|
}),
|
||||||
all: protectedProcedure.query(async ({ ctx }) => {
|
all: protectedProcedure.query(async ({ ctx }) => {
|
||||||
const result = await db
|
const result = await db
|
||||||
@@ -69,7 +76,7 @@ export const serverRouter = createTRPCRouter({
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}),
|
}),
|
||||||
withSSHKey: protectedProcedure.query(async ({ input, ctx }) => {
|
withSSHKey: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return await db.query.server.findMany({
|
return await db.query.server.findMany({
|
||||||
orderBy: desc(server.createdAt),
|
orderBy: desc(server.createdAt),
|
||||||
where: and(
|
where: and(
|
||||||
@@ -82,20 +89,30 @@ export const serverRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneServer)
|
.input(apiFindOneServer)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
|
const server = await findServerById(input.serverId);
|
||||||
|
if (server.adminId !== ctx.user.adminId) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You are not authorized to setup this server",
|
||||||
|
});
|
||||||
|
}
|
||||||
const currentServer = await serverSetup(input.serverId);
|
const currentServer = await serverSetup(input.serverId);
|
||||||
return currentServer;
|
return currentServer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw error;
|
||||||
code: "BAD_REQUEST",
|
|
||||||
message: "Error to setup this server",
|
|
||||||
cause: error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
remove: protectedProcedure
|
remove: protectedProcedure
|
||||||
.input(apiRemoveServer)
|
.input(apiRemoveServer)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
|
const server = await findServerById(input.serverId);
|
||||||
|
if (server.adminId !== ctx.user.adminId) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You are not authorized to delete this server",
|
||||||
|
});
|
||||||
|
}
|
||||||
const activeServers = await haveActiveServices(input.serverId);
|
const activeServers = await haveActiveServices(input.serverId);
|
||||||
|
|
||||||
if (activeServers) {
|
if (activeServers) {
|
||||||
@@ -110,28 +127,27 @@ export const serverRouter = createTRPCRouter({
|
|||||||
|
|
||||||
return currentServer;
|
return currentServer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw error;
|
||||||
code: "BAD_REQUEST",
|
|
||||||
message: "Error to delete this server",
|
|
||||||
cause: error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(apiUpdateServer)
|
.input(apiUpdateServer)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
|
const server = await findServerById(input.serverId);
|
||||||
|
if (server.adminId !== ctx.user.adminId) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You are not authorized to update this server",
|
||||||
|
});
|
||||||
|
}
|
||||||
const currentServer = await updateServerById(input.serverId, {
|
const currentServer = await updateServerById(input.serverId, {
|
||||||
...input,
|
...input,
|
||||||
});
|
});
|
||||||
|
|
||||||
return currentServer;
|
return currentServer;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw error;
|
||||||
code: "BAD_REQUEST",
|
|
||||||
message: "Error to update this server",
|
|
||||||
cause: error,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import {
|
|||||||
removeSSHKeyById,
|
removeSSHKeyById,
|
||||||
updateSSHKeyById,
|
updateSSHKeyById,
|
||||||
} from "@dokploy/builders";
|
} from "@dokploy/builders";
|
||||||
import { eq } from "drizzle-orm";
|
|
||||||
|
|
||||||
export const sshRouter = createTRPCRouter({
|
export const sshRouter = createTRPCRouter({
|
||||||
create: protectedProcedure
|
create: protectedProcedure
|
||||||
@@ -37,24 +36,38 @@ export const sshRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
remove: protectedProcedure
|
remove: protectedProcedure
|
||||||
.input(apiRemoveSshKey)
|
.input(apiRemoveSshKey)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
|
const sshKey = await findSSHKeyById(input.sshKeyId);
|
||||||
|
// if (sshKey.adminId !== ctx.user.adminId) {
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not allowed to delete this ssh key",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
return await removeSSHKeyById(input.sshKeyId);
|
return await removeSSHKeyById(input.sshKeyId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw error;
|
||||||
code: "BAD_REQUEST",
|
|
||||||
message: "Error to delete this ssh key",
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
one: protectedProcedure.input(apiFindOneSshKey).query(async ({ input }) => {
|
one: protectedProcedure
|
||||||
const sshKey = await findSSHKeyById(input.sshKeyId);
|
.input(apiFindOneSshKey)
|
||||||
return sshKey;
|
.query(async ({ input, ctx }) => {
|
||||||
}),
|
const sshKey = await findSSHKeyById(input.sshKeyId);
|
||||||
|
|
||||||
|
if (sshKey.adminId !== ctx.user.adminId) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "UNAUTHORIZED",
|
||||||
|
message: "You are not allowed to access this ssh key",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return sshKey;
|
||||||
|
}),
|
||||||
all: protectedProcedure.query(async ({ ctx }) => {
|
all: protectedProcedure.query(async ({ ctx }) => {
|
||||||
return await db.query.sshKeys.findMany({
|
return await db.query.sshKeys.findMany({});
|
||||||
where: eq(sshKeys.adminId, ctx.user.adminId),
|
// return await db.query.sshKeys.findMany({
|
||||||
});
|
// where: eq(sshKeys.adminId, ctx.user.adminId),
|
||||||
|
// }); // TODO: Remove this line when the cloud version is ready
|
||||||
}),
|
}),
|
||||||
generate: protectedProcedure
|
generate: protectedProcedure
|
||||||
.input(apiGenerateSSHKey)
|
.input(apiGenerateSSHKey)
|
||||||
@@ -63,8 +76,15 @@ export const sshRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
update: protectedProcedure
|
update: protectedProcedure
|
||||||
.input(apiUpdateSshKey)
|
.input(apiUpdateSshKey)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
try {
|
try {
|
||||||
|
const sshKey = await findSSHKeyById(input.sshKeyId);
|
||||||
|
// if (sshKey.adminId !== ctx.user.adminId) {
|
||||||
|
// throw new TRPCError({
|
||||||
|
// code: "UNAUTHORIZED",
|
||||||
|
// message: "You are not allowed to update this ssh key",
|
||||||
|
// });
|
||||||
|
// }
|
||||||
return await updateSSHKeyById(input);
|
return await updateSSHKeyById(input);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { pgEnum, pgTable, text } from "drizzle-orm/pg-core";
|
|||||||
import { createInsertSchema } from "drizzle-zod";
|
import { createInsertSchema } from "drizzle-zod";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { auth } from "./auth";
|
|
||||||
import { bitbucket } from "./bitbucket";
|
import { bitbucket } from "./bitbucket";
|
||||||
import { github } from "./github";
|
import { github } from "./github";
|
||||||
import { gitlab } from "./gitlab";
|
import { gitlab } from "./gitlab";
|
||||||
|
import { admins } from "./admin";
|
||||||
|
|
||||||
export const gitProviderType = pgEnum("gitProviderType", [
|
export const gitProviderType = pgEnum("gitProviderType", [
|
||||||
"github",
|
"github",
|
||||||
@@ -24,9 +24,9 @@ export const gitProvider = pgTable("git_provider", {
|
|||||||
createdAt: text("createdAt")
|
createdAt: text("createdAt")
|
||||||
.notNull()
|
.notNull()
|
||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
authId: text("authId")
|
adminId: text("adminId").references(() => admins.adminId, {
|
||||||
.notNull()
|
onDelete: "cascade",
|
||||||
.references(() => auth.id, { onDelete: "cascade" }),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
|
export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
|
||||||
@@ -42,9 +42,9 @@ export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
|
|||||||
fields: [gitProvider.gitProviderId],
|
fields: [gitProvider.gitProviderId],
|
||||||
references: [bitbucket.gitProviderId],
|
references: [bitbucket.gitProviderId],
|
||||||
}),
|
}),
|
||||||
auth: one(auth, {
|
admin: one(admins, {
|
||||||
fields: [gitProvider.authId],
|
fields: [gitProvider.adminId],
|
||||||
references: [auth.id],
|
references: [admins.adminId],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { boolean, integer, pgEnum, pgTable, text } from "drizzle-orm/pg-core";
|
|||||||
import { createInsertSchema } from "drizzle-zod";
|
import { createInsertSchema } from "drizzle-zod";
|
||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
import { admins } from "./admin";
|
||||||
|
|
||||||
export const notificationType = pgEnum("notificationType", [
|
export const notificationType = pgEnum("notificationType", [
|
||||||
"slack",
|
"slack",
|
||||||
@@ -38,6 +39,9 @@ export const notifications = pgTable("notification", {
|
|||||||
emailId: text("emailId").references(() => email.emailId, {
|
emailId: text("emailId").references(() => email.emailId, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
}),
|
}),
|
||||||
|
adminId: text("adminId").references(() => admins.adminId, {
|
||||||
|
onDelete: "cascade",
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const slack = pgTable("slack", {
|
export const slack = pgTable("slack", {
|
||||||
@@ -96,6 +100,10 @@ export const notificationsRelations = relations(notifications, ({ one }) => ({
|
|||||||
fields: [notifications.emailId],
|
fields: [notifications.emailId],
|
||||||
references: [email.emailId],
|
references: [email.emailId],
|
||||||
}),
|
}),
|
||||||
|
admin: one(admins, {
|
||||||
|
fields: [notifications.adminId],
|
||||||
|
references: [admins.adminId],
|
||||||
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const notificationsSchema = createInsertSchema(notifications);
|
export const notificationsSchema = createInsertSchema(notifications);
|
||||||
@@ -118,6 +126,7 @@ export const apiCreateSlack = notificationsSchema
|
|||||||
export const apiUpdateSlack = apiCreateSlack.partial().extend({
|
export const apiUpdateSlack = apiCreateSlack.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
slackId: z.string(),
|
slackId: z.string(),
|
||||||
|
adminId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestSlackConnection = apiCreateSlack.pick({
|
export const apiTestSlackConnection = apiCreateSlack.pick({
|
||||||
@@ -143,6 +152,7 @@ export const apiCreateTelegram = notificationsSchema
|
|||||||
export const apiUpdateTelegram = apiCreateTelegram.partial().extend({
|
export const apiUpdateTelegram = apiCreateTelegram.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
telegramId: z.string().min(1),
|
telegramId: z.string().min(1),
|
||||||
|
adminId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestTelegramConnection = apiCreateTelegram.pick({
|
export const apiTestTelegramConnection = apiCreateTelegram.pick({
|
||||||
@@ -167,6 +177,7 @@ export const apiCreateDiscord = notificationsSchema
|
|||||||
export const apiUpdateDiscord = apiCreateDiscord.partial().extend({
|
export const apiUpdateDiscord = apiCreateDiscord.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
discordId: z.string().min(1),
|
discordId: z.string().min(1),
|
||||||
|
adminId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestDiscordConnection = apiCreateDiscord.pick({
|
export const apiTestDiscordConnection = apiCreateDiscord.pick({
|
||||||
@@ -195,6 +206,7 @@ export const apiCreateEmail = notificationsSchema
|
|||||||
export const apiUpdateEmail = apiCreateEmail.partial().extend({
|
export const apiUpdateEmail = apiCreateEmail.partial().extend({
|
||||||
notificationId: z.string().min(1),
|
notificationId: z.string().min(1),
|
||||||
emailId: z.string().min(1),
|
emailId: z.string().min(1),
|
||||||
|
adminId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const apiTestEmailConnection = apiCreateEmail.pick({
|
export const apiTestEmailConnection = apiCreateEmail.pick({
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ export type Bitbucket = typeof bitbucket.$inferSelect;
|
|||||||
|
|
||||||
export const createBitbucket = async (
|
export const createBitbucket = async (
|
||||||
input: typeof apiCreateBitbucket._type,
|
input: typeof apiCreateBitbucket._type,
|
||||||
|
adminId: string,
|
||||||
) => {
|
) => {
|
||||||
return await db.transaction(async (tx) => {
|
return await db.transaction(async (tx) => {
|
||||||
const newGitProvider = await tx
|
const newGitProvider = await tx
|
||||||
.insert(gitProvider)
|
.insert(gitProvider)
|
||||||
.values({
|
.values({
|
||||||
providerType: "bitbucket",
|
providerType: "bitbucket",
|
||||||
authId: input.authId,
|
adminId: adminId,
|
||||||
name: input.name,
|
name: input.name,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
@@ -73,11 +74,12 @@ export const updateBitbucket = async (
|
|||||||
.where(eq(bitbucket.bitbucketId, bitbucketId))
|
.where(eq(bitbucket.bitbucketId, bitbucketId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
if (input.name) {
|
if (input.name || input.adminId) {
|
||||||
await tx
|
await tx
|
||||||
.update(gitProvider)
|
.update(gitProvider)
|
||||||
.set({
|
.set({
|
||||||
name: input.name,
|
name: input.name,
|
||||||
|
adminId: input.adminId,
|
||||||
})
|
})
|
||||||
.where(eq(gitProvider.gitProviderId, input.gitProviderId))
|
.where(eq(gitProvider.gitProviderId, input.gitProviderId))
|
||||||
.returning();
|
.returning();
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import { type apiCreateDestination, destinations } from "@/server/db/schema";
|
import { type apiCreateDestination, destinations } from "@/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { and, eq } from "drizzle-orm";
|
||||||
import { findAdmin } from "./admin";
|
|
||||||
|
|
||||||
export type Destination = typeof destinations.$inferSelect;
|
export type Destination = typeof destinations.$inferSelect;
|
||||||
|
|
||||||
export const createDestintation = async (
|
export const createDestintation = async (
|
||||||
input: typeof apiCreateDestination._type,
|
input: typeof apiCreateDestination._type,
|
||||||
|
adminId: string,
|
||||||
) => {
|
) => {
|
||||||
const adminResponse = await findAdmin();
|
|
||||||
const newDestination = await db
|
const newDestination = await db
|
||||||
.insert(destinations)
|
.insert(destinations)
|
||||||
.values({
|
.values({
|
||||||
...input,
|
...input,
|
||||||
adminId: adminResponse.adminId,
|
adminId: adminId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -31,7 +30,7 @@ export const createDestintation = async (
|
|||||||
|
|
||||||
export const findDestinationById = async (destinationId: string) => {
|
export const findDestinationById = async (destinationId: string) => {
|
||||||
const destination = await db.query.destinations.findFirst({
|
const destination = await db.query.destinations.findFirst({
|
||||||
where: eq(destinations.destinationId, destinationId),
|
where: and(eq(destinations.destinationId, destinationId)),
|
||||||
});
|
});
|
||||||
if (!destination) {
|
if (!destination) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
@@ -42,10 +41,18 @@ export const findDestinationById = async (destinationId: string) => {
|
|||||||
return destination;
|
return destination;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeDestinationById = async (destinationId: string) => {
|
export const removeDestinationById = async (
|
||||||
|
destinationId: string,
|
||||||
|
adminId: string,
|
||||||
|
) => {
|
||||||
const result = await db
|
const result = await db
|
||||||
.delete(destinations)
|
.delete(destinations)
|
||||||
.where(eq(destinations.destinationId, destinationId))
|
.where(
|
||||||
|
and(
|
||||||
|
eq(destinations.destinationId, destinationId),
|
||||||
|
eq(destinations.adminId, adminId),
|
||||||
|
),
|
||||||
|
)
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
return result[0];
|
return result[0];
|
||||||
@@ -60,7 +67,12 @@ export const updateDestinationById = async (
|
|||||||
.set({
|
.set({
|
||||||
...destinationData,
|
...destinationData,
|
||||||
})
|
})
|
||||||
.where(eq(destinations.destinationId, destinationId))
|
.where(
|
||||||
|
and(
|
||||||
|
eq(destinations.destinationId, destinationId),
|
||||||
|
eq(destinations.adminId, destinationData.adminId || ""),
|
||||||
|
),
|
||||||
|
)
|
||||||
.returning();
|
.returning();
|
||||||
|
|
||||||
return result[0];
|
return result[0];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { db } from "@/server/db";
|
import { db } from "@/server/db";
|
||||||
import { type apiCreateGithub, gitProvider, github } from "@/server/db/schema";
|
import { gitProvider } from "@/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
@@ -14,6 +14,20 @@ export const removeGitProvider = async (gitProviderId: string) => {
|
|||||||
return result[0];
|
return result[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const findGitProviderById = async (gitProviderId: string) => {
|
||||||
|
const result = await db.query.gitProvider.findFirst({
|
||||||
|
where: eq(gitProvider.gitProviderId, gitProviderId),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "NOT_FOUND",
|
||||||
|
message: "Git Provider not found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export const updateGitProvider = async (
|
export const updateGitProvider = async (
|
||||||
gitProviderId: string,
|
gitProviderId: string,
|
||||||
input: Partial<GitProvider>,
|
input: Partial<GitProvider>,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export type Notification = typeof notifications.$inferSelect;
|
|||||||
|
|
||||||
export const createSlackNotification = async (
|
export const createSlackNotification = async (
|
||||||
input: typeof apiCreateSlack._type,
|
input: typeof apiCreateSlack._type,
|
||||||
|
adminId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newSlack = await tx
|
const newSlack = await tx
|
||||||
@@ -50,6 +51,7 @@ export const createSlackNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "slack",
|
notificationType: "slack",
|
||||||
|
adminId: adminId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -78,6 +80,7 @@ export const updateSlackNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
|
adminId: input.adminId,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
.returning()
|
.returning()
|
||||||
@@ -106,6 +109,7 @@ export const updateSlackNotification = async (
|
|||||||
|
|
||||||
export const createTelegramNotification = async (
|
export const createTelegramNotification = async (
|
||||||
input: typeof apiCreateTelegram._type,
|
input: typeof apiCreateTelegram._type,
|
||||||
|
adminId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newTelegram = await tx
|
const newTelegram = await tx
|
||||||
@@ -135,6 +139,7 @@ export const createTelegramNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "telegram",
|
notificationType: "telegram",
|
||||||
|
adminId: adminId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -163,6 +168,7 @@ export const updateTelegramNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
|
adminId: input.adminId,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
.returning()
|
.returning()
|
||||||
@@ -191,6 +197,7 @@ export const updateTelegramNotification = async (
|
|||||||
|
|
||||||
export const createDiscordNotification = async (
|
export const createDiscordNotification = async (
|
||||||
input: typeof apiCreateDiscord._type,
|
input: typeof apiCreateDiscord._type,
|
||||||
|
adminId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newDiscord = await tx
|
const newDiscord = await tx
|
||||||
@@ -219,6 +226,7 @@ export const createDiscordNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "discord",
|
notificationType: "discord",
|
||||||
|
adminId: adminId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -247,6 +255,7 @@ export const updateDiscordNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
|
adminId: input.adminId,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
.returning()
|
.returning()
|
||||||
@@ -274,6 +283,7 @@ export const updateDiscordNotification = async (
|
|||||||
|
|
||||||
export const createEmailNotification = async (
|
export const createEmailNotification = async (
|
||||||
input: typeof apiCreateEmail._type,
|
input: typeof apiCreateEmail._type,
|
||||||
|
adminId: string,
|
||||||
) => {
|
) => {
|
||||||
await db.transaction(async (tx) => {
|
await db.transaction(async (tx) => {
|
||||||
const newEmail = await tx
|
const newEmail = await tx
|
||||||
@@ -307,6 +317,7 @@ export const createEmailNotification = async (
|
|||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
notificationType: "email",
|
notificationType: "email",
|
||||||
|
adminId: adminId,
|
||||||
})
|
})
|
||||||
.returning()
|
.returning()
|
||||||
.then((value) => value[0]);
|
.then((value) => value[0]);
|
||||||
@@ -335,6 +346,7 @@ export const updateEmailNotification = async (
|
|||||||
databaseBackup: input.databaseBackup,
|
databaseBackup: input.databaseBackup,
|
||||||
dokployRestart: input.dokployRestart,
|
dokployRestart: input.dokployRestart,
|
||||||
dockerCleanup: input.dockerCleanup,
|
dockerCleanup: input.dockerCleanup,
|
||||||
|
adminId: input.adminId,
|
||||||
})
|
})
|
||||||
.where(eq(notifications.notificationId, input.notificationId))
|
.where(eq(notifications.notificationId, input.notificationId))
|
||||||
.returning()
|
.returning()
|
||||||
|
|||||||
Reference in New Issue
Block a user