mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 09:40:12 +00:00
fix(controller): filter listing endpoints by ownership
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -39,8 +39,12 @@ func listNotificationGroup(c *gin.Context) ([]*model.NotificationGroupResponseIt
|
|||||||
groupNotifications[n.NotificationGroupID] = append(groupNotifications[n.NotificationGroupID], n.NotificationID)
|
groupNotifications[n.NotificationGroupID] = append(groupNotifications[n.NotificationGroupID], n.NotificationID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAdmin := callerIsAdmin(c)
|
||||||
ngRes := make([]*model.NotificationGroupResponseItem, 0, len(ng))
|
ngRes := make([]*model.NotificationGroupResponseItem, 0, len(ng))
|
||||||
for _, n := range ng {
|
for _, n := range ng {
|
||||||
|
if !isAdmin && !n.HasPermission(c) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
ngRes = append(ngRes, &model.NotificationGroupResponseItem{
|
ngRes = append(ngRes, &model.NotificationGroupResponseItem{
|
||||||
Group: n,
|
Group: n,
|
||||||
Notifications: groupNotifications[n.ID],
|
Notifications: groupNotifications[n.ID],
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ func listServerGroup(c *gin.Context) ([]*model.ServerGroupResponseItem, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, isMember := c.Get(model.CtxKeyAuthorizedUser)
|
_, isMember := c.Get(model.CtxKeyAuthorizedUser)
|
||||||
authorized := isMember
|
isAdmin := isMember && callerIsAdmin(c)
|
||||||
|
|
||||||
visibleServerIDs := make(map[uint64]struct{})
|
visibleServerIDs := make(map[uint64]struct{})
|
||||||
if !authorized {
|
if !isMember {
|
||||||
for _, server := range singleton.ServerShared.GetSortedListForGuest() {
|
for _, server := range singleton.ServerShared.GetSortedListForGuest() {
|
||||||
visibleServerIDs[server.ID] = struct{}{}
|
visibleServerIDs[server.ID] = struct{}{}
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func listServerGroup(c *gin.Context) ([]*model.ServerGroupResponseItem, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, s := range sgs {
|
for _, s := range sgs {
|
||||||
if !authorized {
|
if !isMember {
|
||||||
if _, ok := visibleServerIDs[s.ServerId]; !ok {
|
if _, ok := visibleServerIDs[s.ServerId]; !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,9 @@ func listServerGroup(c *gin.Context) ([]*model.ServerGroupResponseItem, error) {
|
|||||||
|
|
||||||
var sgRes []*model.ServerGroupResponseItem
|
var sgRes []*model.ServerGroupResponseItem
|
||||||
for _, s := range sg {
|
for _, s := range sg {
|
||||||
|
if isMember && !isAdmin && !s.HasPermission(c) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
sgRes = append(sgRes, &model.ServerGroupResponseItem{
|
sgRes = append(sgRes, &model.ServerGroupResponseItem{
|
||||||
Group: s,
|
Group: s,
|
||||||
Servers: groupServers[s.ID],
|
Servers: groupServers[s.ID],
|
||||||
|
|||||||
Reference in New Issue
Block a user