Skip to content

Commit

Permalink
feat: global kill switch for sharedataovermail
Browse files Browse the repository at this point in the history
  • Loading branch information
puni9869 committed Nov 10, 2024
1 parent f7e390a commit be5ad74
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
11 changes: 6 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ type Mailer struct {

// ConfigProvider ie converted value in go types
type ConfigProvider struct {
EnableSSL bool `json:"enableSSL"`
Database map[string]DatabaseObj `json:"database"`
AppConfig AppConfig `json:"appConfig"`
Authentication Authentication `json:"authentication"`
Mailer Mailer `json:"mailer"`
EnableSSL bool `json:"enableSSL"`
ShareDataOverMail bool `json:"shareDataOverMail"`
Database map[string]DatabaseObj `json:"database"`
AppConfig AppConfig `json:"appConfig"`
Authentication Authentication `json:"authentication"`
Mailer Mailer `json:"mailer"`
}

var C ConfigProvider
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestConfigProviderStruct(t *testing.T) {
Authentication: Authentication{},
Mailer: Mailer{},
}
want := "config.ConfigProvider{EnableSSL:false, Database:map[string]config.DatabaseObj(nil), AppConfig:config.AppConfig{Debug:false, SecretKey:\"\", DefaultPort:\"\", CustomPort:\"\", UseCDN:false, Hostname:\"\"}, Authentication:config.Authentication{EnableLogin:false, EnableRegistration:false, EnableForgotPassword:false}, Mailer:config.Mailer{SmtpHost:\"\", SmtpPort:0, EmailId:\"\", BccEmailId:\"\", Username:\"\", Password:\"\"}}"
want := "config.ConfigProvider{EnableSSL:false, ShareDataOverMail:false, Database:map[string]config.DatabaseObj(nil), AppConfig:config.AppConfig{Debug:false, SecretKey:\"\", DefaultPort:\"\", CustomPort:\"\", UseCDN:false, Hostname:\"\"}, Authentication:config.Authentication{EnableLogin:false, EnableRegistration:false, EnableForgotPassword:false}, Mailer:config.Mailer{SmtpHost:\"\", SmtpPort:0, EmailId:\"\", BccEmailId:\"\", Username:\"\", Password:\"\"}}"
got := fmt.Sprintf("%#v", c)
if strings.Compare(want, got) != 0 {
t.Errorf("GetString() = %s, want %s", got, want)
Expand Down
6 changes: 5 additions & 1 deletion server/setting/setting.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package setting

import (
"fmt"
"github.com/puni9869/pinmyblogs/models"
"github.com/puni9869/pinmyblogs/pkg/config"
"github.com/puni9869/pinmyblogs/pkg/database"
"github.com/puni9869/pinmyblogs/pkg/logger"
"net/http"
Expand Down Expand Up @@ -31,7 +33,9 @@ func Setting(c *gin.Context) {
} else {
tmplCtx["DisplayName"] = user.DisplayName
}

}
if !config.C.ShareDataOverMail {
tmplCtx["ShareDataOverMail"] = fmt.Sprintf("%t", config.C.ShareDataOverMail)
}
c.HTML(http.StatusOK, "setting.tmpl", tmplCtx)
}
Expand Down
2 changes: 1 addition & 1 deletion templates/setting/container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<p><span class="ml-1 text-indigo-400 cursor-pointer hover:underline hover:underline-offset-4 select-none">Download .json</span></p>
<p><span class="ml-1 text-indigo-400 cursor-pointer hover:underline hover:underline-offset-4 select-none">Download .html</span></p>
<br />
<p><span class="ml-1 text-indigo-400 cursor-pointer hover:underline hover:underline-offset-4 select-none">Send me my data over email</span></p>
<p><span class="ml-1 select-none {{if eq .ShareDataOverMail "true"}}text-indigo-400 hover:underline hover:underline-offset-4 cursor-pointer {{else}}text-gray-400 cursor-not-allowed{{end}}">Send me my data over email</span></p>
</div>
</div>
<div class="mb-6"></div>
Expand Down

0 comments on commit be5ad74

Please sign in to comment.