feat: 初始化配置中心项目

This commit is contained in:
2026-01-14 21:02:13 +08:00
commit 4436d3ee88
95 changed files with 8736 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
package service
import (
"errors"
"kenaito-conf/server/internal/model"
)
type PermissionService struct{}
func NewPermissionService() *PermissionService {
return &PermissionService{}
}
func (s *PermissionService) RequireSuperAdmin(userInfo *model.LoginUserInfo) error {
if !userInfo.IsSuperAdmin() {
return errors.New("超级管理员才有权限操作")
}
return nil
}
func (s *PermissionService) RequirePermission(userInfo *model.LoginUserInfo, groupId *int, appId *int, operate string) error {
if userInfo.IsSuperAdmin() {
return nil
}
if groupId != nil && userInfo.GroupId != nil && *groupId == *userInfo.GroupId {
return nil
}
if appId == nil || *appId == 0 {
return errors.New("你没有全局配置权限")
}
permCode := buildPermissionCode(*appId, operate)
for _, p := range userInfo.GrantPermissons {
if p == permCode {
return nil
}
}
return errors.New("你没有该应用权限")
}
func (s *PermissionService) HasPermissionForUser(userInfo *model.LoginUserInfo, targetUser *model.User) error {
if userInfo.IsSuperAdmin() {
return nil
}
if !userInfo.IsGroupAdmin() {
return errors.New("你不是业务组管理员")
}
if userInfo.GroupId == nil || targetUser.GroupId == nil || *userInfo.GroupId != *targetUser.GroupId {
return errors.New("不能操作其他组成员")
}
return nil
}