mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-24 22:03:54 +00:00
purge old permission (#2118)
* chore: purge old permission - remove useless role of teamMember - Cleanup auth apis' Props and Return type Definitions * chore: a better way of RequireAtLeastOne Signed-off-by: Finley Ge <m13203533462@163.com> --------- Signed-off-by: Finley Ge <m13203533462@163.com>
This commit is contained in:
@@ -3,20 +3,21 @@ import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { MongoChat } from '@fastgpt/service/core/chat/chatSchema';
|
||||
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
|
||||
import { DelHistoryProps } from '@/global/core/chat/api';
|
||||
import { autChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
/* clear chat history */
|
||||
async function handler(req: ApiRequestProps<{}, DelHistoryProps>, res: NextApiResponse) {
|
||||
const { appId, chatId } = req.query;
|
||||
|
||||
await autChatCrud({
|
||||
await authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
...req.query,
|
||||
per: 'w'
|
||||
per: WritePermissionVal
|
||||
});
|
||||
|
||||
await mongoSessionRun(async (session) => {
|
||||
|
@@ -1,10 +1,10 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import type { AdminUpdateFeedbackParams } from '@/global/core/chat/api.d';
|
||||
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
|
||||
import { autChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
/* 初始化我的聊天框,需要身份验证 */
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -17,12 +17,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error('missing parameter');
|
||||
}
|
||||
|
||||
await autChatCrud({
|
||||
await authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
appId,
|
||||
chatId,
|
||||
per: 'r'
|
||||
per: ReadPermissionVal
|
||||
});
|
||||
|
||||
await MongoChatItem.findOneAndUpdate(
|
||||
|
@@ -4,7 +4,8 @@ import { connectToDatabase } from '@/service/mongo';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import type { CloseCustomFeedbackParams } from '@/global/core/chat/api.d';
|
||||
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
|
||||
import { autChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
/* remove custom feedback */
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -16,12 +17,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error('missing parameter');
|
||||
}
|
||||
|
||||
await autChatCrud({
|
||||
await authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
appId,
|
||||
chatId,
|
||||
per: 'r'
|
||||
per: ReadPermissionVal
|
||||
});
|
||||
await authCert({ req, authToken: true });
|
||||
|
||||
|
@@ -3,7 +3,8 @@ import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
|
||||
import { UpdateChatFeedbackProps } from '@fastgpt/global/core/chat/api';
|
||||
import { autChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
/* 初始化我的聊天框,需要身份验证 */
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -22,7 +23,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
try {
|
||||
await connectToDatabase();
|
||||
|
||||
await autChatCrud({
|
||||
await authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
authApiKey: true,
|
||||
@@ -32,7 +33,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
chatId,
|
||||
shareId,
|
||||
outLinkUid,
|
||||
per: 'r'
|
||||
per: ReadPermissionVal
|
||||
});
|
||||
|
||||
if (!chatItemId) {
|
||||
|
@@ -2,10 +2,11 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
|
||||
import { autChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import type { DeleteChatItemProps } from '@/global/core/chat/api.d';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
async function handler(req: ApiRequestProps<{}, DeleteChatItemProps>, res: NextApiResponse) {
|
||||
const { appId, chatId, contentId, shareId, outLinkUid } = req.query;
|
||||
@@ -14,11 +15,11 @@ async function handler(req: ApiRequestProps<{}, DeleteChatItemProps>, res: NextA
|
||||
return jsonRes(res);
|
||||
}
|
||||
|
||||
await autChatCrud({
|
||||
await authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
...req.query,
|
||||
per: 'w'
|
||||
per: WritePermissionVal
|
||||
});
|
||||
|
||||
await MongoChatItem.deleteOne({
|
||||
|
@@ -2,18 +2,19 @@ import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { UpdateHistoryProps } from '@/global/core/chat/api.d';
|
||||
import { MongoChat } from '@fastgpt/service/core/chat/chatSchema';
|
||||
import { autChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { authChatCrud } from '@/service/support/permission/auth/chat';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
/* update chat top, custom title */
|
||||
async function handler(req: ApiRequestProps<UpdateHistoryProps>, res: NextApiResponse) {
|
||||
const { appId, chatId, title, customTitle, top } = req.body;
|
||||
await autChatCrud({
|
||||
await authChatCrud({
|
||||
req,
|
||||
authToken: true,
|
||||
...req.body,
|
||||
per: 'w'
|
||||
per: WritePermissionVal
|
||||
});
|
||||
|
||||
await MongoChat.findOneAndUpdate(
|
||||
|
@@ -3,6 +3,7 @@ import { jsonRes } from '@fastgpt/service/common/response';
|
||||
import { connectToDatabase } from '@/service/mongo';
|
||||
import { MongoOpenApi } from '@fastgpt/service/support/openapi/schema';
|
||||
import { authOpenApiKeyCrud } from '@fastgpt/service/support/permission/auth/openapi';
|
||||
import { OwnerPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
@@ -13,7 +14,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
throw new Error('缺少参数');
|
||||
}
|
||||
|
||||
await authOpenApiKeyCrud({ req, authToken: true, id, per: 'owner' });
|
||||
await authOpenApiKeyCrud({ req, authToken: true, id, per: OwnerPermissionVal });
|
||||
|
||||
await MongoOpenApi.findOneAndRemove({ _id: id });
|
||||
|
||||
|
@@ -4,13 +4,14 @@ import { connectToDatabase } from '@/service/mongo';
|
||||
import { MongoOpenApi } from '@fastgpt/service/support/openapi/schema';
|
||||
import type { EditApiKeyProps } from '@/global/support/openapi/api.d';
|
||||
import { authOpenApiKeyCrud } from '@fastgpt/service/support/permission/auth/openapi';
|
||||
import { OwnerPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
await connectToDatabase();
|
||||
const { _id, name, limit } = req.body as EditApiKeyProps & { _id: string };
|
||||
|
||||
await authOpenApiKeyCrud({ req, authToken: true, id: _id, per: 'owner' });
|
||||
await authOpenApiKeyCrud({ req, authToken: true, id: _id, per: OwnerPermissionVal });
|
||||
|
||||
await MongoOpenApi.findByIdAndUpdate(_id, {
|
||||
...(name && { name }),
|
||||
|
@@ -8,7 +8,12 @@ import { TeamMemberRoleEnum } from '@fastgpt/global/support/user/team/constant';
|
||||
import { authTeamSpaceToken } from './team';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { authOutLinkValid } from '@fastgpt/service/support/permission/publish/authLink';
|
||||
import { AuthUserTypeEnum, ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import {
|
||||
AuthUserTypeEnum,
|
||||
OwnerPermissionVal,
|
||||
ReadPermissionVal,
|
||||
WritePermissionVal
|
||||
} from '@fastgpt/global/support/permission/constant';
|
||||
import { MongoTeamMember } from '@fastgpt/service/support/user/team/teamMemberSchema';
|
||||
import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
|
||||
import { addLog } from '@fastgpt/service/common/system/log';
|
||||
@@ -16,7 +21,7 @@ import { addLog } from '@fastgpt/service/common/system/log';
|
||||
outLink: Must be the owner
|
||||
token: team owner and chat owner have all permissions
|
||||
*/
|
||||
export async function autChatCrud({
|
||||
export async function authChatCrud({
|
||||
appId,
|
||||
chatId,
|
||||
shareId,
|
||||
@@ -24,7 +29,7 @@ export async function autChatCrud({
|
||||
|
||||
teamId: spaceTeamId,
|
||||
teamToken,
|
||||
per = 'owner',
|
||||
per = OwnerPermissionVal,
|
||||
...props
|
||||
}: AuthModeType & {
|
||||
appId: string;
|
||||
@@ -77,7 +82,7 @@ export async function autChatCrud({
|
||||
if (String(tmbId) === String(chat.tmbId)) return { uid: outLinkUid };
|
||||
|
||||
// admin
|
||||
if (per === 'r' && permission.hasManagePer) return { uid: outLinkUid };
|
||||
if (per === WritePermissionVal && permission.hasManagePer) return { uid: outLinkUid };
|
||||
|
||||
return Promise.reject(ChatErrEnum.unAuthChat);
|
||||
})();
|
||||
|
Reference in New Issue
Block a user