From da55756917fff98e2f144383091ca9cc52918912 Mon Sep 17 00:00:00 2001 From: NikoCat233 Date: Wed, 22 Jul 2026 15:57:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20SpamBlock=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=B6=8A=E6=9D=83=20(#352)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/hooks/spam_block/spam_block.go | 3 +++ server/hooks/spam_block/spam_block_test.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 server/hooks/spam_block/spam_block_test.go diff --git a/server/hooks/spam_block/spam_block.go b/server/hooks/spam_block/spam_block.go index 4d40357e..145c607e 100644 --- a/server/hooks/spam_block/spam_block.go +++ b/server/hooks/spam_block/spam_block.go @@ -63,6 +63,9 @@ func (s *SpamBlock) SettingsHtml(ctx *context.Context, url string, requestData s } return fmt.Sprintf(index, s.cfg.ApiURL, s.cfg.ApiTimeout, s.cfg.Threshold) } + if !ctx.IsAdmin { + return "No Access Privileges" + } var cfg SpamBlockConfig var tempCfg map[string]string diff --git a/server/hooks/spam_block/spam_block_test.go b/server/hooks/spam_block/spam_block_test.go new file mode 100644 index 00000000..9795bcf1 --- /dev/null +++ b/server/hooks/spam_block/spam_block_test.go @@ -0,0 +1,18 @@ +package main + +import ( + "testing" + + "github.com/Jinnrry/pmail/utils/context" +) + +func TestSettingsHtmlRejectsNonAdminSave(t *testing.T) { + s := &SpamBlock{} + result := s.SettingsHtml(&context.Context{}, "SpamBlock/save", `{"url":"https://model.example.com/predict"}`) + if result != "No Access Privileges" { + t.Fatalf("non-admin save result = %q, want access denial", result) + } + if s.cfg.ApiURL != "" { + t.Fatal("non-admin save changed the configuration") + } +}