Broadcast role deletion
This commit is contained in:
@@ -320,6 +320,26 @@ func (m *ManagementStore) DeleteRole(id string) error {
|
|||||||
if err := m.Events.DeleteEvent(event.ID); err != nil {
|
if err := m.Events.DeleteEvent(event.ID); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
address := nostr.EntityPointer{
|
||||||
|
Kind: event.Kind,
|
||||||
|
PublicKey: event.PubKey,
|
||||||
|
Identifier: event.Tags.GetD(),
|
||||||
|
}.AsTagReference()
|
||||||
|
|
||||||
|
event := nostr.Event{
|
||||||
|
Kind: nostr.KindDeletion,
|
||||||
|
CreatedAt: nostr.Now(),
|
||||||
|
Tags: nostr.Tags{
|
||||||
|
nostr.Tag{"e", event.ID.Hex()},
|
||||||
|
nostr.Tag{"a", address},
|
||||||
|
nostr.Tag{"k", strconv.Itoa(int(event.Kind))},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := m.Events.SignAndStoreEvent(&event, true); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m.removeRoleFromMembers(id)
|
return m.removeRoleFromMembers(id)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package zooid
|
package zooid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
@@ -390,6 +391,53 @@ func TestManagementStore_DeleteRole(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestManagementStore_DeleteRole_BroadcastsDeletion(t *testing.T) {
|
||||||
|
mgmt := createTestManagementStore()
|
||||||
|
|
||||||
|
if err := mgmt.CreateRole("king", "King", "", 0, 0); err != nil {
|
||||||
|
t.Fatalf("CreateRole() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
role, ok := mgmt.GetRoleDefinition("king")
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("GetRoleDefinition() should return the created role")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := mgmt.DeleteRole("king"); err != nil {
|
||||||
|
t.Fatalf("DeleteRole() error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
filter := nostr.Filter{Kinds: []nostr.Kind{nostr.KindDeletion}}
|
||||||
|
|
||||||
|
var deletion *nostr.Event
|
||||||
|
for event := range mgmt.Events.QueryEvents(filter, 1) {
|
||||||
|
e := event
|
||||||
|
deletion = &e
|
||||||
|
}
|
||||||
|
|
||||||
|
if deletion == nil {
|
||||||
|
t.Fatal("DeleteRole() should store a deletion event")
|
||||||
|
}
|
||||||
|
|
||||||
|
address := nostr.EntityPointer{
|
||||||
|
Kind: RELAY_ROLE,
|
||||||
|
PublicKey: role.PubKey,
|
||||||
|
Identifier: "king",
|
||||||
|
}.AsTagReference()
|
||||||
|
|
||||||
|
if tag := deletion.Tags.FindWithValue("e", role.ID.Hex()); tag == nil {
|
||||||
|
t.Errorf("deletion event missing e tag for %s", role.ID.Hex())
|
||||||
|
}
|
||||||
|
|
||||||
|
if tag := deletion.Tags.FindWithValue("a", address); tag == nil {
|
||||||
|
t.Errorf("deletion event missing a tag for %s", address)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tag := deletion.Tags.FindWithValue("k", strconv.Itoa(RELAY_ROLE)); tag == nil {
|
||||||
|
t.Errorf("deletion event missing k tag for kind %d", RELAY_ROLE)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestManagementStore_PubkeyIsBanned_NotBanned(t *testing.T) {
|
func TestManagementStore_PubkeyIsBanned_NotBanned(t *testing.T) {
|
||||||
mgmt := createTestManagementStore()
|
mgmt := createTestManagementStore()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user