mirror of
https://github.com/usememos/memos.git
synced 2025-02-16 03:12:13 +01:00
chore: disable setting memo visibility when creating
This commit is contained in:
parent
05a5c59a7e
commit
3b1bb4a95d
@ -46,8 +46,8 @@ type MemoCreate struct {
|
|||||||
CreatedTs *int64 `json:"createdTs"`
|
CreatedTs *int64 `json:"createdTs"`
|
||||||
|
|
||||||
// Domain specific fields
|
// Domain specific fields
|
||||||
Content string `json:"content"`
|
Visibility Visibility
|
||||||
Visibility *Visibility `json:"visibility"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemoPatch struct {
|
type MemoPatch struct {
|
||||||
|
@ -22,11 +22,17 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if memoCreate.Content == "" {
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest, "Memo content shouldn't be empty")
|
||||||
|
}
|
||||||
|
|
||||||
userSettingMemoVisibilityKey := api.UserSettingMemoVisibilityKey
|
userSettingMemoVisibilityKey := api.UserSettingMemoVisibilityKey
|
||||||
userMemoVisibilitySetting, err := s.Store.FindUserSetting(ctx, &api.UserSettingFind{
|
userMemoVisibilitySetting, err := s.Store.FindUserSetting(ctx, &api.UserSettingFind{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
@ -38,12 +44,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
|
|||||||
if userMemoVisibilitySetting != nil {
|
if userMemoVisibilitySetting != nil {
|
||||||
memoVisibility := api.Privite
|
memoVisibility := api.Privite
|
||||||
json.Unmarshal([]byte(userMemoVisibilitySetting.Value), &memoVisibility)
|
json.Unmarshal([]byte(userMemoVisibilitySetting.Value), &memoVisibility)
|
||||||
memoCreate.Visibility = &memoVisibility
|
memoCreate.Visibility = memoVisibility
|
||||||
}
|
|
||||||
|
|
||||||
if memoCreate.Visibility == nil || *memoCreate.Visibility == "" {
|
|
||||||
private := api.Privite
|
|
||||||
memoCreate.Visibility = &private
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memo, err := s.Store.CreateMemo(ctx, memoCreate)
|
memo, err := s.Store.CreateMemo(ctx, memoCreate)
|
||||||
|
@ -201,13 +201,10 @@ func (s *Store) DeleteMemo(ctx context.Context, delete *api.MemoDelete) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createMemoRaw(ctx context.Context, tx *sql.Tx, create *api.MemoCreate) (*memoRaw, error) {
|
func createMemoRaw(ctx context.Context, tx *sql.Tx, create *api.MemoCreate) (*memoRaw, error) {
|
||||||
set := []string{"creator_id", "content"}
|
set := []string{"creator_id", "content", "visibility"}
|
||||||
placeholder := []string{"?", "?"}
|
placeholder := []string{"?", "?", "?"}
|
||||||
args := []interface{}{create.CreatorID, create.Content}
|
args := []interface{}{create.CreatorID, create.Content, create.Visibility}
|
||||||
|
|
||||||
if v := create.Visibility; v != nil {
|
|
||||||
set, placeholder, args = append(set, "visibility"), append(placeholder, "?"), append(args, *v)
|
|
||||||
}
|
|
||||||
if v := create.CreatedTs; v != nil {
|
if v := create.CreatedTs; v != nil {
|
||||||
set, placeholder, args = append(set, "created_ts"), append(placeholder, "?"), append(args, *v)
|
set, placeholder, args = append(set, "created_ts"), append(placeholder, "?"), append(args, *v)
|
||||||
}
|
}
|
||||||
|
1
web/src/types/modules/memo.d.ts
vendored
1
web/src/types/modules/memo.d.ts
vendored
@ -17,7 +17,6 @@ interface Memo {
|
|||||||
|
|
||||||
interface MemoCreate {
|
interface MemoCreate {
|
||||||
content: string;
|
content: string;
|
||||||
visibility?: Visibility;
|
|
||||||
createdTs?: TimeStamp;
|
createdTs?: TimeStamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user