From 15957b3107deb895cbc324ccef7324957c0675ee Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Thu, 26 Feb 2026 10:47:23 -0800 Subject: [PATCH] Add unban/unallow --- go.mod | 2 +- go.sum | 4 ++-- zooid/management.go | 22 ++++++++++++--------- zooid/management_test.go | 42 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 16c7952..4ef5404 100644 --- a/go.mod +++ b/go.mod @@ -49,4 +49,4 @@ require ( golang.org/x/text v0.28.0 // indirect ) -replace fiatjaf.com/nostr => git.coracle.social/Coracle/nostrlib v0.0.0-20260209224037-43de47addbce +replace fiatjaf.com/nostr => gitea.coracle.social/Coracle/nostrlib v0.0.0-20260226033137-d6812c040a53 diff --git a/go.sum b/go.sum index 0dc8e22..ed8b8d7 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -git.coracle.social/Coracle/nostrlib v0.0.0-20260209224037-43de47addbce h1:FG5FSVNoA37kcojItd0dKfK/o97BitPPFA5+ZUVcQT8= -git.coracle.social/Coracle/nostrlib v0.0.0-20260209224037-43de47addbce/go.mod h1:ue7yw0zHfZj23Ml2kVSdBx0ENEaZiuvGxs/8VEN93FU= +gitea.coracle.social/Coracle/nostrlib v0.0.0-20260226033137-d6812c040a53 h1:HJ7KJ7IhEtqOe5vR3fPBIDYksTr75kbvICFiMurhgYY= +gitea.coracle.social/Coracle/nostrlib v0.0.0-20260226033137-d6812c040a53/go.mod h1:ue7yw0zHfZj23Ml2kVSdBx0ENEaZiuvGxs/8VEN93FU= github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/ImVexed/fasturl v0.0.0-20230304231329-4e41488060f3 h1:ClzzXMDDuUbWfNNZqGeYq4PnYOlwlOVIvSyNaIy0ykg= diff --git a/zooid/management.go b/zooid/management.go index 744f361..bbff49c 100644 --- a/zooid/management.go +++ b/zooid/management.go @@ -249,6 +249,10 @@ func (m *ManagementStore) BanPubkey(pubkey nostr.PubKey, reason string) error { return nil } +func (m *ManagementStore) UnbanPubkey(pubkey nostr.PubKey, reason string) error { + return m.RemoveBannedPubkey(pubkey) +} + // Allowing func (m *ManagementStore) GetAllowedPubkeyItems() []nip86.PubKeyReason { @@ -278,6 +282,10 @@ func (m *ManagementStore) AllowPubkey(pubkey nostr.PubKey) error { return nil } +func (m *ManagementStore) UnallowPubkey(pubkey nostr.PubKey, reason string) error { + return m.RemoveMember(pubkey) +} + // Joining func (m *ManagementStore) ValidateJoinRequest(event nostr.Event) (reject bool, err string) { @@ -343,21 +351,17 @@ func (m *ManagementStore) Enable(instance *Instance) { return m.BanPubkey(pubkey, reason) } - instance.Relay.ManagementAPI.BanPubKey = func(ctx context.Context, pubkey nostr.PubKey, reason string) error { - return m.BanPubkey(pubkey, reason) + instance.Relay.ManagementAPI.UnbanPubKey = func(ctx context.Context, pubkey nostr.PubKey, reason string) error { + return m.UnbanPubkey(pubkey, reason) } - // instance.Relay.ManagementAPI.UnbanPubKey = func(ctx context.Context, pubkey nostr.PubKey, reason string) error { - // return m.RemoveBannedPubkey(pubkey) - // } - instance.Relay.ManagementAPI.AllowPubKey = func(ctx context.Context, pubkey nostr.PubKey, reason string) error { return m.AllowPubkey(pubkey) } - // instance.Relay.ManagementAPI.UnallowPubKey = func(ctx context.Context, pubkey nostr.PubKey, reason string) error { - // return m.RemoveMember(pubkey) - // } + instance.Relay.ManagementAPI.UnallowPubKey = func(ctx context.Context, pubkey nostr.PubKey, reason string) error { + return m.UnallowPubkey(pubkey, reason) + } instance.Relay.ManagementAPI.ListBannedPubKeys = func(ctx context.Context) ([]nip86.PubKeyReason, error) { return m.GetBannedPubkeyItems(), nil diff --git a/zooid/management_test.go b/zooid/management_test.go index 696d3bc..bdad552 100644 --- a/zooid/management_test.go +++ b/zooid/management_test.go @@ -75,6 +75,48 @@ func TestManagementStore_AllowPubkey(t *testing.T) { } } +func TestManagementStore_UnbanPubkey(t *testing.T) { + mgmt := createTestManagementStore() + + pubkey := nostr.Generate().Public() + + mgmt.BanPubkey(pubkey, "test") + + if !mgmt.PubkeyIsBanned(pubkey) { + t.Error("Setup: pubkey should be banned") + } + + if err := mgmt.UnbanPubkey(pubkey, "appeal accepted"); err != nil { + t.Fatalf("UnbanPubkey() should not return error: %v", err) + } + + if mgmt.PubkeyIsBanned(pubkey) { + t.Error("PubkeyIsBanned() should return false after unbanning") + } +} + +func TestManagementStore_UnallowPubkey(t *testing.T) { + mgmt := createTestManagementStore() + + pubkey := nostr.Generate().Public() + + if err := mgmt.AllowPubkey(pubkey); err != nil { + t.Fatalf("AllowPubkey() should not return error: %v", err) + } + + if !mgmt.IsMember(pubkey) { + t.Error("Setup: pubkey should be a member") + } + + if err := mgmt.UnallowPubkey(pubkey, "membership revoked"); err != nil { + t.Fatalf("UnallowPubkey() should not return error: %v", err) + } + + if mgmt.IsMember(pubkey) { + t.Error("IsMember() should return false after unallowing") + } +} + func TestManagementStore_BanEvent(t *testing.T) { mgmt := createTestManagementStore()