feat: user roles (#852)

* [WIP] feat: user roles

* update

* update

* admin handler

* update

* feat: user-specific connection secret

* simplify some logics

* cleanup

* update waf

* update user api error handling

* update waf api

* fix codeql

* update waf table

* fix several problems

* add pagination for waf api

* update permission checks

* switch to runtime check

* 1

* cover?

* some changes
This commit is contained in:
UUBulb
2024-12-22 00:05:41 +08:00
committed by GitHub
parent 50ee62172f
commit 653d0cf2e9
35 changed files with 841 additions and 180 deletions
+14 -20
View File
@@ -1,10 +1,12 @@
package singleton
import (
"sort"
"cmp"
"slices"
"sync"
"github.com/nezhahq/nezha/model"
"github.com/nezhahq/nezha/pkg/utils"
)
var (
@@ -45,29 +47,21 @@ func ReSortServer() {
SortedServerLock.Lock()
defer SortedServerLock.Unlock()
SortedServerList = make([]*model.Server, 0, len(ServerList))
SortedServerListForGuest = make([]*model.Server, 0)
for _, s := range ServerList {
SortedServerList = append(SortedServerList, s)
SortedServerList = utils.MapValuesToSlice(ServerList)
// 按照服务器 ID 排序的具体实现(ID越大越靠前)
slices.SortStableFunc(SortedServerList, func(a, b *model.Server) int {
if a.DisplayIndex == b.DisplayIndex {
return cmp.Compare(a.ID, b.ID)
}
return cmp.Compare(b.DisplayIndex, a.DisplayIndex)
})
SortedServerListForGuest = make([]*model.Server, 0, len(SortedServerList))
for _, s := range SortedServerList {
if !s.HideForGuest {
SortedServerListForGuest = append(SortedServerListForGuest, s)
}
}
// 按照服务器 ID 排序的具体实现(ID越大越靠前)
sort.SliceStable(SortedServerList, func(i, j int) bool {
if SortedServerList[i].DisplayIndex == SortedServerList[j].DisplayIndex {
return SortedServerList[i].ID < SortedServerList[j].ID
}
return SortedServerList[i].DisplayIndex > SortedServerList[j].DisplayIndex
})
sort.SliceStable(SortedServerListForGuest, func(i, j int) bool {
if SortedServerListForGuest[i].DisplayIndex == SortedServerListForGuest[j].DisplayIndex {
return SortedServerListForGuest[i].ID < SortedServerListForGuest[j].ID
}
return SortedServerListForGuest[i].DisplayIndex > SortedServerListForGuest[j].DisplayIndex
})
}
func OnServerDelete(sid []uint64) {