feat(group): 业务组禁用后限制用户登录和配置拉取

This commit is contained in:
2026-03-15 21:19:48 +08:00
parent 928a95fccd
commit 6ab368f21e
5 changed files with 62 additions and 2 deletions
+1
View File
@@ -90,6 +90,7 @@ func main() {
admin.GET("/group/get/:id", groupHandler.GetById) admin.GET("/group/get/:id", groupHandler.GetById)
admin.POST("/group/add", groupHandler.Add) admin.POST("/group/add", groupHandler.Add)
admin.POST("/group/update", groupHandler.Update) admin.POST("/group/update", groupHandler.Update)
admin.POST("/group/switch/:id", groupHandler.Switch)
admin.GET("/group/options", groupHandler.Options) admin.GET("/group/options", groupHandler.Options)
// profile management // profile management
+10
View File
@@ -53,6 +53,16 @@ func (h *ConfigApiHandler) FetchAllConfigs(c *gin.Context) {
return return
} }
// check if app's group is enabled
if app.GroupId != nil {
var group model.BusinessGroup
has, _ := dao.Engine.ID(*app.GroupId).Get(&group)
if !has || !group.Enabled {
c.JSON(http.StatusForbidden, model.WrapperResponse{Code: 403, Msg: "业务组已禁用"})
return
}
}
// validate token if app has token configured // validate token if app has token configured
if app.Token != "" && app.Token != req.Token { if app.Token != "" && app.Token != req.Token {
c.JSON(http.StatusForbidden, model.WrapperResponse{Code: 403, Msg: "Token 无效"}) c.JSON(http.StatusForbidden, model.WrapperResponse{Code: 403, Msg: "Token 无效"})
+24
View File
@@ -124,6 +124,30 @@ func (h *GroupHandler) Update(c *gin.Context) {
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0}) c.JSON(http.StatusOK, model.WrapperResponse{Code: 0})
} }
func (h *GroupHandler) Switch(c *gin.Context) {
id, _ := strconv.Atoi(c.Param("id"))
userInfo := middleware.GetUserInfo(c)
if !userInfo.IsSuperAdmin() {
c.JSON(http.StatusForbidden, model.WrapperResponse{Code: 403, Msg: "超级管理员才能操作"})
return
}
var group model.BusinessGroup
has, _ := dao.Engine.ID(id).Get(&group)
if !has {
c.JSON(http.StatusOK, model.WrapperResponse{Code: 404, Msg: "业务组不存在"})
return
}
group.Enabled = !group.Enabled
now := time.Now()
group.UpdatedAt = &now
group.UpdatedBy = userInfo.Name
dao.Engine.ID(group.Id).Cols("enabled", "updated_at", "updated_by").Update(&group)
c.JSON(http.StatusOK, model.WrapperResponse{Code: 0, Data: true})
}
func (h *GroupHandler) Options(c *gin.Context) { func (h *GroupHandler) Options(c *gin.Context) {
var groups []model.BusinessGroup var groups []model.BusinessGroup
dao.Engine.Where("enabled = 1").Find(&groups) dao.Engine.Where("enabled = 1").Find(&groups)
+18
View File
@@ -31,6 +31,15 @@ func (s *AuthService) Login(userName, password string) (string, *model.LoginUser
return "", nil, errors.New("用户不存在或已禁用") return "", nil, errors.New("用户不存在或已禁用")
} }
// 检查业务组是否启用
if user.GroupId != nil {
var group model.BusinessGroup
has, _ := dao.Engine.ID(*user.GroupId).Get(&group)
if !has || !group.Enabled {
return "", nil, errors.New("所属业务组已禁用")
}
}
if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)); err != nil { if err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)); err != nil {
return "", nil, errors.New("密码错误") return "", nil, errors.New("密码错误")
} }
@@ -93,6 +102,15 @@ func (s *AuthService) ValidateToken(tokenString string) (*model.LoginUserInfo, e
return nil, errors.New("user is disabled") return nil, errors.New("user is disabled")
} }
// 检查业务组是否启用
if user.GroupId != nil {
var group model.BusinessGroup
has, _ := dao.Engine.ID(*user.GroupId).Get(&group)
if !has || !group.Enabled {
return nil, errors.New("group is disabled")
}
}
// 检查 token 是否在登出后签发 // 检查 token 是否在登出后签发
if user.LastLogoutAt != nil { if user.LastLogoutAt != nil {
iat := int64(claims["iat"].(float64)) iat := int64(claims["iat"].(float64))
+9 -2
View File
@@ -9,9 +9,9 @@
<el-table-column prop="name" label="组名称"></el-table-column> <el-table-column prop="name" label="组名称"></el-table-column>
<el-table-column prop="master" label="负责人"></el-table-column> <el-table-column prop="master" label="负责人"></el-table-column>
<el-table-column prop="remarks" label="备注"></el-table-column> <el-table-column prop="remarks" label="备注"></el-table-column>
<el-table-column prop="enabled" label="状态" width="80"> <el-table-column prop="enabled" label="状态" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<el-tag :type="scope.row.enabled ? 'success' : 'info'">{{ scope.row.enabled ? '启用' : '禁用' }}</el-tag> <el-switch v-model="scope.row.enabled" @change="handleSwitch(scope.row)"></el-switch>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="操作" width="100"> <el-table-column label="操作" width="100">
@@ -81,6 +81,13 @@ export default {
this.users = res.data || [] this.users = res.data || []
} catch (e) {} } catch (e) {}
}, },
async handleSwitch(row) {
try {
await request({ url: `/admin/group/switch/${row.id}`, method: 'post' })
} catch (e) {
row.enabled = !row.enabled
}
},
showAdd() { showAdd() {
this.dialogTitle = '新建业务组' this.dialogTitle = '新建业务组'
this.form = { name: '', masterUid: null, remarks: '' } this.form = { name: '', masterUid: null, remarks: '' }