From 36147f580cbbd0db56226726366aebdcbf0af08c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 1 Mar 2024 13:22:40 +0100 Subject: [PATCH] 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 --- models/forgejo_migrations/migrate.go | 2 + models/forgejo_migrations/v1_22/v7.go | 17 ++++ models/user/user.go | 1 + modules/structs/user.go | 30 +++--- options/locale/locale_en-US.ini | 5 + routers/api/v1/user/settings.go | 1 + routers/web/user/setting/profile.go | 19 ++++ routers/web/web.go | 1 + services/convert/user.go | 19 ++-- services/forms/user_form.go | 5 + services/user/update.go | 6 ++ templates/repo/header.tmpl | 2 +- templates/swagger/v1_json.tmpl | 8 ++ templates/user/settings/appearance.tmpl | 19 ++++ tests/integration/user_test.go | 122 ++++++++++++++++++++++++ 15 files changed, 233 insertions(+), 24 deletions(-) create mode 100644 models/forgejo_migrations/v1_22/v7.go diff --git a/models/forgejo_migrations/migrate.go b/models/forgejo_migrations/migrate.go index da417cc08c..39c8c8a142 100644 --- a/models/forgejo_migrations/migrate.go +++ b/models/forgejo_migrations/migrate.go @@ -50,6 +50,8 @@ var migrations = []*Migration{ NewMigration("create the forgejo_repo_flag table", forgejo_v1_22.CreateRepoFlagTable), // v5 -> v6 NewMigration("Add wiki_branch to repository", forgejo_v1_22.AddWikiBranchToRepository), + // v6 -> v7 + NewMigration("Add enable_repo_unit_hints to the user table", forgejo_v1_22.AddUserRepoUnitHintsSetting), } // GetCurrentDBVersion returns the current Forgejo database version. diff --git a/models/forgejo_migrations/v1_22/v7.go b/models/forgejo_migrations/v1_22/v7.go new file mode 100644 index 0000000000..9e237d2c06 --- /dev/null +++ b/models/forgejo_migrations/v1_22/v7.go @@ -0,0 +1,17 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "xorm.io/xorm" +) + +func AddUserRepoUnitHintsSetting(x *xorm.Engine) error { + type User struct { + ID int64 + EnableRepoUnitHints bool `xorm:"NOT NULL DEFAULT true"` + } + + return x.Sync(&User{}) +} diff --git a/models/user/user.go b/models/user/user.go index d37463895d..4aef30ca56 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -146,6 +146,7 @@ type User struct { DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"` Theme string `xorm:"NOT NULL DEFAULT ''"` KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"` + EnableRepoUnitHints bool `xorm:"NOT NULL DEFAULT true"` } func init() { diff --git a/modules/structs/user.go b/modules/structs/user.go index 0df67894b0..4e13669ad2 100644 --- a/modules/structs/user.go +++ b/modules/structs/user.go @@ -67,13 +67,14 @@ func (u User) MarshalJSON() ([]byte, error) { // UserSettings represents user settings // swagger:model type UserSettings struct { - FullName string `json:"full_name"` - Website string `json:"website"` - Description string `json:"description"` - Location string `json:"location"` - Language string `json:"language"` - Theme string `json:"theme"` - DiffViewStyle string `json:"diff_view_style"` + FullName string `json:"full_name"` + Website string `json:"website"` + Description string `json:"description"` + Location string `json:"location"` + Language string `json:"language"` + Theme string `json:"theme"` + DiffViewStyle string `json:"diff_view_style"` + EnableRepoUnitHints bool `json:"enable_repo_unit_hints"` // Privacy HideEmail bool `json:"hide_email"` HideActivity bool `json:"hide_activity"` @@ -82,13 +83,14 @@ type UserSettings struct { // UserSettingsOptions represents options to change user settings // swagger:model type UserSettingsOptions struct { - FullName *string `json:"full_name" binding:"MaxSize(100)"` - Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"` - Description *string `json:"description" binding:"MaxSize(255)"` - Location *string `json:"location" binding:"MaxSize(50)"` - Language *string `json:"language"` - Theme *string `json:"theme"` - DiffViewStyle *string `json:"diff_view_style"` + FullName *string `json:"full_name" binding:"MaxSize(100)"` + Website *string `json:"website" binding:"OmitEmpty;ValidUrl;MaxSize(255)"` + Description *string `json:"description" binding:"MaxSize(255)"` + Location *string `json:"location" binding:"MaxSize(50)"` + Language *string `json:"language"` + Theme *string `json:"theme"` + DiffViewStyle *string `json:"diff_view_style"` + EnableRepoUnitHints *bool `json:"enable_repo_unit_hints"` // Privacy HideEmail *bool `json:"hide_email"` HideActivity *bool `json:"hide_activity"` diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 647c46b5a9..2944c3e78b 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -703,6 +703,11 @@ continue = Continue cancel = Cancel language = Language ui = Theme +hints = Hints +additional_repo_units_hint_description = Display an "Add more units..." button for repositories that do not have all available units enabled. +additional_repo_units_hint = Encourage enabling additional repository units +update_hints = Update hints +update_hints_success = Hints have been updated. hidden_comment_types = Hidden comment types hidden_comment_types_description = Comment types checked here will not be shown inside issue pages. Checking "Label" for example removes all " added/removed