From a1f8ad7bd8740a5d02d51d573f5a3441c74bf2e4 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Mon, 30 Dec 2019 22:05:55 +0100 Subject: [PATCH] expose email_notifications flag on /config endpoint (#514) --- backend/app/cmd/server.go | 17 ++++++++-- backend/app/rest/api/rest.go | 63 +++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/backend/app/cmd/server.go b/backend/app/cmd/server.go index 3b3735e3..0091381f 100644 --- a/backend/app/cmd/server.go +++ b/backend/app/cmd/server.go @@ -328,10 +328,20 @@ func (s *ServerCommand) newServerApp() (*serverApp, error) { KeyStore: adminStore, } + var emailNotifications bool notifyService, err := s.makeNotify(dataService, authenticator) + + for _, t := range s.Notify.Type { + switch t { + case "email": + emailNotifications = true + } + } + if err != nil { log.Printf("[WARN] failed to make notify service, %s", err) notifyService = notify.NopService // disable notifier + emailNotifications = false // email notifications are not available in this case } imgProxy := &proxy.Image{Enabled: s.ImageProxy, RoutePath: "/api/v1/img", RemarkURL: s.RemarkURL} @@ -367,9 +377,10 @@ func (s *ServerCommand) newServerApp() (*serverApp, error) { Refresh: s.Stream.RefreshInterval, MaxActive: int32(s.Stream.MaxActive), }, - EmojiEnabled: s.EnableEmoji, - AnonVote: s.AnonymousVote && s.RestrictVoteIP, - SimpleView: s.SimpleView, + EmailNotifications: emailNotifications, + EmojiEnabled: s.EnableEmoji, + AnonVote: s.AnonymousVote && s.RestrictVoteIP, + SimpleView: s.SimpleView, } srv.ScoreThresholds.Low, srv.ScoreThresholds.Critical = s.LowScore, s.CriticalScore diff --git a/backend/app/rest/api/rest.go b/backend/app/rest/api/rest.go index 34f065dd..65eb353c 100644 --- a/backend/app/rest/api/rest.go +++ b/backend/app/rest/api/rest.go @@ -55,9 +55,10 @@ type Rest struct { Low int Critical int } - UpdateLimiter float64 - EmojiEnabled bool - SimpleView bool + UpdateLimiter float64 + EmailNotifications bool + EmojiEnabled bool + SimpleView bool SSLConfig SSLConfig httpsServer *http.Server @@ -398,34 +399,36 @@ func (s *Rest) configCtrl(w http.ResponseWriter, r *http.Request) { emails, _ := s.DataService.AdminStore.Email(siteID) cnf := struct { - Version string `json:"version"` - 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"` - AnonVote bool `json:"anon_vote"` - LowScore int `json:"low_score"` - CriticalScore int `json:"critical_score"` - PositiveScore bool `json:"positive_score"` - ReadOnlyAge int `json:"readonly_age"` - MaxImageSize int `json:"max_image_size"` - EmojiEnabled bool `json:"emoji_enabled"` - SimpleView bool `json:"simple_view"` + Version string `json:"version"` + 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"` + AnonVote bool `json:"anon_vote"` + LowScore int `json:"low_score"` + CriticalScore int `json:"critical_score"` + PositiveScore bool `json:"positive_score"` + ReadOnlyAge int `json:"readonly_age"` + MaxImageSize int `json:"max_image_size"` + EmailNotifications bool `json:"email_notifications"` + EmojiEnabled bool `json:"emoji_enabled"` + SimpleView bool `json:"simple_view"` }{ - Version: s.Version, - EditDuration: int(s.DataService.EditDuration.Seconds()), - MaxCommentSize: s.DataService.MaxCommentSize, - Admins: admins, - AdminEmail: emails, - LowScore: s.ScoreThresholds.Low, - CriticalScore: s.ScoreThresholds.Critical, - PositiveScore: s.DataService.PositiveScore, - ReadOnlyAge: s.ReadOnlyAge, - MaxImageSize: s.ImageService.Store.SizeLimit(), - EmojiEnabled: s.EmojiEnabled, - AnonVote: s.AnonVote, - SimpleView: s.SimpleView, + Version: s.Version, + EditDuration: int(s.DataService.EditDuration.Seconds()), + MaxCommentSize: s.DataService.MaxCommentSize, + Admins: admins, + AdminEmail: emails, + LowScore: s.ScoreThresholds.Low, + CriticalScore: s.ScoreThresholds.Critical, + PositiveScore: s.DataService.PositiveScore, + ReadOnlyAge: s.ReadOnlyAge, + MaxImageSize: s.ImageService.Store.SizeLimit(), + EmailNotifications: s.EmailNotifications, + EmojiEnabled: s.EmojiEnabled, + AnonVote: s.AnonVote, + SimpleView: s.SimpleView, } cnf.Auth = []string{}