mirror of
https://github.com/usememos/memos.git
synced 2025-02-26 22:34:17 +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"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
@ -357,16 +356,21 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||||
|
|
||||||
currentUserID, ok := c.Get(getUserIDContextKey()).(int)
|
currentUserID, ok := c.Get(getUserIDContextKey()).(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// Anonymous use should only fetch PUBLIC memos with specified user
|
||||||
if findMemoMessage.CreatorID == nil {
|
if findMemoMessage.CreatorID == nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find memo")
|
return echo.NewHTTPError(http.StatusBadRequest, "Missing user id to find memo")
|
||||||
}
|
}
|
||||||
findMemoMessage.VisibilityList = []store.Visibility{store.Public}
|
findMemoMessage.VisibilityList = []store.Visibility{store.Public}
|
||||||
} else {
|
} 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
|
findMemoMessage.CreatorID = ¤tUserID
|
||||||
} else {
|
visibilityList = append(visibilityList, store.Private)
|
||||||
findMemoMessage.VisibilityList = []store.Visibility{store.Public, store.Protected}
|
|
||||||
}
|
}
|
||||||
|
findMemoMessage.VisibilityList = visibilityList
|
||||||
}
|
}
|
||||||
|
|
||||||
rowStatus := store.RowStatus(c.QueryParam("rowStatus"))
|
rowStatus := store.RowStatus(c.QueryParam("rowStatus"))
|
||||||
|
@ -390,14 +394,6 @@ func (s *APIV1Service) registerMemoRoutes(g *echo.Group) {
|
||||||
}
|
}
|
||||||
findMemoMessage.ContentSearch = contentSearch
|
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 {
|
if limit, err := strconv.Atoi(c.QueryParam("limit")); err == nil {
|
||||||
findMemoMessage.Limit = &limit
|
findMemoMessage.Limit = &limit
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue