diff --git a/controller/user.go b/controller/user.go index 46f5d869..045e0841 100644 --- a/controller/user.go +++ b/controller/user.go @@ -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": "无权将其他用户权限等级提升到大于等于自己的权限等级", diff --git a/model/ability.go b/model/ability.go index 1270ea8a..f3dae7ac 100644 --- a/model/ability.go +++ b/model/ability.go @@ -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 } diff --git a/model/channel.go b/model/channel.go index 006a67d9..fdc89eb9 100644 --- a/model/channel.go +++ b/model/channel.go @@ -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 } diff --git a/web/src/pages/Channel/EditChannel.js b/web/src/pages/Channel/EditChannel.js index 05607f98..022a9fe4 100644 --- a/web/src/pages/Channel/EditChannel.js +++ b/web/src/pages/Channel/EditChannel.js @@ -1,7 +1,7 @@ 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, showInfo, showSuccess } 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); @@ -159,9 +166,20 @@ const EditChannel = () => { autoComplete='new-password' /> + + + { options={modelOptions} /> +
+ + +
{ batch ? { 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 = () => { /> { - userId && ( + userId && <> + + + { autoComplete='new-password' /> - ) + }