@@ -29,6 +29,13 @@ func Notifications(ctx *context.Context) {
2929 ctx .Data ["PageIsSettingsNotifications" ] = true
3030 ctx .Data ["EmailNotificationsPreference" ] = ctx .Doer .EmailNotificationsPreference
3131
32+ fineGrainedPreference , err := user_model .GetUserNotificationSettings (ctx , ctx .Doer .ID )
33+ if err != nil {
34+ ctx .ServerError ("GetUserNotificationSettings" , err )
35+ return
36+ }
37+ ctx .Data ["ActionsEmailNotificationsPreference" ] = fineGrainedPreference .Actions
38+
3239 ctx .HTML (http .StatusOK , tplSettingsNotifications )
3340}
3441
@@ -45,7 +52,7 @@ func NotificationsEmailPost(ctx *context.Context) {
4552 preference == user_model .EmailNotificationsDisabled ||
4653 preference == user_model .EmailNotificationsAndYourOwn ) {
4754 log .Error ("Email notifications preference change returned unrecognized option %s: %s" , preference , ctx .Doer .Name )
48- ctx .ServerError ("SetEmailPreference " , errors .New ("option unrecognized" ))
55+ ctx .ServerError ("NotificationsEmailPost " , errors .New ("option unrecognized" ))
4956 return
5057 }
5158 opts := & user.UpdateOptions {
@@ -60,3 +67,31 @@ func NotificationsEmailPost(ctx *context.Context) {
6067 ctx .Flash .Success (ctx .Tr ("settings.email_preference_set_success" ))
6168 ctx .Redirect (setting .AppSubURL + "/user/settings/notifications" )
6269}
70+
71+ // NotificationsActionsEmailPost set user's email notification preference on Gitea Actions
72+ func NotificationsActionsEmailPost (ctx * context.Context ) {
73+ if ! ctx .GetContextValue ("EnableActions" ).(bool ) {
74+ ctx .NotFound (nil )
75+ return
76+ }
77+
78+ preference := ctx .FormString ("preference" )
79+ if ! (preference == user_model .NotificationGiteaActionsAll ||
80+ preference == user_model .NotificationGiteaActionsDisabled ||
81+ preference == user_model .NotificationGiteaActionsFailureOnly ) {
82+ log .Error ("Actions Email notifications preference change returned unrecognized option %s: %s" , preference , ctx .Doer .Name )
83+ ctx .ServerError ("NotificationsActionsEmailPost" , errors .New ("option unrecognized" ))
84+ return
85+ }
86+ opts := & user.UpdateNotificationSettingsOptions {
87+ Actions : optional .Some (preference ),
88+ }
89+ if err := user .UpdateNotificationSettings (ctx , new (user_model.NotificationSettings ), opts ); err != nil {
90+ log .Error ("Cannot set actions email notifications preference: %v" , err )
91+ ctx .ServerError ("UpdateNotificationSettings" , err )
92+ return
93+ }
94+ log .Trace ("Actions email notifications preference made %s: %s" , preference , ctx .Doer .Name )
95+ ctx .Flash .Success (ctx .Tr ("settings.email_preference_set_success" ))
96+ ctx .Redirect (setting .AppSubURL + "/user/settings/notifications" )
97+ }
0 commit comments