Skip to content

Commit b7f3db2

Browse files
committed
feat: 进一步开放开源版功能
- 开源版支持查询7天内的统计数据 - 开源版支持安全扫描功能 - 优化版本信息页面
1 parent b09dee5 commit b7f3db2

File tree

12 files changed

+126
-49
lines changed

12 files changed

+126
-49
lines changed

backend/errcode/errcode.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ var (
2323
ErrDingtalkNotEnabled = web.NewBadRequestErr("err-dingtalk-not-enabled")
2424
ErrCustomNotEnabled = web.NewBadRequestErr("err-custom-not-enabled")
2525
ErrUserLimit = web.NewBadRequestErr("err-user-limit")
26+
ErrModelLimit = web.NewBadRequestErr("err-model-limit")
27+
ErrSecurityLimit = web.NewBadRequestErr("err-security-limit")
2628
ErrOnlyAdmin = web.NewBadRequestErr("err-only-admin")
29+
ErrOnlyEnterprise = web.NewBadRequestErr("err-only-enterprise")
2730
ErrInvalidSecret = web.NewBadRequestErr("err-invalid-secret")
2831
ErrAIEmployeeLimit = web.NewBadRequestErr("err-ai-employee-limit")
2932
)

backend/errcode/locale.en.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ other = "OAuth is not enabled"
4040
[err-user-limit]
4141
other = "User limit reached"
4242

43+
[err-model-limit]
44+
other = "Model limit reached"
45+
46+
[err-security-limit]
47+
other = "Security limit reached"
48+
49+
[err-only-enterprise]
50+
other = "Only enterprise user can perform this operation"
51+
4352
[err-invalid-secret]
4453
other = "Invalid secret"
4554

backend/errcode/locale.zh.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ other = "OAuth未启用"
4040
[err-user-limit]
4141
other = "用户数量已达上限"
4242

43+
[err-model-limit]
44+
other = "模型数量已达上限"
45+
46+
[err-security-limit]
47+
other = "已有扫描中的任务"
48+
49+
[err-only-enterprise]
50+
other = "仅企业版可用"
51+
4352
[err-invalid-secret]
4453
other = "无效的密钥"
4554

backend/internal/model/repo/model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (r *ModelRepo) Create(ctx context.Context, m *domain.CreateModelReq) (*db.M
6262
return nil, err
6363
}
6464
status := consts.ModelStatusActive
65+
if m.ModelType == consts.ModelTypeCoder {
66+
status = consts.ModelStatusInactive
67+
}
6568
if n == 0 {
6669
status = consts.ModelStatusDefault
6770
}

