refactor: simplify server & service manipulation (#993)

* refactor: simplify server & service manipulation

* update

* fix

* update for nat, ddns & notification

* chore

* update cron

* update dependencies

* use of function iterators

* update default dns servers
This commit is contained in:
UUBulb
2025-02-21 23:08:12 +08:00
committed by GitHub
parent 21eefde995
commit 91bef2882a
32 changed files with 987 additions and 1083 deletions

View File

@@ -68,16 +68,9 @@ func createNotificationGroup(c *gin.Context) (uint64, error) {
}
ngf.Notifications = slices.Compact(ngf.Notifications)
singleton.NotificationsLock.RLock()
for _, nid := range ngf.Notifications {
if n, ok := singleton.NotificationMap[nid]; ok {
if !n.HasPermission(c) {
singleton.NotificationsLock.RUnlock()
return 0, singleton.Localizer.ErrorT("permission denied")
}
}
if !singleton.NotificationShared.CheckPermission(c, slices.Values(ngf.Notifications)) {
return 0, singleton.Localizer.ErrorT("permission denied")
}
singleton.NotificationsLock.RUnlock()
uid := getUid(c)
@@ -115,7 +108,7 @@ func createNotificationGroup(c *gin.Context) (uint64, error) {
return 0, newGormError("%v", err)
}
singleton.OnRefreshOrAddNotificationGroup(&ng, ngf.Notifications)
singleton.NotificationShared.UpdateGroup(&ng, ngf.Notifications)
return ng.ID, nil
}
@@ -144,16 +137,9 @@ func updateNotificationGroup(c *gin.Context) (any, error) {
return nil, err
}
singleton.NotificationsLock.RLock()
for _, nid := range ngf.Notifications {
if n, ok := singleton.NotificationMap[nid]; ok {
if !n.HasPermission(c) {
singleton.NotificationsLock.RUnlock()
return nil, singleton.Localizer.ErrorT("permission denied")
}
}
if !singleton.NotificationShared.CheckPermission(c, slices.Values(ngf.Notifications)) {
return nil, singleton.Localizer.ErrorT("permission denied")
}
singleton.NotificationsLock.RUnlock()
var ngDB model.NotificationGroup
if err := singleton.DB.First(&ngDB, id).Error; err != nil {
@@ -202,7 +188,7 @@ func updateNotificationGroup(c *gin.Context) (any, error) {
return nil, newGormError("%v", err)
}
singleton.OnRefreshOrAddNotificationGroup(&ngDB, ngf.Notifications)
singleton.NotificationShared.UpdateGroup(&ngDB, ngf.Notifications)
return nil, nil
}
@@ -248,6 +234,6 @@ func batchDeleteNotificationGroup(c *gin.Context) (any, error) {
return nil, newGormError("%v", err)
}
singleton.OnDeleteNotificationGroup(ngn)
singleton.NotificationShared.DeleteGroup(ngn)
return nil, nil
}