Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: revert resource visibility changes (#1444)

boojack41c50e758aee
diff --git a/api/resource.go b/api/resource.go
index 3ee90d9d8..b412c44a5 100644
--- a/api/resource.go
+++ b/api/resource.go
@@ -9,13 +9,12 @@ type Resource struct {
UpdatedTs int64 `json:"updatedTs"`
// Domain specific fields
- Filename string `json:"filename"`
- Blob []byte `json:"-"`
- InternalPath string `json:"internalPath"`
- ExternalLink string `json:"externalLink"`
- Type string `json:"type"`
- Size int64 `json:"size"`
- Visibility Visibility `json:"visibility"`
+ Filename string `json:"filename"`
+ Blob []byte `json:"-"`
+ InternalPath string `json:"internalPath"`
+ ExternalLink string `json:"externalLink"`
+ Type string `json:"type"`
+ Size int64 `json:"size"`
// Related fields
LinkedMemoAmount int `json:"linkedMemoAmount"`
@@ -26,13 +25,12 @@ type ResourceCreate struct {
CreatorID int `json:"-"`
// Domain specific fields
- Filename string `json:"filename"`
- Blob []byte `json:"-"`
- InternalPath string `json:"internalPath"`
- ExternalLink string `json:"externalLink"`
- Type string `json:"type"`
- Size int64 `json:"-"`
- Visibility Visibility `json:"visibility"`
+ Filename string `json:"filename"`
+ Blob []byte `json:"-"`
+ InternalPath string `json:"internalPath"`
+ ExternalLink string `json:"externalLink"`
+ Type string `json:"type"`
+ Size int64 `json:"-"`
}
type ResourceFind struct {
@@ -58,8 +56,7 @@ type ResourcePatch struct {
UpdatedTs *int64
// Domain specific fields
- Filename *string `json:"filename"`
- Visibility *Visibility `json:"visibility"`
+ Filename *string `json:"filename"`
}
type ResourceDelete struct {
diff --git a/server/resource.go b/server/resource.go
index bd2c46b70..0d64c1701 100644
--- a/server/resource.go
+++ b/server/resource.go
@@ -47,27 +47,6 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
if resourceCreate.ExternalLink != "" && !strings.HasPrefix(resourceCreate.ExternalLink, "http") {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid external link")
}
- if resourceCreate.Visibility == "" {
- userResourceVisibilitySetting, err := s.Store.FindUserSetting(ctx, &api.UserSettingFind{
- UserID: userID,
- Key: api.UserSettingResourceVisibilityKey,
- })
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user setting").SetInternal(err)
- }
-
- if userResourceVisibilitySetting != nil {
- resourceVisibility := api.Private
- err := json.Unmarshal([]byte(userResourceVisibilitySetting.Value), &resourceVisibility)
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal user setting value").SetInternal(err)
- }
- resourceCreate.Visibility = resourceVisibility
- } else {
- // Private is the default resource visibility.
- resourceCreate.Visibility = api.Private
- }
- }
resource, err := s.Store.CreateResource(ctx, resourceCreate)
if err != nil {
@@ -215,28 +194,6 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
}
}
- if resourceCreate.Visibility == "" {
- userResourceVisibilitySetting, err := s.Store.FindUserSetting(ctx, &api.UserSettingFind{
- UserID: userID,
- Key: api.UserSettingResourceVisibilityKey,
- })
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find user setting").SetInternal(err)
- }
-
- if userResourceVisibilitySetting != nil {
- resourceVisibility := api.Private
- err := json.Unmarshal([]byte(userResourceVisibilitySetting.Value), &resourceVisibility)
- if err != nil {
- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to unmarshal user setting value").SetInternal(err)
- }
- resourceCreate.Visibility = resourceVisibility
- } else {
- // Private is the default resource visibility.
- resourceCreate.Visibility = api.Private
- }
- }
-
resource, err := s.Store.CreateResource(ctx, resourceCreate)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create resource").SetInternal(err)
diff --git a/store/db/migration/dev/LATEST__SCHEMA.sql b/store/db/migration/dev/LATEST__SCHEMA.sql
index 60d0063b7..1e50942fd 100644
--- a/store/db/migration/dev/LATEST__SCHEMA.sql
+++ b/store/db/migration/dev/LATEST__SCHEMA.sql
@@ -77,8 +77,7 @@ CREATE TABLE resource (
internal_path TEXT NOT NULL DEFAULT '',
external_link TEXT NOT NULL DEFAULT '',
type TEXT NOT NULL DEFAULT '',
- size INTEGER NOT NULL DEFAULT 0,
- visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE'
+ size INTEGER NOT NULL DEFAULT 0
);
-- memo_resource
diff --git a/store/resource.go b/store/resource.go
index f5f3c3c7b..943597fef 100644
--- a/store/resource.go
+++ b/store/resource.go
@@ -28,7 +28,6 @@ type resourceRaw struct {
ExternalLink string
Type string
Size int64
- Visibility api.Visibility
LinkedMemoAmount int
}
@@ -48,7 +47,6 @@ func (raw *resourceRaw) toResource() *api.Resource {
ExternalLink: raw.ExternalLink,
Type: raw.Type,
Size: raw.Size,
- Visibility: raw.Visibility,
LinkedMemoAmount: raw.LinkedMemoAmount,
}
}
@@ -197,9 +195,9 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api.
values := []any{create.Filename, create.Blob, create.ExternalLink, create.Type, create.Size, create.CreatorID}
placeholders := []string{"?", "?", "?", "?", "?", "?"}
if s.profile.IsDev() {
- fields = append(fields, "visibility", "internal_path")
- values = append(values, create.Visibility, create.InternalPath)
- placeholders = append(placeholders, "?", "?")
+ fields = append(fields, "internal_path")
+ values = append(values, create.InternalPath)
+ placeholders = append(placeholders, "?")
}
query := `
@@ -220,7 +218,7 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api.
&resourceRaw.CreatorID,
}
if s.profile.IsDev() {
- dests = append(dests, &resourceRaw.Visibility, &resourceRaw.InternalPath)
+ dests = append(dests, &resourceRaw.InternalPath)
}
dests = append(dests, []any{&resourceRaw.CreatedTs, &resourceRaw.UpdatedTs}...)
if err := tx.QueryRowContext(ctx, query, values...).Scan(dests...); err != nil {
@@ -239,17 +237,12 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re
if v := patch.Filename; v != nil {
set, args = append(set, "filename = ?"), append(args, *v)
}
- if s.profile.IsDev() {
- if v := patch.Visibility; v != nil {
- set, args = append(set, "visibility = ?"), append(args, *v)
- }
- }
args = append(args, patch.ID)
fields := []string{"id", "filename", "external_link", "type", "size", "creator_id", "created_ts", "updated_ts"}
if s.profile.IsDev() {
- fields = append(fields, "visibility", "internal_path")
+ fields = append(fields, "internal_path")
}
query := `
@@ -269,7 +262,7 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re
&resourceRaw.UpdatedTs,
}
if s.profile.IsDev() {
- dests = append(dests, &resourceRaw.Visibility, &resourceRaw.InternalPath)
+ dests = append(dests, &resourceRaw.InternalPath)
}
if err := tx.QueryRowContext(ctx, query, args...).Scan(dests...); err != nil {
return nil, FormatError(err)
@@ -299,7 +292,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api.
fields = append(fields, "resource.blob")
}
if s.profile.IsDev() {
- fields = append(fields, "visibility", "internal_path")
+ fields = append(fields, "internal_path")
}
query := fmt.Sprintf(`
@@ -343,7 +336,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api.
dests = append(dests, &resourceRaw.Blob)
}
if s.profile.IsDev() {
- dests = append(dests, &resourceRaw.Visibility, &resourceRaw.InternalPath)
+ dests = append(dests, &resourceRaw.InternalPath)
}
if err := rows.Scan(dests...); err != nil {
return nil, FormatError(err)