-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Add Notifications section in User Settings #35008
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6d0d2f9
MOVE
NorthRealm 8e6ee8e
MOVE
NorthRealm e00af17
MOVE
NorthRealm 0dd3b4b
MOVE
NorthRealm 472124b
MOVE
NorthRealm ee20c9a
Merge remote-tracking branch 'upstream/main' into patch7
NorthRealm ede1b95
Merge branch 'main' into patch7
GiteaBot 5a7e9c1
UPDATE
NorthRealm 06b0575
UPDATE
NorthRealm 1878e4e
update
NorthRealm 9df2d9a
Merge branch 'main' into patch7
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package setting | ||
|
|
||
| import ( | ||
| "errors" | ||
| "net/http" | ||
|
|
||
| user_model "code.gitea.io/gitea/models/user" | ||
| "code.gitea.io/gitea/modules/log" | ||
| "code.gitea.io/gitea/modules/optional" | ||
| "code.gitea.io/gitea/modules/setting" | ||
| "code.gitea.io/gitea/modules/templates" | ||
| "code.gitea.io/gitea/services/context" | ||
| "code.gitea.io/gitea/services/user" | ||
| ) | ||
|
|
||
| const tplSettingsNotifications templates.TplName = "user/settings/notifications" | ||
|
|
||
| // Notifications render user's notifications settings | ||
| func Notifications(ctx *context.Context) { | ||
| if !setting.Service.EnableNotifyMail { | ||
| ctx.NotFound(errors.New("NotifyMail not enabled")) | ||
| return | ||
| } | ||
|
|
||
| ctx.Data["Title"] = ctx.Tr("notifications") | ||
| ctx.Data["PageIsSettingsNotifications"] = true | ||
| ctx.Data["EmailNotificationsPreference"] = ctx.Doer.EmailNotificationsPreference | ||
|
|
||
| ctx.HTML(http.StatusOK, tplSettingsNotifications) | ||
| } | ||
|
|
||
| // SetGlobalEmailNotificationPreference set user's email notification preference | ||
| func SetGlobalEmailNotificationPreference(ctx *context.Context) { | ||
| if !setting.Service.EnableNotifyMail { | ||
| ctx.NotFound(errors.New("NotifyMail not enabled")) | ||
NorthRealm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return | ||
| } | ||
|
|
||
| preference := ctx.FormString("preference") | ||
| if !(preference == user_model.EmailNotificationsEnabled || | ||
| preference == user_model.EmailNotificationsOnMention || | ||
| preference == user_model.EmailNotificationsDisabled || | ||
| preference == user_model.EmailNotificationsAndYourOwn) { | ||
| log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.Doer.Name) | ||
| ctx.ServerError("SetEmailPreference", errors.New("option unrecognized")) | ||
| return | ||
| } | ||
| opts := &user.UpdateOptions{ | ||
| EmailNotificationsPreference: optional.Some(preference), | ||
| } | ||
| if err := user.UpdateUser(ctx, ctx.Doer, opts); err != nil { | ||
| log.Error("Set Email Notifications failed: %v", err) | ||
| ctx.ServerError("UpdateUser", err) | ||
| return | ||
| } | ||
| log.Trace("Email notifications preference made %s: %s", preference, ctx.Doer.Name) | ||
| ctx.Flash.Success(ctx.Tr("settings.email_preference_set_success")) | ||
| ctx.Redirect(setting.AppSubURL + "/user/settings/notifications") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| {{template "user/settings/layout_head" (dict "ctxData" . "pageClass" "user settings")}} | ||
| <div class="user-setting-content"> | ||
| <h4 class="ui top attached header"> | ||
| {{ctx.Locale.Tr "notifications"}} | ||
| </h4> | ||
| <div class="ui attached segment"> | ||
| <div class="ui list flex-items-block"> | ||
| <div class="item"> | ||
| <form class="ui form tw-w-full" action="{{AppSubUrl}}/user/settings/notifications/email" method="post"> | ||
| {{$.CsrfTokenHtml}} | ||
| <div class="field"> | ||
| <label>{{ctx.Locale.Tr "settings.email_desc"}}</label> | ||
| <div class="ui selection dropdown"> | ||
| <input name="preference" type="hidden" value="{{.EmailNotificationsPreference}}"> | ||
| {{svg "octicon-triangle-down" 14 "dropdown icon"}} | ||
| <div class="text"></div> | ||
| <div class="menu"> | ||
| <div data-value="enabled" class="{{if eq .EmailNotificationsPreference "enabled"}}active selected {{end}}item">{{ctx.Locale.Tr "settings.email_notifications.enable"}}</div> | ||
| <div data-value="andyourown" class="{{if eq .EmailNotificationsPreference "andyourown"}}active selected {{end}}item">{{ctx.Locale.Tr "settings.email_notifications.andyourown"}}</div> | ||
| <div data-value="onmention" class="{{if eq .EmailNotificationsPreference "onmention"}}active selected {{end}}item">{{ctx.Locale.Tr "settings.email_notifications.onmention"}}</div> | ||
| <div data-value="disabled" class="{{if eq .EmailNotificationsPreference "disabled"}}active selected {{end}}item">{{ctx.Locale.Tr "settings.email_notifications.disable"}}</div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div class="field"> | ||
| <button class="ui primary button">{{ctx.Locale.Tr "settings.email_notifications.submit"}}</button> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {{template "user/settings/layout_footer" .}} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.