mirror of
https://github.com/usememos/memos.git
synced 2025-02-26 14:25:24 +08:00
fix: visibility param override the user auth state (#1942)
fix visibility param override the user auth state
This commit is contained in:
parent
11aa01ee2e
commit
3093f80d68
1 changed files with 8 additions and 12 deletions
|
@ -6,7 +6,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
@ -357,16 +356,21 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
|||
|
||||
currentUserID, ok := c.Get(getUserIDContextKey()).(int)
|
||||
if !ok {
|
||||
// Anonymous use should only fetch PUBLIC memos with specified user
|
||||
if findMemoMessage.CreatorID == nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find memo")
|
||||
}
|
||||
findMemoMessage.VisibilityList = []store.Visibility{store.Public}
|
||||
} else {
|
||||
if findMemoMessage.CreatorID == nil {
|
||||
// Authorized user can fetch all PUBLIC/PROTECTED memo
|
||||
visibilityList := []store.Visibility{store.Public, store.Protected}
|
||||
|
||||
// If Creator is authorized user (as default), PRIVATE memo is OK
|
||||
if findMemoMessage.CreatorID == nil || *findMemoMessage.CreatorID == currentUserID {
|
||||
findMemoMessage.CreatorID = ¤tUserID
|
||||
} else {
|
||||
findMemoMessage.VisibilityList = []store.Visibility{store.Public, store.Protected}
|
||||
visibilityList = append(visibilityList, store.Private)
|
||||
}
|
||||
findMemoMessage.VisibilityList = visibilityList
|
||||
}
|
||||
|
||||
rowStatus := store.RowStatus(c.QueryParam("rowStatus"))
|
||||
|
@ -390,14 +394,6 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
|||
}
|
||||
findMemoMessage.ContentSearch = contentSearch
|
||||
|
||||
visibilityListStr := c.QueryParam("visibility")
|
||||
if visibilityListStr != "" {
|
||||
visibilityList := []store.Visibility{}
|
||||
for _, visibility := range strings.Split(visibilityListStr, ",") {
|
||||
visibilityList = append(visibilityList, store.Visibility(visibility))
|
||||
}
|
||||
findMemoMessage.VisibilityList = visibilityList
|
||||
}
|
||||
if limit, err := strconv.Atoi(c.QueryParam("limit")); err == nil {
|
||||
findMemoMessage.Limit = &limit
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue