Skip to content

Commit

Permalink
Keep the metadata.favorite for shared io.cozy.files (#4489)
Browse files Browse the repository at this point in the history
  • Loading branch information
nono authored Nov 13, 2024
2 parents 575c6aa + 0ee6964 commit 7618392
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion model/sharing/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,10 @@ func fileToJSONDoc(file *vfs.FileDoc, instanceURL string) couchdb.JSONDoc {
doc.M["restore_path"] = file.RestorePath
}
if len(file.Metadata) > 0 {
doc.M["metadata"] = file.Metadata.RemoveCertifiedMetadata()
meta := file.Metadata
meta = meta.RemoveCertifiedMetadata()
meta = meta.RemoveFavoriteMetadata()
doc.M["metadata"] = meta
}
fcm := file.CozyMetadata
if fcm == nil {
Expand Down
17 changes: 17 additions & 0 deletions model/vfs/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ func MergeMetadata(doc *FileDoc, meta Metadata) {
}
}

// RemoveFavoriteMetadata returns a metadata map where the favorite key has been
// removed. It can be useful for sharing, as favorite metadata are only valid
// localy.
func (m Metadata) RemoveFavoriteMetadata() Metadata {
if len(m) == 0 {
return Metadata{}
}
result := make(Metadata, len(m))
for k, v := range m {
if k == consts.FavoriteKey {
continue
}
result[k] = v
}
return result
}

// RemoveCertifiedMetadata returns a metadata map where the keys that are
// certified have been removed. It can be useful for sharing, as certified
// metadata are only valid localy.
Expand Down
2 changes: 2 additions & 0 deletions pkg/consts/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
CarbonCopyKey = "carbonCopy"
// ElectronicSafeKey is the metadata key for an electronic safe (certified)
ElectronicSafeKey = "electronicSafe"
// FavoriteKey is the metadata key for a favorite.
FavoriteKey = "favorite"
)

const (
Expand Down

0 comments on commit 7618392

Please sign in to comment.