Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Preserve ACL when saving record with ACL=nil
Browse files Browse the repository at this point in the history
refs #38
  • Loading branch information
cheungpat authored and rickmak committed Jul 21, 2016
1 parent 282a3dc commit 0ebab13
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
6 changes: 5 additions & 1 deletion handler/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,11 @@ func mergeRecord(dst, src *skydb.Record) {
// the same record
func deriveDeltaRecord(dst, base, delta *skydb.Record) {
dst.ID = delta.ID
dst.ACL = delta.ACL
if delta.ACL != nil {
dst.ACL = delta.ACL
} else {
dst.ACL = base.ACL
}
dst.OwnerID = delta.OwnerID
dst.CreatedAt = delta.CreatedAt
dst.CreatorID = delta.CreatorID
Expand Down
44 changes: 44 additions & 0 deletions handler/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2292,3 +2292,47 @@ func TestAtomicOperation(t *testing.T) {
})
})
}

func TestDeriveDeltaRecord(t *testing.T) {
Convey("DeriveDeltaRecord", t, func() {
Convey("set ACL when delta is non-nil", func() {
acl := skydb.RecordACL{
skydb.NewRecordACLEntryDirect("user0", skydb.WriteLevel),
}

dst := skydb.Record{}
base := skydb.Record{
ID: skydb.NewRecordID("record", "id"),
OwnerID: "user0",
}
delta := skydb.Record{
ID: skydb.NewRecordID("record", "id"),
ACL: acl,
}

deriveDeltaRecord(&dst, &base, &delta)

So(dst.ACL, ShouldResemble, acl)
})

Convey("preserve ACL when delta is nil", func() {
acl := skydb.RecordACL{
skydb.NewRecordACLEntryDirect("user0", skydb.WriteLevel),
}

dst := skydb.Record{}
base := skydb.Record{
ID: skydb.NewRecordID("record", "id"),
OwnerID: "user0",
ACL: acl,
}
delta := skydb.Record{
ID: skydb.NewRecordID("record", "id"),
}

deriveDeltaRecord(&dst, &base, &delta)

So(dst.ACL, ShouldResemble, acl)
})
})
}

0 comments on commit 0ebab13

Please sign in to comment.