summaryrefslogtreecommitdiffstats
path: root/modules/setting/ui.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-02-20 00:12:01 +0800
committerGitHub <noreply@github.com>2023-02-20 00:12:01 +0800
commitc53ad052d8bd040ecd269d9757ce9885396a04af (patch)
tree7142da12dc9511445c76d3bf5616f1c220441a84 /modules/setting/ui.go
parent2b02343e218755c36c6a45da8a53c06dfff843a1 (diff)
downloadgitea-c53ad052d8bd040ecd269d9757ce9885396a04af.tar.gz
gitea-c53ad052d8bd040ecd269d9757ce9885396a04af.zip
Refactor the setting to make unit test easier (#22405)
Some bugs caused by less unit tests in fundamental packages. This PR refactor `setting` package so that create a unit test will be easier than before. - All `LoadFromXXX` files has been splited as two functions, one is `InitProviderFromXXX` and `LoadCommonSettings`. The first functions will only include the code to create or new a ini file. The second function will load common settings. - It also renames all functions in setting from `newXXXService` to `loadXXXSetting` or `loadXXXFrom` to make the function name less confusing. - Move `XORMLog` to `SQLLog` because it's a better name for that. Maybe we should finally move these `loadXXXSetting` into the `XXXInit` function? Any idea? --------- Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'modules/setting/ui.go')
-rw-r--r--modules/setting/ui.go152
1 files changed, 152 insertions, 0 deletions
diff --git a/modules/setting/ui.go b/modules/setting/ui.go
new file mode 100644
index 0000000000..2df3c35c76
--- /dev/null
+++ b/modules/setting/ui.go
@@ -0,0 +1,152 @@
+// Copyright 2023 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package setting
+
+import (
+ "time"
+
+ "code.gitea.io/gitea/modules/container"
+)
+
+// UI settings
+var UI = struct {
+ ExplorePagingNum int
+ SitemapPagingNum int
+ IssuePagingNum int
+ RepoSearchPagingNum int
+ MembersPagingNum int
+ FeedMaxCommitNum int
+ FeedPagingNum int
+ PackagesPagingNum int
+ GraphMaxCommitNum int
+ CodeCommentLines int
+ ReactionMaxUserNum int
+ ThemeColorMetaTag string
+ MaxDisplayFileSize int64
+ ShowUserEmail bool
+ DefaultShowFullName bool
+ DefaultTheme string
+ Themes []string
+ Reactions []string
+ ReactionsLookup container.Set[string] `ini:"-"`
+ CustomEmojis []string
+ CustomEmojisMap map[string]string `ini:"-"`
+ SearchRepoDescription bool
+ UseServiceWorker bool
+ OnlyShowRelevantRepos bool
+
+ Notification struct {
+ MinTimeout time.Duration
+ TimeoutStep time.Duration
+ MaxTimeout time.Duration
+ EventSourceUpdateTime time.Duration
+ } `ini:"ui.notification"`
+
+ SVG struct {
+ Enabled bool `ini:"ENABLE_RENDER"`
+ } `ini:"ui.svg"`
+
+ CSV struct {
+ MaxFileSize int64
+ } `ini:"ui.csv"`
+
+ Admin struct {
+ UserPagingNum int
+ RepoPagingNum int
+ NoticePagingNum int
+ OrgPagingNum int
+ } `ini:"ui.admin"`
+ User struct {
+ RepoPagingNum int
+ } `ini:"ui.user"`
+ Meta struct {
+ Author string
+ Description string
+ Keywords string
+ } `ini:"ui.meta"`
+}{
+ ExplorePagingNum: 20,
+ SitemapPagingNum: 20,
+ IssuePagingNum: 20,
+ RepoSearchPagingNum: 20,
+ MembersPagingNum: 20,
+ FeedMaxCommitNum: 5,
+ FeedPagingNum: 20,
+ PackagesPagingNum: 20,
+ GraphMaxCommitNum: 100,
+ CodeCommentLines: 4,
+ ReactionMaxUserNum: 10,
+ ThemeColorMetaTag: `#6cc644`,
+ MaxDisplayFileSize: 8388608,
+ DefaultTheme: `auto`,
+ Themes: []string{`auto`, `gitea`, `arc-green`},
+ Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
+ CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
+ CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
+ Notification: struct {
+ MinTimeout time.Duration
+ TimeoutStep time.Duration
+ MaxTimeout time.Duration
+ EventSourceUpdateTime time.Duration
+ }{
+ MinTimeout: 10 * time.Second,
+ TimeoutStep: 10 * time.Second,
+ MaxTimeout: 60 * time.Second,
+ EventSourceUpdateTime: 10 * time.Second,
+ },
+ SVG: struct {
+ Enabled bool `ini:"ENABLE_RENDER"`
+ }{
+ Enabled: true,
+ },
+ CSV: struct {
+ MaxFileSize int64
+ }{
+ MaxFileSize: 524288,
+ },
+ Admin: struct {
+ UserPagingNum int
+ RepoPagingNum int
+ NoticePagingNum int
+ OrgPagingNum int
+ }{
+ UserPagingNum: 50,
+ RepoPagingNum: 50,
+ NoticePagingNum: 25,
+ OrgPagingNum: 50,
+ },
+ User: struct {
+ RepoPagingNum int
+ }{
+ RepoPagingNum: 15,
+ },
+ Meta: struct {
+ Author string
+ Description string
+ Keywords string
+ }{
+ Author: "Gitea - Git with a cup of tea",
+ Description: "Gitea (Git with a cup of tea) is a painless self-hosted Git service written in Go",
+ Keywords: "go,git,self-hosted,gitea",
+ },
+}
+
+func loadUIFrom(rootCfg ConfigProvider) {
+ mustMapSetting(rootCfg, "ui", &UI)
+ sec := rootCfg.Section("ui")
+ UI.ShowUserEmail = sec.Key("SHOW_USER_EMAIL").MustBool(true)
+ UI.DefaultShowFullName = sec.Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)
+ UI.SearchRepoDescription = sec.Key("SEARCH_REPO_DESCRIPTION").MustBool(true)
+ UI.UseServiceWorker = sec.Key("USE_SERVICE_WORKER").MustBool(false)
+ UI.OnlyShowRelevantRepos = sec.Key("ONLY_SHOW_RELEVANT_REPOS").MustBool(false)
+
+ UI.ReactionsLookup = make(container.Set[string])
+ for _, reaction := range UI.Reactions {
+ UI.ReactionsLookup.Add(reaction)
+ }
+ UI.CustomEmojisMap = make(map[string]string)
+ for _, emoji := range UI.CustomEmojis {
+ UI.CustomEmojisMap[emoji] = ":" + emoji + ":"
+ }
+}