mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
fix: create memo with visibility (#281)
This commit is contained in:
@@ -24,8 +24,6 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
|
|
||||||
memoCreate := &api.MemoCreate{
|
memoCreate := &api.MemoCreate{
|
||||||
CreatorID: userID,
|
CreatorID: userID,
|
||||||
// Private is the default memo visibility.
|
|
||||||
Visibility: api.Privite,
|
|
||||||
}
|
}
|
||||||
if err := json.NewDecoder(c.Request().Body).Decode(memoCreate); err != nil {
|
if err := json.NewDecoder(c.Request().Body).Decode(memoCreate); err != nil {
|
||||||
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post memo request").SetInternal(err)
|
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted post memo request").SetInternal(err)
|
||||||
@@ -34,21 +32,27 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
return echo.NewHTTPError(http.StatusBadRequest, "Memo content shouldn't be empty")
|
return echo.NewHTTPError(http.StatusBadRequest, "Memo content shouldn't be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
userSettingMemoVisibilityKey := api.UserSettingMemoVisibilityKey
|
if memoCreate.Visibility == "" {
|
||||||
userMemoVisibilitySetting, err := s.Store.FindUserSetting(ctx, &api.UserSettingFind{
|
userSettingMemoVisibilityKey := api.UserSettingMemoVisibilityKey
|
||||||
UserID: userID,
|
userMemoVisibilitySetting, err := s.Store.FindUserSetting(ctx, &api.UserSettingFind{
|
||||||
Key: &userSettingMemoVisibilityKey,
|
UserID: userID,
|
||||||
})
|
Key: &userSettingMemoVisibilityKey,
|
||||||
if err != nil {
|
})
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user setting").SetInternal(err)
|
|
||||||
}
|
|
||||||
if userMemoVisibilitySetting != nil {
|
|
||||||
memoVisibility := api.Privite
|
|
||||||
err := json.Unmarshal([]byte(userMemoVisibilitySetting.Value), &memoVisibility)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal user setting value").SetInternal(err)
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user setting").SetInternal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if userMemoVisibilitySetting != nil {
|
||||||
|
memoVisibility := api.Privite
|
||||||
|
err := json.Unmarshal([]byte(userMemoVisibilitySetting.Value), &memoVisibility)
|
||||||
|
if err != nil {
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal user setting value").SetInternal(err)
|
||||||
|
}
|
||||||
|
memoCreate.Visibility = memoVisibility
|
||||||
|
} else {
|
||||||
|
// Private is the default memo visibility.
|
||||||
|
memoCreate.Visibility = api.Privite
|
||||||
}
|
}
|
||||||
memoCreate.Visibility = memoVisibility
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memo, err := s.Store.CreateMemo(ctx, memoCreate)
|
memo, err := s.Store.CreateMemo(ctx, memoCreate)
|
||||||
|
Reference in New Issue
Block a user