backend/internal/model/usecase/model.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,22 @@ func (m *ModelUsecase) Update(ctx context.Context, req *domain.UpdateModelReq) (
109109
}
110110
if req.Status != nil {
111111
if *req.Status == consts.ModelStatusDefault {
112-
if err := tx.Model.Update().
113-
Where(model.Status(consts.ModelStatusDefault)).
114-
Where(model.ModelType(old.ModelType)).
115-
SetStatus(consts.ModelStatusActive).
116-
Exec(ctx); err != nil {
117-
return err
112+
if old.ModelType == consts.ModelTypeCoder {
113+
if err := tx.Model.Update().
114+
Where(model.StatusIn(consts.ModelStatusDefault, consts.ModelStatusActive)).
115+
Where(model.ModelType(old.ModelType)).
116+
SetStatus(consts.ModelStatusInactive).
117+
Exec(ctx); err != nil {
118+
return err
119+
}
120+
} else {
121+
if err := tx.Model.Update().
122+
Where(model.Status(consts.ModelStatusDefault)).
123+
Where(model.ModelType(old.ModelType)).
124+
SetStatus(consts.ModelStatusActive).
125+
Exec(ctx); err != nil {
126+
return err
127+
}
118128
}
119129
}
120130
if *req.Status == consts.ModelStatusActive {

backend/internal/user/handler/v1/user.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -442,23 +442,6 @@ func (h *UserHandler) LoginHistory(c *web.Context) error {
442442
// @Router /api/v1/user/invite [get]
443443
func (h *UserHandler) Invite(c *web.Context) error {
444444
admin := middleware.GetAdmin(c)
445-
446-
edition := c.Get("edition")
447-
if edition == nil {
448-
return errcode.ErrPermission
449-
}
450-
451-
// 如果是 Free 版本 user 表不允许超过 100 人
452-
if edition.(int) == 0 {
453-
count, err := h.usecase.GetUserCount(c.Request().Context())
454-
if err != nil {
455-
return err
456-
}
457-
if count >= 100 {
458-
return errcode.ErrUserLimit
459-
}
460-
}
461-
462445
resp, err := h.usecase.Invite(c.Request().Context(), admin.ID.String())
463446
if err != nil {
464447
return err

backend/pro

Submodule pro updated from c7e10ee to 4792df3

ui/src/assets/json/takeoff.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

ui/src/components/sidebar/aboutModal.tsx

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import dayjs from 'dayjs';
22
import { useState } from 'react';
3-
import { Ellipsis, Modal } from '@c-x/ui';
4-
import { Box, Button, Link, Stack } from '@mui/material';
3+
import { Modal } from '@c-x/ui';
4+
import HelpCenter from '@/assets/json/help-center.json';
5+
import Takeoff from '@/assets/json/takeoff.json';
6+
import IconUpgrade from '@/assets/json/upgrade.json';
7+
import { Box, Button, Stack } from '@mui/material';
58
import { DomainLicenseResp } from '@/api/types';
69
import ChangeLicense from './changeLicense';
10+
import LottieIcon from '../lottieIcon';
711

812
interface LicenseModalProps {
913
open: boolean;
@@ -36,7 +40,7 @@ const AboutModal = ({
3640
}
3741

3842
return (
39-
<Modal
43+
<Modal
4044
title='关于 MonkeyCode'
4145
width={600}
4246
open={open}
@@ -45,43 +49,93 @@ const AboutModal = ({
4549
<Stack direction={'column'} gap={2} sx={{
4650
fontSize: '14px'
4751
}}>
48-
<Stack direction={'row'}>
52+
<Stack direction={'row'} gap={2} alignItems={'center'}>
4953
<Box sx={{
5054
width: '120px'
5155
}}>当前版本</Box>
5256
<Box sx={{
5357
width: '120px',
5458
fontWeight: 700
5559
}}>{curVersion}</Box>
60+
61+
{latestVersion === `v${curVersion}` ? (
62+
<Box sx={{ color: 'text.auxiliary', fontSize: 12 }}>
63+
已是最新版本,无需更新
64+
</Box>
65+
) : (
66+
<Button
67+
size='small'
68+
startIcon={
69+
<Box>
70+
<LottieIcon
71+
id='version'
72+
src={latestVersion === '' ? HelpCenter : IconUpgrade}
73+
style={{ width: 16, height: 16, display: 'flex' }}
74+
/>
75+
</Box>
76+
}
77+
onClick={() => {
78+
window.open(
79+
'https://monkeycode.docs.baizhi.cloud/node/01980d22-db84-73b4-ae13-6a188e318048',
80+
);
81+
}}
82+
>
83+
立即更新
84+
</Button>
85+
)}
5686
</Stack>
57-
<Stack direction={'row'}>
87+
88+
<Stack direction={'row'} gap={2} alignItems={'center'}>
5889
<Box sx={{
5990
width: '120px',
6091
}}>产品型号</Box>
61-
<Box sx={{
62-
mr: '20px'
63-
}}>{editionText(license?.edition)}</Box>
64-
<Link href="#" sx={{
65-
color: 'info.main',
66-
'&:hover': {
67-
fontWeight: 700
92+
<Box>{editionText(license?.edition)}</Box>
93+
94+
<Button
95+
size='small'
96+
startIcon={
97+
<Box>
98+
<LottieIcon
99+
id='version'
100+
src={Takeoff}
101+
style={{ width: 16, height: 16, display: 'flex' }}
102+
/>
103+
</Box>
104+
}
105+
onClick={() => setOpenChangeLicense(true)}
106+
>
107+
切换授权
108+
</Button>
109+
110+
<Button
111+
size='small'
112+
startIcon={
113+
<Box>
114+
<LottieIcon
115+
id='consult'
116+
src={HelpCenter}
117+
style={{ width: 16, display: 'flex' }}
118+
/>
119+
</Box>
68120
}
69-
}}
70-
onClick={() => {
71-
setOpenChangeLicense(true);
72-
}}>切换授权</Link>
121+
onClick={() => {
122+
window.open('https://baizhi.cloud/consult');
123+
}}
124+
>
125+
商务咨询
126+
</Button>
73127
</Stack>
74-
{license && license?.edition !== 0 && <Stack direction={'row'}>
128+
{license && license?.edition !== 0 && <Stack direction={'row'} gap={2}>
75129
<Box sx={{
76130
width: '120px'
77131
}}>授权时间</Box>
78132
<Box sx={{
79133
}}>{dayjs.unix(license.started_at!).format('YYYY-MM-DD')} ~ {dayjs.unix(license.expired_at!).format('YYYY-MM-DD')}</Box>
80134
</Stack>}
81135
</Stack>
82-
<ChangeLicense
136+
<ChangeLicense
83137
open={openChangeLicense}
84-
onClose={() => {setOpenChangeLicense(false)}} />
138+
onClose={() => { setOpenChangeLicense(false) }} />
85139
</Modal>
86140
);
87141
};

ui/src/pages/dashboard/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ const presets = {
6161
end: new Date(),
6262
},
6363
};
64-
export type TimeRange = '90d' | '24h';
6564

6665
const Dashboard = () => {
6766
const navigate = useNavigate();
6867
const { tab, id } = useParams();
6968
const [tabValue, setTabValue] = useState(tab || 'global');
7069
const [memberData, setMemberData] = useState<DomainUser | null>(null);
7170
const [timeRange, setTimeRange] = useState<RangeValue>(
72-
presets['last-1-days']
71+
presets['last-7-days']
7372
);
7473

7574
const license = useRequest(() => {
@@ -167,7 +166,7 @@ const Dashboard = () => {
167166
disabled={license?.edition !== 2}
168167
onChange={handleTimeRangeChange}
169168
presets={presets}
170-
presetIndex={0}
169+
presetIndex={2}
171170
value={timeRange}
172171
/>
173172
</Box>

0 commit comments

Comments
 (0)