refactor(channels): add default channel protection in DB, API and UI settings modal
This commit is contained in:
parent
942fce0e63
commit
2325c5725e
4 changed files with 30 additions and 9 deletions
|
|
@ -49,6 +49,14 @@ export async function PATCH(
|
|||
return NextResponse.json({ error: "Channel not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
// Protect the default channel from changes
|
||||
if (existingChannel.isDefault) {
|
||||
return NextResponse.json(
|
||||
{ error: "The default channel cannot be edited." },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
// Check if the user is a member of the server
|
||||
const [member] = await db
|
||||
.select()
|
||||
|
|
@ -114,6 +122,14 @@ export async function DELETE(
|
|||
return NextResponse.json({ error: "Channel not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
// Protect default channel from deletion
|
||||
if (existingChannel.isDefault) {
|
||||
return NextResponse.json(
|
||||
{ error: "The default channel cannot be deleted." },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
// Check if the user is a member of the server
|
||||
const [member] = await db
|
||||
.select()
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ export async function POST(req: Request) {
|
|||
.values({
|
||||
name: "general",
|
||||
serverId: server.id,
|
||||
isDefault: true,
|
||||
})
|
||||
.returning();
|
||||
|
||||
|
|
|
|||
|
|
@ -114,15 +114,17 @@ export function ChannelSidebar() {
|
|||
</div>
|
||||
|
||||
{/* Gear Button */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => handleOpenSettings(e, channel)}
|
||||
className="opacity-0 group-hover:opacity-100 p-1 text-muted hover:text-white focus:outline-none transition-all cursor-pointer"
|
||||
aria-label="Channel Settings"
|
||||
title="Channel Settings"
|
||||
>
|
||||
<Settings className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
{!channel.isDefault && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => handleOpenSettings(e, channel)}
|
||||
className="opacity-0 group-hover:opacity-100 p-1 text-muted hover:text-white focus:outline-none transition-all cursor-pointer"
|
||||
aria-label="Channel Settings"
|
||||
title="Channel Settings"
|
||||
>
|
||||
<Settings className="w-3.5 h-3.5" />
|
||||
</button>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
import { relations } from "drizzle-orm";
|
||||
import {
|
||||
boolean,
|
||||
pgEnum,
|
||||
pgTable,
|
||||
text,
|
||||
|
|
@ -88,6 +89,7 @@ export const channels = pgTable("channels", {
|
|||
serverId: uuid("server_id")
|
||||
.references(() => servers.id, { onDelete: "cascade" })
|
||||
.notNull(),
|
||||
isDefault: boolean("is_default").default(false).notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue