(e *CollectionEvent)
| 19 | var collectionNameRegex = regexp.MustCompile(`^\w+$`) |
| 20 | |
| 21 | func onCollectionValidate(e *CollectionEvent) error { |
| 22 | var original *Collection |
| 23 | if !e.Collection.IsNew() { |
| 24 | original = &Collection{} |
| 25 | if err := e.App.ModelQuery(original).Model(e.Collection.LastSavedPK(), original); err != nil { |
| 26 | return fmt.Errorf("failed to fetch old collection state: %w", err) |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | validator := newCollectionValidator( |
| 31 | e.Context, |
| 32 | e.App, |
| 33 | e.Collection, |
| 34 | original, |
| 35 | ) |
| 36 | |
| 37 | if err := validator.run(); err != nil { |
| 38 | return err |
| 39 | } |
| 40 | |
| 41 | return e.Next() |
| 42 | } |
| 43 | |
| 44 | func newCollectionValidator(ctx context.Context, app App, new, original *Collection) *collectionValidator { |
| 45 | validator := &collectionValidator{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…