Skip to content

Commit 7618392

Browse files
authored
Keep the metadata.favorite for shared io.cozy.files (#4489)
2 parents 575c6aa + 0ee6964 commit 7618392

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

model/sharing/files.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,10 @@ func fileToJSONDoc(file *vfs.FileDoc, instanceURL string) couchdb.JSONDoc {
14041404
doc.M["restore_path"] = file.RestorePath
14051405
}
14061406
if len(file.Metadata) > 0 {
1407-
doc.M["metadata"] = file.Metadata.RemoveCertifiedMetadata()
1407+
meta := file.Metadata
1408+
meta = meta.RemoveCertifiedMetadata()
1409+
meta = meta.RemoveFavoriteMetadata()
1410+
doc.M["metadata"] = meta
14081411
}
14091412
fcm := file.CozyMetadata
14101413
if fcm == nil {

model/vfs/metadata.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ func MergeMetadata(doc *FileDoc, meta Metadata) {
6060
}
6161
}
6262

63+
// RemoveFavoriteMetadata returns a metadata map where the favorite key has been
64+
// removed. It can be useful for sharing, as favorite metadata are only valid
65+
// localy.
66+
func (m Metadata) RemoveFavoriteMetadata() Metadata {
67+
if len(m) == 0 {
68+
return Metadata{}
69+
}
70+
result := make(Metadata, len(m))
71+
for k, v := range m {
72+
if k == consts.FavoriteKey {
73+
continue
74+
}
75+
result[k] = v
76+
}
77+
return result
78+
}
79+
6380
// RemoveCertifiedMetadata returns a metadata map where the keys that are
6481
// certified have been removed. It can be useful for sharing, as certified
6582
// metadata are only valid localy.

pkg/consts/file.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
CarbonCopyKey = "carbonCopy"
3636
// ElectronicSafeKey is the metadata key for an electronic safe (certified)
3737
ElectronicSafeKey = "electronicSafe"
38+
// FavoriteKey is the metadata key for a favorite.
39+
FavoriteKey = "favorite"
3840
)
3941

4042
const (

0 commit comments

Comments
 (0)