Skip to content

Commit b4ae0d0

Browse files
committed
Update
1 parent 6e9cca0 commit b4ae0d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+199
-164
lines changed

models/activities/action.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func (a *Action) ShortActUserName(ctx context.Context) string {
231231

232232
// GetActDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
233233
func (a *Action) GetActDisplayName(ctx context.Context) string {
234-
if setting.UI.DefaultShowFullName {
234+
if setting.Config().UI.DefaultShowFullName.Value(ctx) {
235235
trimmedFullName := strings.TrimSpace(a.GetActFullName(ctx))
236236
if len(trimmedFullName) > 0 {
237237
return trimmedFullName
@@ -242,7 +242,7 @@ func (a *Action) GetActDisplayName(ctx context.Context) string {
242242

243243
// GetActDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
244244
func (a *Action) GetActDisplayNameTitle(ctx context.Context) string {
245-
if setting.UI.DefaultShowFullName {
245+
if setting.Config().UI.DefaultShowFullName.Value(ctx) {
246246
return a.ShortActUserName(ctx)
247247
}
248248
return a.GetActFullName(ctx)

models/issues/milestone_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func TestGetMilestones(t *testing.T) {
9898
milestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
9999
ListOptions: db.ListOptions{
100100
Page: page,
101-
PageSize: setting.UI.IssuePagingNum,
101+
PageSize: setting.Config().UI.IssuePagingNum.Value(t.Context()),
102102
},
103103
RepoID: repo.ID,
104104
IsClosed: optional.Some(false),
@@ -115,7 +115,7 @@ func TestGetMilestones(t *testing.T) {
115115
milestones, err = db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
116116
ListOptions: db.ListOptions{
117117
Page: page,
118-
PageSize: setting.UI.IssuePagingNum,
118+
PageSize: setting.Config().UI.IssuePagingNum.Value(t.Context()),
119119
},
120120
RepoID: repo.ID,
121121
IsClosed: optional.Some(true),
@@ -231,7 +231,7 @@ func TestGetMilestonesByRepoIDs(t *testing.T) {
231231
openMilestones, err := db.Find[issues_model.Milestone](db.DefaultContext, issues_model.FindMilestoneOptions{
232232
ListOptions: db.ListOptions{
233233
Page: page,
234-
PageSize: setting.UI.IssuePagingNum,
234+
PageSize: setting.Config().UI.IssuePagingNum.Value(t.Context()),
235235
},
236236
RepoIDs: []int64{repo1.ID, repo2.ID},
237237
IsClosed: optional.Some(false),
@@ -249,7 +249,7 @@ func TestGetMilestonesByRepoIDs(t *testing.T) {
249249
issues_model.FindMilestoneOptions{
250250
ListOptions: db.ListOptions{
251251
Page: page,
252-
PageSize: setting.UI.IssuePagingNum,
252+
PageSize: setting.Config().UI.IssuePagingNum.Value(t.Context()),
253253
},
254254
RepoIDs: []int64{repo1.ID, repo2.ID},
255255
IsClosed: optional.Some(true),

models/issues/reaction.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func FindIssueReactions(ctx context.Context, issueID int64, listOptions db.ListO
162162
func FindReactions(ctx context.Context, opts FindReactionsOptions) (ReactionList, int64, error) {
163163
sess := db.GetEngine(ctx).
164164
Where(opts.toConds()).
165-
In("reaction.`type`", setting.UI.Reactions).
165+
In("reaction.`type`", setting.Config().UI.Reactions.Value(ctx)).
166166
Asc("reaction.issue_id", "reaction.comment_id", "reaction.created_unix", "reaction.id")
167167
if opts.Page > 0 {
168168
sess = db.SetSessionPagination(sess, &opts)
@@ -220,7 +220,7 @@ type ReactionOptions struct {
220220

221221
// CreateReaction creates reaction for issue or comment.
222222
func CreateReaction(ctx context.Context, opts *ReactionOptions) (*Reaction, error) {
223-
if !setting.UI.ReactionsLookup.Contains(opts.Type) {
223+
if !setting.Config().UI.ReactionsLookup.Contains(opts.Type) {
224224
return nil, ErrForbiddenIssueReaction{opts.Type}
225225
}
226226

@@ -357,7 +357,7 @@ func (list ReactionList) LoadUsers(ctx context.Context, repo *repo_model.Reposit
357357
// GetFirstUsers returns first reacted user display names separated by comma
358358
func (list ReactionList) GetFirstUsers() string {
359359
var buffer bytes.Buffer
360-
rem := setting.UI.ReactionMaxUserNum
360+
rem := setting.Config().UI.ReactionMaxUserNum.Value(context.Background())
361361
for _, reaction := range list {
362362
if buffer.Len() > 0 {
363363
buffer.WriteString(", ")
@@ -372,8 +372,9 @@ func (list ReactionList) GetFirstUsers() string {
372372

373373
// GetMoreUserCount returns count of not shown users in reaction tooltip
374374
func (list ReactionList) GetMoreUserCount() int {
375-
if len(list) <= setting.UI.ReactionMaxUserNum {
375+
ctx := context.Background()
376+
if len(list) <= setting.Config().UI.ReactionMaxUserNum.Value(ctx) {
376377
return 0
377378
}
378-
return len(list) - setting.UI.ReactionMaxUserNum
379+
return len(list) - setting.Config().UI.ReactionMaxUserNum.Value(ctx)
379380
}

models/user/user.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"context"
99
"encoding/hex"
1010
"fmt"
11+
_ "image/jpeg" // Needed for jpeg support
1112
"mime"
1213
"net/mail"
1314
"net/url"
@@ -18,8 +19,6 @@ import (
1819
"time"
1920
"unicode"
2021

21-
_ "image/jpeg" // Needed for jpeg support
22-
2322
"code.gitea.io/gitea/models/auth"
2423
"code.gitea.io/gitea/models/db"
2524
"code.gitea.io/gitea/modules/auth/openid"
@@ -200,7 +199,7 @@ func (u *User) BeforeUpdate() {
200199
// AfterLoad is invoked from XORM after filling all the fields of this object.
201200
func (u *User) AfterLoad() {
202201
if u.Theme == "" {
203-
u.Theme = setting.UI.DefaultTheme
202+
u.Theme = setting.Config().UI.DefaultTheme.Value(context.Background())
204203
}
205204
}
206205

@@ -441,7 +440,7 @@ func (u *User) EmailTo() string {
441440
// GetDisplayName returns full name if it's not empty and DEFAULT_SHOW_FULL_NAME is set,
442441
// returns username otherwise.
443442
func (u *User) GetDisplayName() string {
444-
if setting.UI.DefaultShowFullName {
443+
if setting.Config().UI.DefaultShowFullName.Value(context.Background()) {
445444
trimmed := strings.TrimSpace(u.FullName)
446445
if len(trimmed) > 0 {
447446
return trimmed
@@ -483,7 +482,7 @@ func (u *User) GitName() string {
483482

484483
// ShortName ellipses username to length
485484
func (u *User) ShortName(length int) string {
486-
if setting.UI.DefaultShowFullName && len(u.FullName) > 0 {
485+
if setting.Config().UI.DefaultShowFullName.Value(context.Background()) && len(u.FullName) > 0 {
487486
return util.EllipsisDisplayString(u.FullName, length)
488487
}
489488
return util.EllipsisDisplayString(u.Name, length)
@@ -662,7 +661,7 @@ func createUser(ctx context.Context, u *User, meta *Meta, createdByAdmin bool, o
662661
u.AllowCreateOrganization = setting.Service.DefaultAllowCreateOrganization && !setting.Admin.DisableRegularOrgCreation
663662
u.EmailNotificationsPreference = setting.Admin.DefaultEmailNotification
664663
u.MaxRepoCreation = -1
665-
u.Theme = setting.UI.DefaultTheme
664+
u.Theme = setting.Config().UI.DefaultTheme.Value(ctx)
666665
u.IsRestricted = setting.Service.DefaultUserIsRestricted
667666
u.IsActive = !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm)
668667

@@ -1394,7 +1393,7 @@ func FixWrongUserType(ctx context.Context) (int64, error) {
13941393
}
13951394

13961395
func GetOrderByName() string {
1397-
if setting.UI.DefaultShowFullName {
1396+
if setting.Config().UI.DefaultShowFullName.Value(context.Background()) {
13981397
return "full_name, name"
13991398
}
14001399
return "name"

models/user/user_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func TestCreateUserInvalidEmail(t *testing.T) {
240240
Email: "[email protected]\r\n",
241241
Passwd: ";p['////..-++']",
242242
IsAdmin: false,
243-
Theme: setting.UI.DefaultTheme,
243+
Theme: setting.Config().UI.DefaultTheme.Value(t.Context()),
244244
MustChangePassword: false,
245245
}
246246

modules/charset/escape.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package charset
99

1010
import (
11+
"context"
1112
"html/template"
1213
"io"
1314
"strings"
@@ -29,7 +30,7 @@ func EscapeControlHTML(html template.HTML, locale translation.Locale, allowed ..
2930

3031
// EscapeControlReader escapes the unicode control sequences in a provided reader of HTML content and writer in a locale and returns the findings as an EscapeStatus
3132
func EscapeControlReader(reader io.Reader, writer io.Writer, locale translation.Locale, allowed ...rune) (escaped *EscapeStatus, err error) {
32-
if !setting.UI.AmbiguousUnicodeDetection {
33+
if !setting.Config().UI.AmbiguousUnicodeDetection.Value(context.Background()) {
3334
_, err = io.Copy(writer, reader)
3435
return &EscapeStatus{}, err
3536
}

modules/charset/escape_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"testing"
1010

1111
"code.gitea.io/gitea/modules/setting"
12+
"code.gitea.io/gitea/modules/setting/config"
1213
"code.gitea.io/gitea/modules/test"
1314
"code.gitea.io/gitea/modules/translation"
1415

@@ -172,10 +173,12 @@ func TestEscapeControlReader(t *testing.T) {
172173
}
173174

174175
func TestSettingAmbiguousUnicodeDetection(t *testing.T) {
175-
defer test.MockVariableValue(&setting.UI.AmbiguousUnicodeDetection, true)()
176+
ambiguousUnicodeDetectionValue := setting.Config().UI.AmbiguousUnicodeDetection.Value(t.Context())
177+
defer test.MockVariableValue(&ambiguousUnicodeDetectionValue, true)()
176178
_, out := EscapeControlHTML("a test", &translation.MockLocale{})
177179
assert.EqualValues(t, `a<span class="escaped-code-point" data-escaped="[U+00A0]"><span class="char"> </span></span>test`, out)
178-
setting.UI.AmbiguousUnicodeDetection = false
180+
ambiguousUnicodeDetection := config.Value[bool]{}
181+
setting.Config().UI.AmbiguousUnicodeDetection = ambiguousUnicodeDetection.WithDefault(false)
179182
_, out = EscapeControlHTML("a test", &translation.MockLocale{})
180183
assert.EqualValues(t, `a test`, out)
181184
}

modules/indexer/code/gitgrep/gitgrep.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func PerformSearch(ctx context.Context, page int, repoID int64, gitRepo *git.Rep
4141
}
4242

4343
total = len(res)
44-
pageStart := min((page-1)*setting.UI.RepoSearchPagingNum, len(res))
45-
pageEnd := min(page*setting.UI.RepoSearchPagingNum, len(res))
44+
pageStart := min((page-1)*setting.Config().UI.RepoSearchPagingNum.Value(ctx), len(res))
45+
pageEnd := min(page*setting.Config().UI.RepoSearchPagingNum.Value(ctx), len(res))
4646
res = res[pageStart:pageEnd]
4747
for _, r := range res {
4848
searchResults = append(searchResults, &code_indexer.Result{

modules/issue/template/unmarshal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package template
55

66
import (
7+
"context"
78
"fmt"
89
"io"
910
"path"
@@ -66,7 +67,7 @@ func UnmarshalFromRepo(repo *git.Repository, branch, filename string) (*api.Issu
6667
}
6768

6869
func unmarshalFromEntry(entry *git.TreeEntry, filename string) (*api.IssueTemplate, error) {
69-
if size := entry.Blob().Size(); size > setting.UI.MaxDisplayFileSize {
70+
if size := entry.Blob().Size(); size > setting.Config().UI.MaxDisplayFileSize.Value(context.Background()) {
7071
return nil, fmt.Errorf("too large: %v > MaxDisplayFileSize", size)
7172
}
7273

modules/markup/html_emoji.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func emojiShortCodeProcessor(ctx *RenderContext, node *html.Node) {
7474
converted := emoji.FromAlias(alias)
7575
if converted == nil {
7676
// check if this is a custom reaction
77-
if _, exist := setting.UI.CustomEmojisMap[alias]; exist {
77+
if _, exist := setting.Config().UI.CustomEmojisMap[alias]; exist {
7878
replaceContent(node, m[0], m[1], createCustomEmoji(ctx, alias))
7979
node = node.NextSibling.NextSibling
8080
start = 0

0 commit comments

Comments
 (0)