Skip to content

Commit

Permalink
Fix expires_at: null in CouchDB
Browse files Browse the repository at this point in the history
This issue was discovered by @Merkur39. When creating an
io.cozy.permissions for a share by link, the expires_at field was set to
null in CouchDB, even if the field was declared as omitempty. A nil
pointer to a time.Time is not considered by Go as an empty value for a
field of the type interface{}. So, we need to use the empty value of
type interface{} instead to fix the JSON marshaling.
  • Loading branch information
nono committed Jan 21, 2025
1 parent b5c32e3 commit 64f57e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion model/permission/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,14 @@ func checkSetPermissions(set Set, parent *Permission) error {
}

// CreateShareSet creates a Permission doc for sharing by link
func CreateShareSet(db prefixer.Prefixer, parent *Permission, sourceID string, codes, shortcodes map[string]string, subdoc Permission, expiresAt *time.Time) (*Permission, error) {
func CreateShareSet(
db prefixer.Prefixer,
parent *Permission,
sourceID string,
codes, shortcodes map[string]string,
subdoc Permission,
expiresAt interface{},
) (*Permission, error) {
set := subdoc.Permissions
if err := checkSetPermissions(set, parent); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion web/permissions/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func createPermission(c echo.Context) error {
return err
}

var expiresAt *time.Time
var expiresAt interface{}
if ttl != "" {
if d, errd := bigduration.ParseDuration(ttl); errd == nil {
ex := time.Now().Add(d)
Expand Down

0 comments on commit 64f57e3

Please sign in to comment.