Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ability for User to Customize Email Notification Frequency #7813

Merged
merged 15 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/migrations/v93.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "github.com/go-xorm/xorm"
func addEmailNotificationEnabledToUser(x *xorm.Engine) error {
// Issue see models/user.go
gary-kim marked this conversation as resolved.
Show resolved Hide resolved
type User struct {
EmailNotificationsEnabled bool `xorm:"NOT NULL DEFAULT true"`
EmailNotificationsEnabled bool `xorm:"DEFAULT true"`
gary-kim marked this conversation as resolved.
Show resolved Hide resolved
}

return x.Sync2(new(User))
Expand Down
3 changes: 2 additions & 1 deletion models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type User struct {
// Email is the primary email address (to be used for communication)
Email string `xorm:"NOT NULL"`
KeepEmailPrivate bool
EmailNotificationsEnabled bool `xorm:"NOT NULL DEFAULT true"`
EmailNotificationsEnabled bool `xorm:"DEFAULT true"`
Passwd string `xorm:"NOT NULL"`
PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'pbkdf2'"`

Expand Down Expand Up @@ -730,6 +730,7 @@ func (u *User) EnabledEmailNotifications() bool {
// would like to receive notifications by email
func (u *User) SetEmailNotifications(set bool) {
u.EmailNotificationsEnabled = set
_ = UpdateUser(u)
}

func isUserExist(e Engine, uid int64, name string) (bool, error) {
Expand Down
5 changes: 5 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,9 @@ confirm_delete_account = Confirm Deletion
delete_account_title = Delete User Account
delete_account_desc = Are you sure you want to permanently delete this user account?

email_notifications.enable = Enable Email Notifications
email_notifications.disable = Disable Email Notifications

[repo]
owner = Owner
repo_name = Repository Name
Expand Down Expand Up @@ -1126,6 +1129,8 @@ settings.basic_settings = Basic Settings
settings.mirror_settings = Mirror Settings
settings.sync_mirror = Synchronize Now
settings.mirror_sync_in_progress = Mirror synchronization is in progress. Check back in a minute.
settings.email_notifications.enable = Enable Email Notifications
settings.email_notifications.disable = Disable Email Notifications
settings.site = Website
settings.update_settings = Update Settings
settings.advanced_settings = Advanced Settings
Expand Down
2 changes: 2 additions & 0 deletions routers/user/setting/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Account(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAccount"] = true
ctx.Data["Email"] = ctx.User.Email
ctx.Data["NotificationsEnabled"] = ctx.User.EnabledEmailNotifications()

loadAccountData(ctx)

Expand Down Expand Up @@ -84,6 +85,7 @@ func EmailPost(ctx *context.Context, form auth.AddEmailForm) {
// Set Email Notification Preference
if ctx.Query("_method") == "NOTIFICATION" {
ctx.User.SetEmailNotifications(ctx.QueryBool("enable"))
log.Trace("Email notifications enabled made %s: %s", ctx.QueryBool("enable"), ctx.User.Name)
ctx.Redirect(setting.AppSubURL + "/user/settings/account")
return
}
Expand Down
13 changes: 13 additions & 0 deletions templates/user/settings/account.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
<div class="ui email list">
<div class="item">
{{.i18n.Tr "settings.email_desc"}}
<div class="right floated content">
<form action="{{AppSubUrl}}/user/settings/account/email" method="post">
{{$.CsrfTokenHtml}}
<input name="_method" type="hidden" value="NOTIFICATION">
{{if .NotificationsEnabled}}
<input name="enable" type="hidden" value="false">
<button class="ui blue tiny button">{{$.i18n.Tr "settings.email_notifications.disable"}}</button>
{{else}}
<input name="enable" type="hidden" value="true">
<button class="ui blue tiny button">{{$.i18n.Tr "settings.email_notifications.enable"}}</button>
{{end}}
</form>
</div>
</div>
{{range .Emails}}
<div class="item">
Expand Down