From caf343ef9cd638568a613a4e8bcb2e49229fc27b Mon Sep 17 00:00:00 2001 From: Sven-Kristjan Kompus <63632594+svekko@users.noreply.github.com> Date: Fri, 16 Jun 2023 14:43:05 +0300 Subject: [PATCH 1/2] [#2726] removed unnecessary Dao().TotalAdmins() call --- apis/middlewares.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apis/middlewares.go b/apis/middlewares.go index 3b8d808d..05e1d0ff 100644 --- a/apis/middlewares.go +++ b/apis/middlewares.go @@ -129,14 +129,17 @@ func RequireAdminAuth() echo.MiddlewareFunc { func RequireAdminAuthOnlyIfAny(app core.App) echo.MiddlewareFunc { return func(next echo.HandlerFunc) echo.HandlerFunc { return func(c echo.Context) error { + admin, _ := c.Get(ContextAdminKey).(*models.Admin) + if admin != nil { + return next(c) + } + totalAdmins, err := app.Dao().TotalAdmins() if err != nil { return NewBadRequestError("Failed to fetch admins info.", err) } - admin, _ := c.Get(ContextAdminKey).(*models.Admin) - - if admin != nil || totalAdmins == 0 { + if totalAdmins == 0 { return next(c) } From bd94940eeff1b1d8f34e0d97b9544b4a473c2a4f Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Fri, 16 Jun 2023 14:47:34 +0300 Subject: [PATCH 2/2] updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ae16c69..bf4f0791 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - Fixed collection index column sort normalization in the Admin UI ([#2681](https://github.com/pocketbase/pocketbase/pull/2681); thanks @SimonLoir). +- Removed unnecessary admins count in `apis.RequireAdminAuthOnlyIfAny()` middleware ([#2726](https://github.com/pocketbase/pocketbase/pull/2726); thanks @svekko). + ## v0.16.5