diff --git a/README.md b/README.md index 61ba1fc0..8462eef6 100644 --- a/README.md +++ b/README.md @@ -41,13 +41,15 @@ Remark42 is a self-hosted, lightweight, and simple (yet functional) comment engi | --max-cache-value | MAX_CACHE_VALUE | `65536` | no | max size of cached value, o-unlimited | | --session | SESSION_STORE | `/tmp` | no | path to session store directory | | --secret | SECRET | | no | secret key, required | -| --max-comment | MAX_COMMENT_SIZE | `2048` | no | comment's size limit | +| --max-comment | MAX_COMMENT_SIZE | 2048 | no | comment's size limit | | --google-cid | REMARK_GOOGLE_CID | | no | Google OAuth client ID | | --google-csec | REMARK_GOOGLE_CSEC | | no | Google OAuth client secret | | --facebook-cid | REMARK_FACEBOOK_CID | | no | Facebook OAuth client ID | | --facebook-csec | REMARK_FACEBOOK_CSEC | | no | Facebook OAuth client secret | | --github-cid | REMARK_GITHUB_CID | | no | Github OAuth client ID | | --github-csec | REMARK_GITHUB_CSEC | | no | Github OAuth client secret | +| --low-score | LOW_SCORE | `-5` | no | Low score threshold | +| --critical-score | CRITICAL_SCORE | `-10` | no | Critical score threshold | | --dbg | DEBUG | `false` | no | debug mode | | --dev-password | DEV_PASSWD | | no | password for `dev` user | @@ -325,10 +327,12 @@ Sort can be `time`, `active` or `score`. Supported sort order with prefix -/+, i ```go type config struct { - Version string `json:"version"` - EditDuration int `json:"edit_duration"` // seconds - Admins []string `json:"admins"` - Auth []string `json:"auth_providers"` + Version string `json:"version"` + EditDuration int `json:"edit_duration"` // seconds + Admins []string `json:"admins"` + Auth []string `json:"auth_providers"` + LowScore int `json:"low_score"` + CriticalScore int `json:"critical_score"` } ``` diff --git a/app/main.go b/app/main.go index 18279aa4..6cc22601 100644 --- a/app/main.go +++ b/app/main.go @@ -43,6 +43,9 @@ var opts struct { MaxCachedItems int `long:"max-cache-items" env:"MAX_CACHE_ITEMS" default:"1000" description:"max cached items"` MaxCachedValue int `long:"max-cache-value" env:"MAX_CACHE_VALUE" default:"65536" description:"max size of cached value"` + LowScore int `long:"low-score" env:"LOW_SCORE" default:"-5" description:"low score threshold"` + CriticalScore int `long:"critical-score" env:"CRITICAL_SCORE" default:"-10" description:"critical score threshold"` + GoogleCID string `long:"google-cid" env:"REMARK_GOOGLE_CID" description:"Google OAuth client ID"` GoogleCSEC string `long:"google-csec" env:"REMARK_GOOGLE_CSEC" description:"Google OAuth client secret"` GithubCID string `long:"github-cid" env:"REMARK_GITHUB_CID" description:"Github OAuth client ID"` @@ -129,6 +132,7 @@ func main() { }, Cache: cache, } + srv.ScoreThresholds.Low, srv.ScoreThresholds.Critical = opts.LowScore, opts.CriticalScore srv.Run(opts.Port) } diff --git a/app/rest/api/rest.go b/app/rest/api/rest.go index 60a95bd3..20ece30e 100644 --- a/app/rest/api/rest.go +++ b/app/rest/api/rest.go @@ -37,6 +37,11 @@ type Rest struct { Cache rest.LoadingCache WebRoot string + ScoreThresholds struct { + Low int + Critical int + } + httpServer *http.Server adminService admin } @@ -376,6 +381,8 @@ func (s *Rest) configCtrl(w http.ResponseWriter, r *http.Request) { MaxCommentSize int `json:"max_comment_size"` Admins []string `json:"admins"` Auth []string `json:"auth_providers"` + LowScore int `json:"low_score"` + CriticalScore int `json:"critical_score"` } cnf := config{ @@ -383,6 +390,8 @@ func (s *Rest) configCtrl(w http.ResponseWriter, r *http.Request) { EditDuration: int(s.DataService.EditDuration.Seconds()), MaxCommentSize: s.DataService.MaxCommentSize, Admins: s.Authenticator.Admins, + LowScore: s.ScoreThresholds.Low, + CriticalScore: s.ScoreThresholds.Critical, } authNames := []string{} for _, ap := range s.Authenticator.Providers { diff --git a/app/rest/api/rest_test.go b/app/rest/api/rest_test.go index 7bd02333..a150c2a2 100644 --- a/app/rest/api/rest_test.go +++ b/app/rest/api/rest_test.go @@ -450,6 +450,8 @@ func TestServer_Config(t *testing.T) { assert.Equal(t, 300., j["edit_duration"]) assert.EqualValues(t, []interface{}([]interface{}{"a1", "a2"}), j["admins"]) assert.Equal(t, 4000., j["max_comment_size"]) + assert.Equal(t, -5., j["low_score"]) + assert.Equal(t, -10., j["critical_score"]) t.Logf("%+v", j) } @@ -480,6 +482,7 @@ func prep(t *testing.T) (srv *Rest, port int) { Cache: &mockCache{}, WebRoot: "/tmp", } + srv.ScoreThresholds.Low, srv.ScoreThresholds.Critical = -5, -10 importSrv := &Import{ DisqusImporter: &migrator.Disqus{DataStore: &dataStore},