Add unban/unallow
This commit is contained in:
+13
-9
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user