Skip to content
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

pref: work-order #4

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions config.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"en": "FastGPT | WorkOrder",
"zh": "FastGPT | 工单"
},
"adminName": {
"en": "FastGPT Support",
"zh": "FastGPT 支持"
},
"workorder": {
"type": [
{
Expand Down Expand Up @@ -37,30 +41,35 @@
},
"userlevel": [
{
"id": "free",
"label": {
"en": "Free",
"zh": "免费版"
}
},
{
"id": "experience",
"label": {
"en": "Experience",
"zh": "体验版"
}
},
{
"id": "team",
"label": {
"en": "Team",
"zh": "团队版"
}
},
{
"id": "enterprise",
"label": {
"en": "Enterprise",
"zh": "企业版"
}
},
{
"id": "custom",
"label": {
"en": "custom",
"zh": "自定义"
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@
"user_recalled_a_message": "Withdrawn a message",
"you_recalled_a_message": "You recalled a message",
"close_confirm": "Are you sure you want to close?",
"delete_confirm": "Are you sure you want to delete?"
"delete_confirm": "Are you sure you want to delete?",
"reopen": "Reopen"
}
3 changes: 2 additions & 1 deletion public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@
"Experience": "体验版",
"user_level": "用户等级",
"delete_confirm": "确认删除?",
"close_confirm": "确认关闭?"
"close_confirm": "确认关闭?",
"reopen": "重新打开"
}
2 changes: 1 addition & 1 deletion src/components/Icon/icons/restart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/pages/api/auth/token.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateAccessToken, verifyToken } from '@/services/backend/auth';
import { jsonRes } from '@/services/backend/response';
import { createUser, getUserById } from '@/services/db/user';
import { createUser, getUserById, updateUser } from '@/services/db/user';
import { AppSession, TokenPayload } from '@/types/user';
import { NextApiRequest, NextApiResponse } from 'next';

Expand All @@ -19,6 +19,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const existingUser = await getUserById(payload.userId);

if (existingUser) {
// update the userlevel
await updateUser(existingUser.userId, existingUser.username, {
level: payload.level
});

const token = generateAccessToken(existingUser);
return jsonRes<AppSession>(res, {
code: 200,
Expand Down
21 changes: 12 additions & 9 deletions src/pages/api/user/setAdmin.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { verifyAccessToken } from '@/services/backend/auth';
import { verifyAdmin } from '@/services/backend/auth';
import { jsonRes } from '@/services/backend/response';
import { updateUser } from '@/services/db/user';
import { ApiResp } from '@/services/kubernet';
import { NextApiRequest, NextApiResponse } from 'next/types';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
const { userId, username } = req.body;
const payload = await verifyAccessToken(req);
if (!payload) {
try {
const isAdmin = await verifyAdmin(req);
if (!isAdmin) {
return jsonRes(res, {
code: 401,
message: "'token is invaild'"
});
}
} catch (error) {
return jsonRes(res, {
code: 401,
message: "'token is invaild'"
});
}
if (!payload.isAdmin) {
return jsonRes(res, {
code: 401,
message: 'unauthorized'
});
}

await updateUser(userId, username, {
isAdmin: true
});

return jsonRes(res, {
code: 200,
message: 'success'
Expand Down
23 changes: 21 additions & 2 deletions src/pages/api/workorder/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 12);
export type CreateWorkOrderParams = {
type: string;
description: string;
files?: string[];
appendix?: string[];
token: string;
};

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const { type, description, appendix, token } = req.body as CreateWorkOrderParams;
const { type, description, appendix, token, files } = req.body as CreateWorkOrderParams;
const userInfo = await verifyToken(token);
if (!userInfo) {
return jsonRes(res, {
Expand Down Expand Up @@ -44,7 +45,25 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
isAdmin: userInfo.isAdmin,
domain: userInfo.domain,
level: userInfo.level
}
},
dialogs: [
...(files
? files.map((file) => ({
isAdmin: false,
isAIBot: false,
userId: userInfo.userId,
content: file,
time: new Date()
}))
: []),
{
isAdmin: false,
isAIBot: false,
userId: userInfo.userId,
content: description,
time: new Date()
}
]
};

await createOrder({ order: workorder });
Expand Down
Loading
Loading