make use of the after hook finalizer
This commit is contained in:
parent
624b443f98
commit
d9e1a759a1
|
@ -69,12 +69,10 @@ func (api *adminApi) authRefresh(c echo.Context) error {
|
||||||
event.Admin = admin
|
event.Admin = admin
|
||||||
|
|
||||||
return api.app.OnAdminBeforeAuthRefreshRequest().Trigger(event, func(e *core.AdminAuthRefreshEvent) error {
|
return api.app.OnAdminBeforeAuthRefreshRequest().Trigger(event, func(e *core.AdminAuthRefreshEvent) error {
|
||||||
if err := api.app.OnAdminAfterAuthRefreshRequest().Trigger(event); err != nil {
|
return api.app.OnAdminAfterAuthRefreshRequest().Trigger(event, func(e *core.AdminAuthRefreshEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return api.authResponse(e.HttpContext, e.Admin)
|
return api.authResponse(e.HttpContext, e.Admin)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *adminApi) authWithPassword(c echo.Context) error {
|
func (api *adminApi) authWithPassword(c echo.Context) error {
|
||||||
|
@ -97,12 +95,10 @@ func (api *adminApi) authWithPassword(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to authenticate.", err)
|
return NewBadRequestError("Failed to authenticate.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnAdminAfterAuthWithPasswordRequest().Trigger(event); err != nil {
|
return api.app.OnAdminAfterAuthWithPasswordRequest().Trigger(event, func(e *core.AdminAuthWithPasswordEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return api.authResponse(e.HttpContext, e.Admin)
|
return api.authResponse(e.HttpContext, e.Admin)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -135,12 +131,10 @@ func (api *adminApi) requestPasswordReset(c echo.Context) error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := api.app.OnAdminAfterRequestPasswordResetRequest().Trigger(event); err != nil {
|
return api.app.OnAdminAfterRequestPasswordResetRequest().Trigger(event, func(e *core.AdminRequestPasswordResetEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -171,12 +165,10 @@ func (api *adminApi) confirmPasswordReset(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to set new password.", err)
|
return NewBadRequestError("Failed to set new password.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnAdminAfterConfirmPasswordResetRequest().Trigger(event); err != nil {
|
return api.app.OnAdminAfterConfirmPasswordResetRequest().Trigger(event, func(e *core.AdminConfirmPasswordResetEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -252,12 +244,10 @@ func (api *adminApi) create(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to create admin.", err)
|
return NewBadRequestError("Failed to create admin.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnAdminAfterCreateRequest().Trigger(event); err != nil {
|
return api.app.OnAdminAfterCreateRequest().Trigger(event, func(e *core.AdminCreateEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, e.Admin)
|
return e.HttpContext.JSON(http.StatusOK, e.Admin)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -296,12 +286,10 @@ func (api *adminApi) update(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to update admin.", err)
|
return NewBadRequestError("Failed to update admin.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnAdminAfterUpdateRequest().Trigger(event); err != nil {
|
return api.app.OnAdminAfterUpdateRequest().Trigger(event, func(e *core.AdminUpdateEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, e.Admin)
|
return e.HttpContext.JSON(http.StatusOK, e.Admin)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -328,10 +316,8 @@ func (api *adminApi) delete(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to delete admin.", err)
|
return NewBadRequestError("Failed to delete admin.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnAdminAfterDeleteRequest().Trigger(event); err != nil {
|
return api.app.OnAdminAfterDeleteRequest().Trigger(event, func(e *core.AdminDeleteEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,12 +91,10 @@ func (api *collectionApi) create(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to create the collection.", err)
|
return NewBadRequestError("Failed to create the collection.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnCollectionAfterCreateRequest().Trigger(event); err != nil {
|
return api.app.OnCollectionAfterCreateRequest().Trigger(event, func(e *core.CollectionCreateEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, e.Collection)
|
return e.HttpContext.JSON(http.StatusOK, e.Collection)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -128,12 +126,10 @@ func (api *collectionApi) update(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to update the collection.", err)
|
return NewBadRequestError("Failed to update the collection.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnCollectionAfterUpdateRequest().Trigger(event); err != nil {
|
return api.app.OnCollectionAfterUpdateRequest().Trigger(event, func(e *core.CollectionUpdateEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, e.Collection)
|
return e.HttpContext.JSON(http.StatusOK, e.Collection)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -153,12 +149,10 @@ func (api *collectionApi) delete(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to delete collection due to existing dependency.", err)
|
return NewBadRequestError("Failed to delete collection due to existing dependency.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnCollectionAfterDeleteRequest().Trigger(event); err != nil {
|
return api.app.OnCollectionAfterDeleteRequest().Trigger(event, func(e *core.CollectionDeleteEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *collectionApi) bulkImport(c echo.Context) error {
|
func (api *collectionApi) bulkImport(c echo.Context) error {
|
||||||
|
@ -183,12 +177,10 @@ func (api *collectionApi) bulkImport(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to import the submitted collections.", err)
|
return NewBadRequestError("Failed to import the submitted collections.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnCollectionsAfterImportRequest().Trigger(event); err != nil {
|
return api.app.OnCollectionsAfterImportRequest().Trigger(event, func(e *core.CollectionsImportEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,14 +50,12 @@ func (api *fileApi) fileToken(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to generate file token.", nil)
|
return NewBadRequestError("Failed to generate file token.", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnFileAfterTokenRequest().Trigger(event); err != nil {
|
return api.app.OnFileAfterTokenRequest().Trigger(event, func(e *core.FileTokenEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, map[string]string{
|
return e.HttpContext.JSON(http.StatusOK, map[string]string{
|
||||||
"token": e.Token,
|
"token": e.Token,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *fileApi) download(c echo.Context) error {
|
func (api *fileApi) download(c echo.Context) error {
|
||||||
|
|
|
@ -142,8 +142,11 @@ func (api *realtimeApi) connect(c echo.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRealtimeAfterMessageSend().Trigger(msgEvent); err != nil && api.app.IsDebug() {
|
if err := api.app.OnRealtimeAfterMessageSend().Trigger(msgEvent); err != nil {
|
||||||
log.Println("OnRealtimeAfterMessageSend error:", err)
|
if api.app.IsDebug() {
|
||||||
|
log.Println("Realtime connection closed (OnRealtimeAfterMessageSend error):", client.Id(), err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
idleTimer.Stop()
|
idleTimer.Stop()
|
||||||
|
@ -202,12 +205,10 @@ func (api *realtimeApi) setSubscriptions(c echo.Context) error {
|
||||||
// subscribe to the new subscriptions
|
// subscribe to the new subscriptions
|
||||||
e.Client.Subscribe(e.Subscriptions...)
|
e.Client.Subscribe(e.Subscriptions...)
|
||||||
|
|
||||||
if err := api.app.OnRealtimeAfterSubscribeRequest().Trigger(event); err != nil {
|
return api.app.OnRealtimeAfterSubscribeRequest().Trigger(event, func(e *core.RealtimeSubscribeEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateClientsAuthModel updates the existing clients auth model with the new one (matched by ID).
|
// updateClientsAuthModel updates the existing clients auth model with the new one (matched by ID).
|
||||||
|
|
|
@ -332,12 +332,10 @@ func (api *recordAuthApi) requestPasswordReset(c echo.Context) error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterRequestPasswordResetRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterRequestPasswordResetRequest().Trigger(event, func(e *core.RecordRequestPasswordResetEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -374,12 +372,10 @@ func (api *recordAuthApi) confirmPasswordReset(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to set new password.", err)
|
return NewBadRequestError("Failed to set new password.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterConfirmPasswordResetRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterConfirmPasswordResetRequest().Trigger(event, func(e *core.RecordConfirmPasswordResetEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -417,12 +413,10 @@ func (api *recordAuthApi) requestVerification(c echo.Context) error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterRequestVerificationRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterRequestVerificationRequest().Trigger(event, func(e *core.RecordRequestVerificationEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -459,12 +453,10 @@ func (api *recordAuthApi) confirmVerification(c echo.Context) error {
|
||||||
return NewBadRequestError("An error occurred while submitting the form.", err)
|
return NewBadRequestError("An error occurred while submitting the form.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterConfirmVerificationRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterConfirmVerificationRequest().Trigger(event, func(e *core.RecordConfirmVerificationEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -499,12 +491,10 @@ func (api *recordAuthApi) requestEmailChange(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to request email change.", err)
|
return NewBadRequestError("Failed to request email change.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterRequestEmailChangeRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterRequestEmailChangeRequest().Trigger(event, func(e *core.RecordRequestEmailChangeEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -533,12 +523,10 @@ func (api *recordAuthApi) confirmEmailChange(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to confirm email change.", err)
|
return NewBadRequestError("Failed to confirm email change.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterConfirmEmailChangeRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterConfirmEmailChangeRequest().Trigger(event, func(e *core.RecordConfirmEmailChangeEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -610,12 +598,10 @@ func (api *recordAuthApi) unlinkExternalAuth(c echo.Context) error {
|
||||||
return NewBadRequestError("Cannot unlink the external auth provider.", err)
|
return NewBadRequestError("Cannot unlink the external auth provider.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterUnlinkExternalAuthRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterUnlinkExternalAuthRequest().Trigger(event, func(e *core.RecordUnlinkExternalAuthEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
|
@ -238,12 +238,10 @@ func (api *recordApi) create(c echo.Context) error {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterCreateRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterCreateRequest().Trigger(event, func(e *core.RecordCreateEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, e.Record)
|
return e.HttpContext.JSON(http.StatusOK, e.Record)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -323,12 +321,10 @@ func (api *recordApi) update(c echo.Context) error {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterUpdateRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterUpdateRequest().Trigger(event, func(e *core.RecordUpdateEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, e.Record)
|
return e.HttpContext.JSON(http.StatusOK, e.Record)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -380,12 +376,10 @@ func (api *recordApi) delete(c echo.Context) error {
|
||||||
return NewBadRequestError("Failed to delete record. Make sure that the record is not part of a required relation reference.", err)
|
return NewBadRequestError("Failed to delete record. Make sure that the record is not part of a required relation reference.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnRecordAfterDeleteRequest().Trigger(event); err != nil {
|
return api.app.OnRecordAfterDeleteRequest().Trigger(event, func(e *core.RecordDeleteEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.HttpContext.NoContent(http.StatusNoContent)
|
return e.HttpContext.NoContent(http.StatusNoContent)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *recordApi) checkForForbiddenQueryFields(c echo.Context) error {
|
func (api *recordApi) checkForForbiddenQueryFields(c echo.Context) error {
|
||||||
|
|
|
@ -63,10 +63,7 @@ func (api *settingsApi) set(c echo.Context) error {
|
||||||
return NewBadRequestError("An error occurred while submitting the form.", err)
|
return NewBadRequestError("An error occurred while submitting the form.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := api.app.OnSettingsAfterUpdateRequest().Trigger(event); err != nil {
|
return api.app.OnSettingsAfterUpdateRequest().Trigger(event, func(e *core.SettingsUpdateEvent) error {
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
redactedSettings, err := api.app.Settings().RedactClone()
|
redactedSettings, err := api.app.Settings().RedactClone()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NewBadRequestError("", err)
|
return NewBadRequestError("", err)
|
||||||
|
@ -74,6 +71,7 @@ func (api *settingsApi) set(c echo.Context) error {
|
||||||
|
|
||||||
return e.HttpContext.JSON(http.StatusOK, redactedSettings)
|
return e.HttpContext.JSON(http.StatusOK, redactedSettings)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue