mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
fix: member-created services shouldn't be applied to admin resources (#1113)
This commit is contained in:
@@ -223,7 +223,7 @@ func adminHandler[T any](handler handlerFunc[T]) func(*gin.Context) {
|
||||
}
|
||||
|
||||
user := *auth.(*model.User)
|
||||
if user.Role != model.RoleAdmin {
|
||||
if !user.Role.IsAdmin() {
|
||||
c.JSON(http.StatusOK, newErrorResponse(singleton.Localizer.ErrorT("permission denied")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ func listConfig(c *gin.Context) (*model.SettingResponse, error) {
|
||||
var isAdmin bool
|
||||
if authorized {
|
||||
user := u.(*model.User)
|
||||
isAdmin = user.Role == model.RoleAdmin
|
||||
isAdmin = user.Role.IsAdmin()
|
||||
}
|
||||
|
||||
config := *singleton.Conf
|
||||
config.Language = strings.Replace(config.Language, "_", "-", -1)
|
||||
config.Language = strings.ReplaceAll(config.Language, "_", "-")
|
||||
|
||||
conf := model.SettingResponse{
|
||||
Config: model.Setting{
|
||||
@@ -89,7 +89,7 @@ func updateConfig(c *gin.Context) (any, error) {
|
||||
return nil, errors.New("invalid user template")
|
||||
}
|
||||
|
||||
singleton.Conf.Language = strings.Replace(sf.Language, "-", "_", -1)
|
||||
singleton.Conf.Language = strings.ReplaceAll(sf.Language, "-", "_")
|
||||
|
||||
singleton.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification
|
||||
singleton.Conf.EnablePlainIPInNotification = sf.EnablePlainIPInNotification
|
||||
|
||||
@@ -133,7 +133,7 @@ func createUser(c *gin.Context) (uint64, error) {
|
||||
if uf.Username == "" {
|
||||
return 0, singleton.Localizer.ErrorT("username can't be empty")
|
||||
}
|
||||
if uf.Role != model.RoleAdmin && uf.Role != model.RoleMember {
|
||||
if uf.Role > model.RoleMember {
|
||||
return 0, singleton.Localizer.ErrorT("invalid role")
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ func listOnlineUser(c *gin.Context) (*model.Value[[]*model.OnlineUser], error) {
|
||||
var isAdmin bool
|
||||
u, ok := c.Get(model.CtxKeyAuthorizedUser)
|
||||
if ok {
|
||||
isAdmin = u.(*model.User).Role == model.RoleAdmin
|
||||
isAdmin = u.(*model.User).Role.IsAdmin()
|
||||
}
|
||||
limit, err := strconv.Atoi(c.Query("limit"))
|
||||
if err != nil || limit < 1 {
|
||||
|
||||
Reference in New Issue
Block a user