Add unban/unallow

This commit is contained in:
Jon Staab
2026-02-26 10:47:23 -08:00
parent e13557703c
commit 15957b3107
4 changed files with 58 additions and 12 deletions
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+13 -9
View File
@@ -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
+42
View File
@@ -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()