add admin email #73

This commit is contained in:
Umputun
2018-06-06 14:26:04 -05:00
parent 0374cafa7e
commit 12bf50bb96
6 changed files with 26 additions and 8 deletions
+17 -7
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"os/signal"
"strings"
@@ -27,13 +28,13 @@ import (
// Opts with command line flags and env
type Opts struct {
BoltPath string `long:"bolt" env:"BOLTDB_PATH" default:"./var" description:"parent dir for bolt files"`
Sites []string `long:"site" env:"SITE" default:"remark" description:"site names" env-delim:","`
RemarkURL string `long:"url" env:"REMARK_URL" default:"https://remark42.com" description:"url to remark"`
Admins []string `long:"admin" env:"ADMIN" description:"admin(s) names" env-delim:","`
DevPasswd string `long:"dev-passwd" env:"DEV_PASSWD" default:"" description:"development mode password"`
Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"`
BoltPath string `long:"bolt" env:"BOLTDB_PATH" default:"./var" description:"parent dir for bolt files"`
Sites []string `long:"site" env:"SITE" default:"remark" description:"site names" env-delim:","`
RemarkURL string `long:"url" env:"REMARK_URL" default:"https://remark42.com" description:"url to remark"`
Admins []string `long:"admin" env:"ADMIN" description:"admin(s) names" env-delim:","`
AdminEmail string `long:"admin-email" env:"ADMIN_EMAIL" default:"" description:"admin email"`
DevPasswd string `long:"dev-passwd" env:"DEV_PASSWD" default:"" description:"development mode password"`
Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"`
BackupLocation string `long:"backup" env:"BACKUP_PATH" default:"./var/backup" description:"backups location"`
MaxBackupFiles int `long:"max-back" env:"MAX_BACKUP_FILES" default:"10" description:"max backups to keep"`
@@ -154,11 +155,20 @@ func New(opts Opts) (*Application, error) {
Authenticator: auth.Authenticator{
JWTService: jwtService,
Admins: opts.Admins,
AdminEmail: opts.AdminEmail,
Providers: makeAuthProviders(jwtService, avatarProxy, dataService, opts),
DevPasswd: opts.DevPasswd,
},
Cache: loadingCache,
}
// no admin email, use admin@domain
if srv.Authenticator.AdminEmail == "" {
if u, err := url.Parse(opts.RemarkURL); err == nil {
srv.Authenticator.AdminEmail = "admin@" + u.Host
}
}
srv.ScoreThresholds.Low, srv.ScoreThresholds.Critical = opts.LowScore, opts.CriticalScore
tch := make(chan struct{})
return &Application{restSrv: srv, migratorSrv: migr, exporter: exporter, Opts: opts, terminated: tch}, nil
+4 -1
View File
@@ -38,6 +38,9 @@ func TestApplication(t *testing.T) {
assert.Equal(t, http.StatusCreated, resp.StatusCode)
body, _ = ioutil.ReadAll(resp.Body)
t.Log(string(body))
assert.Equal(t, "admin@demo.remark42.com", app.restSrv.Authenticator.AdminEmail, "default admin email")
app.Wait()
}
@@ -64,7 +67,7 @@ func prepApp(t *testing.T, port int, duration time.Duration) (*Application, cont
// prepare options
opts := Opts{}
p := flags.NewParser(&opts, flags.Default)
p.ParseArgs([]string{"--secret=123456", "--dev-passwd=password"})
p.ParseArgs([]string{"--secret=123456", "--dev-passwd=password", "--url=https://demo.remark42.com"})
opts.AvatarStore, opts.BackupLocation = "/tmp", "/tmp"
opts.BoltPath = fmt.Sprintf("/tmp/%d", port)
opts.GithubCSEC, opts.GithubCID = "csec", "cid"
+2
View File
@@ -204,6 +204,7 @@ func (s *Rest) configCtrl(w http.ResponseWriter, r *http.Request) {
EditDuration int `json:"edit_duration"`
MaxCommentSize int `json:"max_comment_size"`
Admins []string `json:"admins"`
AdminEmail string `json:"admin_email"`
Auth []string `json:"auth_providers"`
LowScore int `json:"low_score"`
CriticalScore int `json:"critical_score"`
@@ -215,6 +216,7 @@ func (s *Rest) configCtrl(w http.ResponseWriter, r *http.Request) {
EditDuration: int(s.DataService.EditDuration.Seconds()),
MaxCommentSize: s.DataService.MaxCommentSize,
Admins: s.Authenticator.Admins,
AdminEmail: s.Authenticator.AdminEmail,
LowScore: s.ScoreThresholds.Low,
CriticalScore: s.ScoreThresholds.Critical,
ReadOnlyAge: s.ReadOnlyAge,
+1
View File
@@ -381,6 +381,7 @@ func TestRest_Config(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 300., j["edit_duration"])
assert.EqualValues(t, []interface{}([]interface{}{"a1", "a2"}), j["admins"])
assert.Equal(t, "admin@remark-42.com", j["admin_email"])
assert.Equal(t, 4000., j["max_comment_size"])
assert.Equal(t, -5., j["low_score"])
assert.Equal(t, -10., j["critical_score"])
+1
View File
@@ -58,6 +58,7 @@ func prep(t *testing.T) (srv *Rest, ts *httptest.Server) {
DevPasswd: "password",
Providers: nil,
Admins: []string{"a1", "a2"},
AdminEmail: "admin@remark-42.com",
JWTService: auth.NewJWT("12345", false, time.Minute),
},
Exporter: &migrator.Remark{DataStore: &dataStore},
+1
View File
@@ -16,6 +16,7 @@ type Authenticator struct {
JWTService *JWT
Providers []Provider
Admins []string
AdminEmail string
DevPasswd string
}