mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
91 lines
3.1 KiB
Go
91 lines
3.1 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package setting
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/hanzoai/git/models/unit"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
"github.com/hanzoai/git/modules/optional"
|
|
"github.com/hanzoai/git/modules/setting"
|
|
"github.com/hanzoai/git/modules/templates"
|
|
"github.com/hanzoai/git/services/context"
|
|
"github.com/hanzoai/git/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(nil)
|
|
return
|
|
}
|
|
|
|
ctx.Data["Title"] = ctx.Tr("notifications")
|
|
ctx.Data["PageIsSettingsNotifications"] = true
|
|
ctx.Data["EmailNotificationsPreference"] = ctx.Doer.EmailNotificationsPreference
|
|
|
|
actionsEmailPref, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyEmailNotificationGiteaActions, user_model.SettingEmailNotificationGiteaActionsFailureOnly)
|
|
if err != nil {
|
|
ctx.ServerError("GetUserSetting", err)
|
|
return
|
|
}
|
|
ctx.Data["ActionsEmailNotificationsPreference"] = actionsEmailPref
|
|
|
|
ctx.HTML(http.StatusOK, tplSettingsNotifications)
|
|
}
|
|
|
|
// NotificationsEmailPost set user's email notification preference
|
|
func NotificationsEmailPost(ctx *context.Context) {
|
|
if !setting.Service.EnableNotifyMail {
|
|
ctx.NotFound(nil)
|
|
return
|
|
}
|
|
|
|
preference := ctx.FormString("preference")
|
|
if !(preference == user_model.EmailNotificationsEnabled ||
|
|
preference == user_model.EmailNotificationsOnMention ||
|
|
preference == user_model.EmailNotificationsDisabled ||
|
|
preference == user_model.EmailNotificationsAndYourOwn) {
|
|
ctx.Flash.Error(ctx.Tr("invalid_data", preference))
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/notifications")
|
|
return
|
|
}
|
|
opts := &user.UpdateOptions{
|
|
EmailNotificationsPreference: optional.Some(preference),
|
|
}
|
|
if err := user.UpdateUser(ctx, ctx.Doer, opts); err != nil {
|
|
ctx.ServerError("UpdateUser", err)
|
|
return
|
|
}
|
|
ctx.Flash.Success(ctx.Tr("settings.email_preference_set_success"))
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/notifications")
|
|
}
|
|
|
|
// NotificationsActionsEmailPost set user's email notification preference on Gitea Actions
|
|
func NotificationsActionsEmailPost(ctx *context.Context) {
|
|
if !setting.Actions.Enabled || unit.TypeActions.UnitGlobalDisabled() {
|
|
ctx.NotFound(nil)
|
|
return
|
|
}
|
|
|
|
preference := ctx.FormString("preference")
|
|
if !(preference == user_model.SettingEmailNotificationGiteaActionsAll ||
|
|
preference == user_model.SettingEmailNotificationGiteaActionsDisabled ||
|
|
preference == user_model.SettingEmailNotificationGiteaActionsFailureOnly) {
|
|
ctx.Flash.Error(ctx.Tr("invalid_data", preference))
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/notifications")
|
|
return
|
|
}
|
|
if err := user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyEmailNotificationGiteaActions, preference); err != nil {
|
|
ctx.ServerError("SetUserSetting", err)
|
|
return
|
|
}
|
|
ctx.Flash.Success(ctx.Tr("settings.email_preference_set_success"))
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/notifications")
|
|
}
|