mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Storage buckets, indexer names, the bleve analyzer, the lock prefix, SSH host keys, the markdown front-matter key, the container data paths, the RPM repo id and the API security scheme all read as this product now, and app.example.ini matches the code again. The upstream maintainer list and the changelog generator config went with the release history they belonged to, and the citation comments state the fact rather than link the issue. Three inert rules turn out to have been inert because they named a module path this tree does not use: gci grouped no first-party imports under prefix(), and depguard let models/migrations import models and modules/structs. They now name github.com/hanzoai/git. The config example also documented .gitea/workflows while the code has read .hanzo/workflows for some time. The authorized_keys marker follows the delegate-hook precedent: the new name is written and the old one is still recognised, because a marker we do not know is copied through as a hand-added key and leaves a revoked key authorized. The stored user_setting key keeps its value; only a migration may change that. Co-authored-by: Hanzo Dev <[email protected]>
90 lines
3.1 KiB
Go
90 lines
3.1 KiB
Go
// Copyright 2026 Hanzo AI, Inc. 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.SettingsKeyEmailNotificationActions, user_model.SettingEmailNotificationActionsFailureOnly)
|
|
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 the forge's 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.SettingEmailNotificationActionsAll ||
|
|
preference == user_model.SettingEmailNotificationActionsDisabled ||
|
|
preference == user_model.SettingEmailNotificationActionsFailureOnly) {
|
|
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.SettingsKeyEmailNotificationActions, 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")
|
|
}
|