Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d5634ee7
authored
Jun 08, 2023
by
JustSong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: able to manage group now
parent
cbf33928
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
13 deletions
+51
-13
controller/user.go
+3
-3
model/ability.go
+2
-2
model/channel.go
+1
-0
web/src/pages/Channel/EditChannel.js
+31
-5
web/src/pages/User/EditUser.js
+14
-3
No files found.
controller/user.go
View file @
d5634ee7
...
...
@@ -228,7 +228,7 @@ func GetUser(c *gin.Context) {
return
}
myRole
:=
c
.
GetInt
(
"role"
)
if
myRole
<=
user
.
Role
{
if
myRole
<=
user
.
Role
&&
myRole
!=
common
.
RoleRootUser
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"无权获取同级或更高等级用户的信息"
,
...
...
@@ -326,14 +326,14 @@ func UpdateUser(c *gin.Context) {
return
}
myRole
:=
c
.
GetInt
(
"role"
)
if
myRole
<=
originUser
.
Role
{
if
myRole
<=
originUser
.
Role
&&
myRole
!=
common
.
RoleRootUser
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"无权更新同权限等级或更高权限等级的用户信息"
,
})
return
}
if
myRole
<=
updatedUser
.
Role
{
if
myRole
<=
updatedUser
.
Role
&&
myRole
!=
common
.
RoleRootUser
{
c
.
JSON
(
http
.
StatusOK
,
gin
.
H
{
"success"
:
false
,
"message"
:
"无权将其他用户权限等级提升到大于等于自己的权限等级"
,
...
...
model/ability.go
View file @
d5634ee7
...
...
@@ -9,7 +9,7 @@ type Ability struct {
Group
string
`json:"group" gorm:"type:varchar(32);primaryKey;autoIncrement:false"`
Model
string
`json:"model" gorm:"primaryKey;autoIncrement:false"`
ChannelId
int
`json:"channel_id" gorm:"primaryKey;autoIncrement:false;index"`
Enabled
bool
`json:"enabled"
gorm:"default:1"
`
Enabled
bool
`json:"enabled"`
}
func
GetRandomSatisfiedChannel
(
group
string
,
model
string
)
(
*
Channel
,
error
)
{
...
...
@@ -68,5 +68,5 @@ func (channel *Channel) UpdateAbilities() error {
}
func
UpdateAbilityStatus
(
channelId
int
,
status
bool
)
error
{
return
DB
.
Model
(
&
Ability
{})
.
Where
(
"channel_id = ?"
,
channelId
)
.
Update
(
"enabled"
,
status
)
.
Error
return
DB
.
Model
(
&
Ability
{})
.
Where
(
"channel_id = ?"
,
channelId
)
.
Select
(
"enabled"
)
.
Update
(
"enabled"
,
status
)
.
Error
}
model/channel.go
View file @
d5634ee7
...
...
@@ -91,6 +91,7 @@ func (channel *Channel) Update() error {
if
err
!=
nil
{
return
err
}
DB
.
Model
(
channel
)
.
First
(
channel
,
"id = ?"
,
channel
.
Id
)
err
=
channel
.
UpdateAbilities
()
return
err
}
...
...
web/src/pages/Channel/EditChannel.js
View file @
d5634ee7
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Button
,
Form
,
Header
,
Message
,
Segment
}
from
'semantic-ui-react'
;
import
{
useParams
}
from
'react-router-dom'
;
import
{
API
,
showError
,
showSuccess
}
from
'../../helpers'
;
import
{
API
,
showError
,
show
Info
,
show
Success
}
from
'../../helpers'
;
import
{
CHANNEL_OPTIONS
}
from
'../../constants'
;
const
EditChannel
=
()
=>
{
...
...
@@ -15,13 +15,15 @@ const EditChannel = () => {
key
:
''
,
base_url
:
''
,
other
:
''
,
group
:
'default'
,
models
:
[],
};
const
[
batch
,
setBatch
]
=
useState
(
false
);
const
[
inputs
,
setInputs
]
=
useState
(
originInputs
);
const
[
modelOptions
,
setModelOptions
]
=
useState
([]);
const
[
basicModels
,
setBasicModels
]
=
useState
([]);
const
[
fullModels
,
setFullModels
]
=
useState
([]);
const
handleInputChange
=
(
e
,
{
name
,
value
})
=>
{
console
.
log
(
name
,
value
);
setInputs
((
inputs
)
=>
({
...
inputs
,
[
name
]:
value
}));
};
...
...
@@ -49,8 +51,10 @@ const EditChannel = () => {
text
:
model
.
id
,
value
:
model
.
id
,
})));
setFullModels
(
res
.
data
.
data
.
map
((
model
)
=>
model
.
id
));
setBasicModels
(
res
.
data
.
data
.
filter
((
model
)
=>
!
model
.
id
.
startsWith
(
"gpt-4"
)).
map
((
model
)
=>
model
.
id
));
}
catch
(
error
)
{
console
.
error
(
'Error fetching models:'
,
error
);
showError
(
error
.
message
);
}
};
...
...
@@ -62,7 +66,10 @@ const EditChannel = () => {
},
[]);
const
submit
=
async
()
=>
{
if
(
!
isEdit
&&
(
inputs
.
name
===
''
||
inputs
.
key
===
''
))
return
;
if
(
!
isEdit
&&
(
inputs
.
name
===
''
||
inputs
.
key
===
''
))
{
showInfo
(
'请填写渠道名称和渠道密钥!'
);
return
;
}
let
localInputs
=
inputs
;
if
(
localInputs
.
base_url
.
endsWith
(
'/'
))
{
localInputs
.
base_url
=
localInputs
.
base_url
.
slice
(
0
,
localInputs
.
base_url
.
length
-
1
);
...
...
@@ -160,8 +167,19 @@ const EditChannel = () => {
/>
<
/Form.Field
>
<
Form
.
Field
>
<
Form
.
Input
label
=
'分组'
name
=
'group'
placeholder
=
{
'请输入分组'
}
onChange
=
{
handleInputChange
}
value
=
{
inputs
.
group
}
autoComplete
=
'new-password'
/>
<
/Form.Field
>
<
Form
.
Field
>
<
Form
.
Dropdown
label
=
'支持的模型'
label
=
'模型'
placeholder
=
{
'请选择该通道所支持的模型'
}
name
=
'models'
fluid
multiple
...
...
@@ -172,6 +190,14 @@ const EditChannel = () => {
options
=
{
modelOptions
}
/
>
<
/Form.Field
>
<
div
style
=
{{
lineHeight
:
'40px'
,
marginBottom
:
'12px'
}}
>
<
Button
type
=
{
'button'
}
onClick
=
{()
=>
{
handleInputChange
(
null
,
{
name
:
'models'
,
value
:
basicModels
});
}}
>
填入基础模型
<
/Button
>
<
Button
type
=
{
'button'
}
onClick
=
{()
=>
{
handleInputChange
(
null
,
{
name
:
'models'
,
value
:
fullModels
});
}}
>
填入所有模型
<
/Button
>
<
/div
>
{
batch
?
<
Form
.
Field
>
<
Form
.
TextArea
...
...
web/src/pages/User/EditUser.js
View file @
d5634ee7
...
...
@@ -15,8 +15,9 @@ const EditUser = () => {
wechat_id
:
''
,
email
:
''
,
quota
:
0
,
group
:
'default'
});
const
{
username
,
display_name
,
password
,
github_id
,
wechat_id
,
email
,
quota
}
=
const
{
username
,
display_name
,
password
,
github_id
,
wechat_id
,
email
,
quota
,
group
}
=
inputs
;
const
handleInputChange
=
(
e
,
{
name
,
value
})
=>
{
setInputs
((
inputs
)
=>
({
...
inputs
,
[
name
]:
value
}));
...
...
@@ -98,7 +99,17 @@ const EditUser = () => {
/>
<
/Form.Field
>
{
userId
&&
(
userId
&&
<>
<
Form
.
Field
>
<
Form
.
Input
label
=
'分组'
name
=
'group'
placeholder
=
{
'请输入用户分组'
}
onChange
=
{
handleInputChange
}
value
=
{
group
}
autoComplete
=
'new-password'
/>
<
/Form.Field
>
<
Form
.
Field
>
<
Form
.
Input
label
=
'剩余额度'
...
...
@@ -110,7 +121,7 @@ const EditUser = () => {
autoComplete
=
'new-password'
/>
<
/Form.Field
>
)
<
/
>
}
<
Form
.
Field
>
<
Form
.
Input
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment