mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-24 12:48:47 +00:00
refactor: update database service components to utilize environment context for project name and organization authorization checks
This commit is contained in:
+2
-2
@@ -69,7 +69,7 @@ const Mariadb = (
|
|||||||
list={[
|
list={[
|
||||||
{ name: "Projects", href: "/dashboard/projects" },
|
{ name: "Projects", href: "/dashboard/projects" },
|
||||||
{
|
{
|
||||||
name: data?.project?.name || "",
|
name: data?.environment?.project?.name || "",
|
||||||
href: `/dashboard/project/${projectId}`,
|
href: `/dashboard/project/${projectId}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -81,7 +81,7 @@ const Mariadb = (
|
|||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<Head>
|
<Head>
|
||||||
<title>
|
<title>
|
||||||
Database: {data?.name} - {data?.project.name} | Dokploy
|
Database: {data?.name} - {data?.environment?.project?.name} | Dokploy
|
||||||
</title>
|
</title>
|
||||||
</Head>
|
</Head>
|
||||||
<Card className="h-full bg-sidebar p-2.5 rounded-xl w-full">
|
<Card className="h-full bg-sidebar p-2.5 rounded-xl w-full">
|
||||||
|
|||||||
+2
-2
@@ -69,7 +69,7 @@ const Mongo = (
|
|||||||
list={[
|
list={[
|
||||||
{ name: "Projects", href: "/dashboard/projects" },
|
{ name: "Projects", href: "/dashboard/projects" },
|
||||||
{
|
{
|
||||||
name: data?.project?.name || "",
|
name: data?.environment?.project?.name || "",
|
||||||
href: `/dashboard/project/${projectId}`,
|
href: `/dashboard/project/${projectId}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ const Mongo = (
|
|||||||
/>
|
/>
|
||||||
<Head>
|
<Head>
|
||||||
<title>
|
<title>
|
||||||
Database: {data?.name} - {data?.project.name} | Dokploy
|
Database: {data?.name} - {data?.environment?.project?.name} | Dokploy
|
||||||
</title>
|
</title>
|
||||||
</Head>
|
</Head>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
|
|||||||
+2
-2
@@ -68,7 +68,7 @@ const MySql = (
|
|||||||
list={[
|
list={[
|
||||||
{ name: "Projects", href: "/dashboard/projects" },
|
{ name: "Projects", href: "/dashboard/projects" },
|
||||||
{
|
{
|
||||||
name: data?.project?.name || "",
|
name: data?.environment?.project?.name || "",
|
||||||
href: `/dashboard/project/${projectId}`,
|
href: `/dashboard/project/${projectId}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ const MySql = (
|
|||||||
<div className="flex flex-col gap-4">
|
<div className="flex flex-col gap-4">
|
||||||
<Head>
|
<Head>
|
||||||
<title>
|
<title>
|
||||||
Database: {data?.name} - {data?.project.name} | Dokploy
|
Database: {data?.name} - {data?.environment?.project?.name} | Dokploy
|
||||||
</title>
|
</title>
|
||||||
</Head>
|
</Head>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
|
|||||||
+2
-2
@@ -68,7 +68,7 @@ const Postgresql = (
|
|||||||
list={[
|
list={[
|
||||||
{ name: "Projects", href: "/dashboard/projects" },
|
{ name: "Projects", href: "/dashboard/projects" },
|
||||||
{
|
{
|
||||||
name: data?.project?.name || "",
|
name: data?.environment?.project?.name || "",
|
||||||
href: `/dashboard/project/${projectId}`,
|
href: `/dashboard/project/${projectId}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -79,7 +79,7 @@ const Postgresql = (
|
|||||||
/>
|
/>
|
||||||
<Head>
|
<Head>
|
||||||
<title>
|
<title>
|
||||||
Database: {data?.name} - {data?.project.name} | Dokploy
|
Database: {data?.name} - {data?.environment?.project?.name} | Dokploy
|
||||||
</title>
|
</title>
|
||||||
</Head>
|
</Head>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
|
|||||||
+2
-2
@@ -68,7 +68,7 @@ const Redis = (
|
|||||||
list={[
|
list={[
|
||||||
{ name: "Projects", href: "/dashboard/projects" },
|
{ name: "Projects", href: "/dashboard/projects" },
|
||||||
{
|
{
|
||||||
name: data?.project?.name || "",
|
name: data?.environment?.project?.name || "",
|
||||||
href: `/dashboard/project/${projectId}`,
|
href: `/dashboard/project/${projectId}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -79,7 +79,7 @@ const Redis = (
|
|||||||
/>
|
/>
|
||||||
<Head>
|
<Head>
|
||||||
<title>
|
<title>
|
||||||
Database: {data?.name} - {data?.project.name} | Dokploy
|
Database: {data?.name} - {data?.environment?.project?.name} | Dokploy
|
||||||
</title>
|
</title>
|
||||||
</Head>
|
</Head>
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to access this Redis",
|
message: "You are not authorized to access this Redis",
|
||||||
@@ -117,7 +117,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneRedis)
|
.input(apiFindOneRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to start this Redis",
|
message: "You are not authorized to start this Redis",
|
||||||
@@ -139,7 +139,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiResetRedis)
|
.input(apiResetRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to reload this Redis",
|
message: "You are not authorized to reload this Redis",
|
||||||
@@ -169,7 +169,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiFindOneRedis)
|
.input(apiFindOneRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to stop this Redis",
|
message: "You are not authorized to stop this Redis",
|
||||||
@@ -190,7 +190,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiSaveExternalPortRedis)
|
.input(apiSaveExternalPortRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findRedisById(input.redisId);
|
const mongo = await findRedisById(input.redisId);
|
||||||
if (mongo.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this external port",
|
message: "You are not authorized to save this external port",
|
||||||
@@ -206,7 +206,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiDeployRedis)
|
.input(apiDeployRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Redis",
|
message: "You are not authorized to deploy this Redis",
|
||||||
@@ -226,7 +226,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiDeployRedis)
|
.input(apiDeployRedis)
|
||||||
.subscription(async ({ input, ctx }) => {
|
.subscription(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to deploy this Redis",
|
message: "You are not authorized to deploy this Redis",
|
||||||
@@ -242,7 +242,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiChangeRedisStatus)
|
.input(apiChangeRedisStatus)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const mongo = await findRedisById(input.redisId);
|
const mongo = await findRedisById(input.redisId);
|
||||||
if (mongo.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (mongo.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to change this Redis status",
|
message: "You are not authorized to change this Redis status",
|
||||||
@@ -267,7 +267,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
|
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
|
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to delete this Redis",
|
message: "You are not authorized to delete this Redis",
|
||||||
@@ -290,7 +290,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiSaveEnvironmentVariablesRedis)
|
.input(apiSaveEnvironmentVariablesRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to save this environment",
|
message: "You are not authorized to save this environment",
|
||||||
@@ -335,7 +335,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
)
|
)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to move this redis",
|
message: "You are not authorized to move this redis",
|
||||||
@@ -373,7 +373,7 @@ export const redisRouter = createTRPCRouter({
|
|||||||
.input(apiRebuildRedis)
|
.input(apiRebuildRedis)
|
||||||
.mutation(async ({ input, ctx }) => {
|
.mutation(async ({ input, ctx }) => {
|
||||||
const redis = await findRedisById(input.redisId);
|
const redis = await findRedisById(input.redisId);
|
||||||
if (redis.project.organizationId !== ctx.session.activeOrganizationId) {
|
if (redis.environment.project.organizationId !== ctx.session.activeOrganizationId) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "UNAUTHORIZED",
|
code: "UNAUTHORIZED",
|
||||||
message: "You are not authorized to rebuild this Redis database",
|
message: "You are not authorized to rebuild this Redis database",
|
||||||
|
|||||||
@@ -52,7 +52,11 @@ export const findRedisById = async (redisId: string) => {
|
|||||||
const result = await db.query.redis.findFirst({
|
const result = await db.query.redis.findFirst({
|
||||||
where: eq(redis.redisId, redisId),
|
where: eq(redis.redisId, redisId),
|
||||||
with: {
|
with: {
|
||||||
project: true,
|
environment: {
|
||||||
|
with: {
|
||||||
|
project: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
mounts: true,
|
mounts: true,
|
||||||
server: true,
|
server: true,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user