un/block now respect other permissions. removed uneeded serialize
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Dan Ballard 2022-01-06 14:35:05 -05:00
parent 830e479539
commit e22bda5bc7
2 changed files with 27 additions and 17 deletions

View File

@ -13,12 +13,6 @@ type AccessControl struct {
Append bool // Allows a handle to append new messages to the conversation Append bool // Allows a handle to append new messages to the conversation
} }
// Serialize transforms the AccessControl into json.
func (ac *AccessControl) Serialize() []byte {
data, _ := json.Marshal(ac)
return data
}
// DefaultP2PAccessControl - because in the year 2021, go does not support constant structs... // DefaultP2PAccessControl - because in the year 2021, go does not support constant structs...
func DefaultP2PAccessControl() AccessControl { func DefaultP2PAccessControl() AccessControl {
return AccessControl{Read: true, Append: true, Blocked: false} return AccessControl{Read: true, Append: true, Blocked: false}

View File

@ -503,16 +503,6 @@ func (cp *cwtchPeer) AcceptConversation(id int) error {
// BlockConversation looks up a conversation by `handle` and sets the Blocked ACL field to `true` // BlockConversation looks up a conversation by `handle` and sets the Blocked ACL field to `true`
// This will cause Cwtch to never try to connect to and refuse connections from the peer // This will cause Cwtch to never try to connect to and refuse connections from the peer
func (cp *cwtchPeer) BlockConversation(id int) error { func (cp *cwtchPeer) BlockConversation(id int) error {
return cp.setACL(id, &model.AccessControl{Blocked: true, Read: false, Append: false})
}
// UnblockConversation looks up a conversation by `handle` and sets the Blocked ACL field to `true`
// Further actions depend on the Accepted field
func (cp *cwtchPeer) UnblockConversation(id int) error {
return cp.setACL(id, &model.AccessControl{Blocked: false, Read: false, Append: false})
}
func (cp *cwtchPeer) setACL(id int, acl *model.AccessControl) error {
cp.mutex.Lock() cp.mutex.Lock()
defer cp.mutex.Unlock() defer cp.mutex.Unlock()
ci, err := cp.storage.GetConversation(id) ci, err := cp.storage.GetConversation(id)
@ -521,7 +511,33 @@ func (cp *cwtchPeer) setACL(id int, acl *model.AccessControl) error {
} }
// p2p conversations have a single ACL referencing the remote peer. Set this to blocked... // p2p conversations have a single ACL referencing the remote peer. Set this to blocked...
ci.ACL[ci.Handle] = *acl if ac, exists := ci.ACL[ci.Handle]; exists {
ac.Blocked = true
ci.ACL[ci.Handle] = ac
}
// Send an event in any case to block the protocol engine...
// TODO at some point in the future engine needs to understand ACLs not just legacy auth status
cp.sendUpdateAuth(id, ci.Handle, ci.Accepted, ci.ACL[ci.Handle].Blocked)
return cp.storage.SetConversationACL(id, ci.ACL)
}
// UnblockConversation looks up a conversation by `handle` and sets the Blocked ACL field to `true`
// Further actions depend on the Accepted field
func (cp *cwtchPeer) UnblockConversation(id int) error {
cp.mutex.Lock()
defer cp.mutex.Unlock()
ci, err := cp.storage.GetConversation(id)
if err != nil {
return err
}
// p2p conversations have a single ACL referencing the remote peer. Set ACL's blocked to false...
if ac, exists := ci.ACL[ci.Handle]; exists {
ac.Blocked = false
ci.ACL[ci.Handle] = ac
}
// Send an event in any case to block the protocol engine... // Send an event in any case to block the protocol engine...
// TODO at some point in the future engine needs to understand ACLs not just legacy auth status // TODO at some point in the future engine needs to understand ACLs not just legacy auth status