From 9eadb003975f38664424ff4f0ee815114c00841d Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Tue, 3 Oct 2023 21:18:06 -0600 Subject: [PATCH] Added default group policy --- group.go | 30 ++++++++++-------------------- policy.go | 2 +- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/group.go b/group.go index fca4383..b6747d6 100644 --- a/group.go +++ b/group.go @@ -1,36 +1,26 @@ package graphvent import ( - "encoding/json" ) -type GroupExt struct { - Members map[NodeID]string `gv:"members"` -} +var GroupReadPolicy = NewAllNodesPolicy(Tree{ + SerializedType(ReadSignalType): { + SerializedType(GroupExtType): { + Hash(FieldNameBase, "members"): nil, + }, + }, +}) -func (ext *GroupExt) Type() ExtType { - return GroupExtType -} - -func (ext *GroupExt) MarshalBinary() ([]byte, error) { - return json.Marshal(ext) +type GroupExt struct { + Members []NodeID `gv:"members"` } -func NewGroupExt(members map[NodeID]string) *GroupExt { - if members == nil { - members = map[NodeID]string{} - } - +func NewGroupExt(members []NodeID) *GroupExt { return &GroupExt{ Members: members, } } -func (ext *GroupExt) Deserialize(ctx *Context, data []byte) error { - ext.Members = map[NodeID]string{} - return json.Unmarshal(data, ext) -} - func (ext *GroupExt) Process(ctx *Context, node *Node, source NodeID, signal Signal) Messages { return nil } diff --git a/policy.go b/policy.go index 4d1e616..c262247 100644 --- a/policy.go +++ b/policy.go @@ -137,7 +137,7 @@ func (policy MemberOfPolicy) Allows(ctx *Context, principal_id NodeID, action Tr if id == node.ID { ext, err := GetExt[*GroupExt](node, GroupExtType) if err == nil { - for member := range(ext.Members) { + for _, member := range(ext.Members) { if member == principal_id { if rule.Allows(action) == Allow { return nil, Allow