Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

feat(plugin): add captcha plugin status coordinate

LinkinStarsa111a0c39189
diff --git a/plugin/captcha.go b/plugin/captcha.go
index 81ee0e13..96047e67 100644
--- a/plugin/captcha.go
+++ b/plugin/captcha.go
@@ -63,3 +63,20 @@ func CaptchaEnabled() (enabled bool) {
})
return
}
+
+func coordinatedCaptchaPlugins(slugName string) (enabledSlugNames []string) {
+ isCaptcha := false
+ _ = callCaptcha(func(captcha Captcha) error {
+ name := captcha.Info().SlugName
+ if slugName == name {
+ isCaptcha = true
+ } else {
+ enabledSlugNames = append(enabledSlugNames, name)
+ }
+ return nil
+ })
+ if isCaptcha {
+ return enabledSlugNames
+ }
+ return nil
+}
diff --git a/plugin/plugin.go b/plugin/plugin.go
index 6e491252..2093d0bd 100644
--- a/plugin/plugin.go
+++ b/plugin/plugin.go
@@ -150,7 +150,14 @@ type statusManager struct {
func (m *statusManager) Enable(name string, enabled bool) {
m.lock.Lock()
defer m.lock.Unlock()
+ if !enabled {
+ m.status[name] = enabled
+ return
+ }
m.status[name] = enabled
+ for _, slugName := range coordinatedCaptchaPlugins(name) {
+ m.status[slugName] = false
+ }
}
func (m *statusManager) IsEnabled(name string) bool {