-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat(roles): ✨ add create and edit role functionality with multi-language support #710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
aXenDeveloper
merged 1 commit into
canary
from
feat(roles)--✨-add-create-and-edit-role-functionality-with-multi-language-support
Jul 13, 2026
The head ref may contain hidden characters: "feat(roles)--\u2728-add-create-and-edit-role-functionality-with-multi-language-support"
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
packages/vitnode/src/api/modules/admin/roles/roles.admin.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| import { buildModule } from "@/api/lib/module"; | ||
| import { CONFIG_PLUGIN } from "@/config"; | ||
|
|
||
| import { createRoleAdminRoute } from "./routes/create.route"; | ||
| import { listRolesAdminRoute } from "./routes/list.route"; | ||
| import { showRoleAdminRoute } from "./routes/show.route"; | ||
| import { updateRoleAdminRoute } from "./routes/update.route"; | ||
|
|
||
| export const rolesAdminModule = buildModule({ | ||
| pluginId: CONFIG_PLUGIN.pluginId, | ||
| name: "roles", | ||
| routes: [listRolesAdminRoute, showRoleAdminRoute], | ||
| routes: [ | ||
| listRolesAdminRoute, | ||
| showRoleAdminRoute, | ||
| createRoleAdminRoute, | ||
| updateRoleAdminRoute, | ||
| ], | ||
| }); |
73 changes: 73 additions & 0 deletions
73
packages/vitnode/src/api/modules/admin/roles/routes/create.route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { z } from "@hono/zod-openapi"; | ||
|
|
||
| import { buildRoute } from "@/api/lib/route"; | ||
| import { saveLanguageWords } from "@/api/lib/save-language-words"; | ||
| import { CONFIG_PLUGIN } from "@/config"; | ||
| import { core_roles } from "@/database/roles"; | ||
|
|
||
| // Role names are not a column on `core_roles` - every translation lives in | ||
| // `core_languages_words`, so the name is the full list of per-language values. | ||
| export const zodRoleNameSchema = z | ||
| .array( | ||
| z.object({ | ||
| languageCode: z.string(), | ||
| value: z.string().min(1).max(255), | ||
| }), | ||
| ) | ||
| .min(1); | ||
|
|
||
| export const zodCreateRoleAdminSchema = z.object({ | ||
| name: zodRoleNameSchema, | ||
| color: z.string().max(19).optional(), | ||
| }); | ||
|
|
||
| export const createRoleAdminRoute = buildRoute({ | ||
| pluginId: CONFIG_PLUGIN.pluginId, | ||
| route: { | ||
| method: "post", | ||
| description: "Create a new role (Admin only)", | ||
| path: "/create", | ||
| request: { | ||
| body: { | ||
| required: true, | ||
| content: { | ||
| "application/json": { | ||
| schema: zodCreateRoleAdminSchema, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| responses: { | ||
| 201: { | ||
| content: { | ||
| "application/json": { | ||
| schema: z.object({ id: z.number() }), | ||
| }, | ||
| }, | ||
| description: "Role created", | ||
| }, | ||
| 403: { | ||
| description: "Access Denied", | ||
| }, | ||
| }, | ||
| }, | ||
| handler: async c => { | ||
| const { name, color } = c.req.valid("json"); | ||
|
|
||
| const [role] = await c | ||
| .get("db") | ||
| .insert(core_roles) | ||
| .values({ color: color?.trim() ? color : null, updatedAt: new Date() }) | ||
|
aXenDeveloper marked this conversation as resolved.
|
||
| .returning({ id: core_roles.id }); | ||
|
|
||
| await saveLanguageWords(c, { | ||
| pluginCode: "core", | ||
| tableName: "core_roles", | ||
| variable: "name", | ||
| itemId: role.id, | ||
| values: name, | ||
| }); | ||
|
|
||
| return c.json({ id: role.id }, 201); | ||
| }, | ||
| }); | ||
103 changes: 103 additions & 0 deletions
103
packages/vitnode/src/api/modules/admin/roles/routes/update.route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import { z } from "@hono/zod-openapi"; | ||
| import { eq } from "drizzle-orm"; | ||
|
|
||
| import { buildRoute } from "@/api/lib/route"; | ||
| import { saveLanguageWords } from "@/api/lib/save-language-words"; | ||
| import { CONFIG_PLUGIN } from "@/config"; | ||
| import { core_roles } from "@/database/roles"; | ||
|
|
||
| import { zodRoleNameSchema } from "./create.route"; | ||
|
|
||
| export const zodUpdateRoleAdminSchema = z | ||
| .object({ | ||
| name: zodRoleNameSchema, | ||
| color: z.string().max(19), | ||
| }) | ||
| .partial() | ||
| .refine(body => Object.values(body).some(value => value !== undefined), { | ||
| message: "At least one field is required", | ||
| }); | ||
|
|
||
| export const updateRoleAdminRoute = buildRoute({ | ||
| pluginId: CONFIG_PLUGIN.pluginId, | ||
| route: { | ||
| method: "patch", | ||
| description: "Update a role by id (Admin only)", | ||
| path: "/{id}", | ||
| request: { | ||
| params: z.object({ | ||
| id: z.string().openapi({ example: "1" }), | ||
| }), | ||
| body: { | ||
| required: true, | ||
| content: { | ||
| "application/json": { | ||
| schema: zodUpdateRoleAdminSchema, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| responses: { | ||
| 200: { | ||
| content: { | ||
| "application/json": { | ||
| schema: z.object({ id: z.number() }), | ||
| }, | ||
| }, | ||
| description: "Role updated", | ||
| }, | ||
| 403: { | ||
| description: "Access Denied", | ||
| }, | ||
| 404: { | ||
| content: { | ||
| "application/json": { | ||
| schema: z.object({ error: z.string() }), | ||
| }, | ||
| }, | ||
| description: "Role not found", | ||
| }, | ||
| }, | ||
| }, | ||
| handler: async c => { | ||
| const { id } = c.req.valid("param"); | ||
| const body = c.req.valid("json"); | ||
| const db = c.get("db"); | ||
|
|
||
| const roleId = Number(id); | ||
| if (!Number.isInteger(roleId)) { | ||
| return c.json({ error: "Role not found" }, 404); | ||
| } | ||
|
|
||
| const [role] = await db | ||
| .select({ id: core_roles.id }) | ||
| .from(core_roles) | ||
| .where(eq(core_roles.id, roleId)) | ||
| .limit(1); | ||
|
|
||
| if (!role) { | ||
| return c.json({ error: "Role not found" }, 404); | ||
| } | ||
|
|
||
| const values: Partial<typeof core_roles.$inferInsert> = { | ||
| updatedAt: new Date(), | ||
| }; | ||
| if (body.color !== undefined) { | ||
| values.color = body.color.trim() ? body.color : null; | ||
|
aXenDeveloper marked this conversation as resolved.
|
||
| } | ||
|
|
||
| await db.update(core_roles).set(values).where(eq(core_roles.id, roleId)); | ||
|
|
||
| if (body.name !== undefined) { | ||
| await saveLanguageWords(c, { | ||
| pluginCode: "core", | ||
| tableName: "core_roles", | ||
| variable: "name", | ||
| itemId: roleId, | ||
| values: body.name, | ||
| }); | ||
| } | ||
|
|
||
| return c.json({ id: roleId }, 200); | ||
| }, | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/vitnode/src/views/admin/views/core/users/roles/actions/actions.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| "use client"; | ||
|
|
||
| import { PlusIcon } from "lucide-react"; | ||
| import { useTranslations } from "next-intl"; | ||
| import dynamic from "next/dynamic"; | ||
| import React from "react"; | ||
|
|
||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| DialogTrigger, | ||
| } from "@/components/ui/dialog"; | ||
| import { Loader } from "@/components/ui/loader"; | ||
|
|
||
| const CreateEditRoleAdmin = dynamic(async () => | ||
| import("./create-edit/create-edit").then(mod => ({ | ||
| default: mod.CreateEditRoleAdmin, | ||
| })), | ||
| ); | ||
|
|
||
| export const ActionsRolesAdmin = () => { | ||
| const t = useTranslations("admin.role.create"); | ||
|
|
||
| return ( | ||
| <Dialog> | ||
| <DialogTrigger render={<Button />}> | ||
| <PlusIcon /> | ||
| {t("title")} | ||
| </DialogTrigger> | ||
|
|
||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle>{t("title")}</DialogTitle> | ||
| <DialogDescription>{t("desc")}</DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <React.Suspense fallback={<Loader />}> | ||
| <CreateEditRoleAdmin /> | ||
| </React.Suspense> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.