()
| 32 | ) |
| 33 | |
| 34 | func (app *BaseApp) registerSettingsHooks() { |
| 35 | saveFunc := func(me *ModelEvent) error { |
| 36 | if err := me.Next(); err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | if me.Model.PK() == paramsKeySettings { |
| 41 | // auto reload the app settings because we don't know whether |
| 42 | // the Settings model is the app one or a different one |
| 43 | return errors.Join( |
| 44 | me.App.Settings().PostScan(), |
| 45 | me.App.ReloadSettings(), |
| 46 | ) |
| 47 | } |
| 48 | |
| 49 | return nil |
| 50 | } |
| 51 | |
| 52 | app.OnModelAfterCreateSuccess(paramsTable).Bind(&hook.Handler[*ModelEvent]{ |
| 53 | Id: systemHookIdSettings, |
| 54 | Func: saveFunc, |
| 55 | Priority: -999, |
| 56 | }) |
| 57 | |
| 58 | app.OnModelAfterUpdateSuccess(paramsTable).Bind(&hook.Handler[*ModelEvent]{ |
| 59 | Id: systemHookIdSettings, |
| 60 | Func: saveFunc, |
| 61 | Priority: -999, |
| 62 | }) |
| 63 | |
| 64 | app.OnModelDelete(paramsTable).Bind(&hook.Handler[*ModelEvent]{ |
| 65 | Id: systemHookIdSettings, |
| 66 | Func: func(me *ModelEvent) error { |
| 67 | if me.Model.PK() == paramsKeySettings { |
| 68 | return errors.New("the app params settings cannot be deleted") |
| 69 | } |
| 70 | |
| 71 | return me.Next() |
| 72 | }, |
| 73 | Priority: -999, |
| 74 | }) |
| 75 | |
| 76 | app.OnCollectionUpdate().Bind(&hook.Handler[*CollectionEvent]{ |
| 77 | Id: systemHookIdSettings, |
| 78 | Func: func(e *CollectionEvent) error { |
| 79 | oldCollection, err := e.App.FindCachedCollectionByNameOrId(e.Collection.Id) |
| 80 | if err != nil { |
| 81 | return fmt.Errorf("failed to retrieve old cached collection: %w", err) |
| 82 | } |
| 83 | |
| 84 | err = e.Next() |
| 85 | if err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | // update existing rate limit rules on collection rename |
| 90 | if oldCollection.Name != e.Collection.Name { |
| 91 | var hasChange bool |
no test coverage detected