summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorGergely Nagy <forgejo@gergo.csillger.hu>2024-03-01 13:22:40 +0100
committerGergely Nagy <forgejo@gergo.csillger.hu>2024-03-21 08:15:51 +0100
commit36147f580cbbd0db56226726366aebdcbf0af08c (patch)
treed8441b4bdc8bf139797e316f24d6c3054c83dfe2 /routers
parentMerge pull request 'Fix repo badges when the label or text contains dashes' (... (diff)
downloadforgejo-36147f580cbbd0db56226726366aebdcbf0af08c.tar.xz
forgejo-36147f580cbbd0db56226726366aebdcbf0af08c.zip
Allow users to hide all "Add more units..." hints
Repositories displaying an "Add more..." tab on the header is a neat way to let people discover they can enable more units. However, displaying it all the time for repository owners, even when they deliberately do not want to enable more units gets noisy very fast. As such, this patch introduces a new setting which lets people disable this hint under the appearance settings. Fixes #2378. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/user/settings.go1
-rw-r--r--routers/web/user/setting/profile.go19
-rw-r--r--routers/web/web.go1
3 files changed, 21 insertions, 0 deletions
diff --git a/routers/api/v1/user/settings.go b/routers/api/v1/user/settings.go
index d0a8daaa85..f594eb211c 100644
--- a/routers/api/v1/user/settings.go
+++ b/routers/api/v1/user/settings.go
@@ -55,6 +55,7 @@ func UpdateUserSettings(ctx *context.APIContext) {
DiffViewStyle: optional.FromPtr(form.DiffViewStyle),
KeepEmailPrivate: optional.FromPtr(form.HideEmail),
KeepActivityPrivate: optional.FromPtr(form.HideActivity),
+ EnableRepoUnitHints: optional.FromPtr(form.EnableRepoUnitHints),
}
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {
ctx.InternalServerError(err)
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go
index 49eb050dcb..4e5c380ed9 100644
--- a/routers/web/user/setting/profile.go
+++ b/routers/web/user/setting/profile.go
@@ -393,6 +393,25 @@ func UpdateUserLang(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
}
+// UpdateUserHints updates a user's hints settings
+func UpdateUserHints(ctx *context.Context) {
+ form := web.GetForm(ctx).(*forms.UpdateHintsForm)
+ ctx.Data["Title"] = ctx.Tr("settings")
+ ctx.Data["PageIsSettingsAppearance"] = true
+
+ opts := &user_service.UpdateOptions{
+ EnableRepoUnitHints: optional.Some(form.EnableRepoUnitHints),
+ }
+ if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {
+ ctx.ServerError("UpdateUser", err)
+ return
+ }
+
+ log.Trace("User settings updated: %s", ctx.Doer.Name)
+ ctx.Flash.Success(translation.NewLocale(ctx.Doer.Language).TrString("settings.update_hints_success"))
+ ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
+}
+
// UpdateUserHiddenComments update a user's shown comment types
func UpdateUserHiddenComments(ctx *context.Context) {
err := user_model.SetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyHiddenCommentTypes, forms.UserHiddenCommentTypesFromRequest(ctx).String())
diff --git a/routers/web/web.go b/routers/web/web.go
index 2e42d7d63b..9029a4a97f 100644
--- a/routers/web/web.go
+++ b/routers/web/web.go
@@ -568,6 +568,7 @@ func registerRoutes(m *web.Route) {
m.Group("/appearance", func() {
m.Get("", user_setting.Appearance)
m.Post("/language", web.Bind(forms.UpdateLanguageForm{}), user_setting.UpdateUserLang)
+ m.Post("/hints", web.Bind(forms.UpdateHintsForm{}), user_setting.UpdateUserHints)
m.Post("/hidden_comments", user_setting.UpdateUserHiddenComments)
m.Post("/theme", web.Bind(forms.UpdateThemeForm{}), user_setting.UpdateUIThemePost)
})