-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Move UI configurations that do not require restarting gitea to take effect to the admin dashboard #33909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hiifong
wants to merge
10
commits into
go-gitea:main
Choose a base branch
from
hiifong:config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Move UI configurations that do not require restarting gitea to take effect to the admin dashboard #33909
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8756c20
Update
hiifong 2675f93
Merge branch 'main' into config
hiifong 1ad4719
Update
hiifong b630848
Update
hiifong 4413489
Update
hiifong b36a08e
Update
hiifong f648caf
Merge branch 'main' into config
hiifong 7924b5c
rename
hiifong 848a475
fix lint
hiifong d934c0f
Merge upstream/main into config
hiifong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
models/migrations/fixtures/Test_MigrateIniToDatabase/system_setting.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# type Setting struct { | ||
# ID int64 `xorm:"pk autoincr"` | ||
# SettingKey string `xorm:"varchar(255) unique"` // key should be lowercase | ||
# SettingValue string `xorm:"text"` | ||
# Version int `xorm:"version"` | ||
# Created timeutil.TimeStamp `xorm:"created"` | ||
# Updated timeutil.TimeStamp `xorm:"updated"` | ||
# } | ||
- | ||
id: 1 | ||
setting_key: revision | ||
version: 1 | ||
|
||
- | ||
id: 2 | ||
setting_key: picture.enable_federated_avatar | ||
setting_value: false | ||
version: 1 | ||
|
||
- | ||
id: 3 | ||
setting_key: picture.disable_gravatar | ||
setting_value: true | ||
version: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_24 //nolint | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/migrations/base" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
base.MainTest(m) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_24 //nolint | ||
|
||
import ( | ||
"math" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/timeutil" | ||
"code.gitea.io/gitea/modules/util" | ||
|
||
"xorm.io/xorm" | ||
) | ||
|
||
const keyRevision = "revision" | ||
|
||
type Setting struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
SettingKey string `xorm:"varchar(255) unique"` // key should be lowercase | ||
SettingValue string `xorm:"text"` | ||
Version int `xorm:"version"` | ||
Created timeutil.TimeStamp `xorm:"created"` | ||
Updated timeutil.TimeStamp `xorm:"updated"` | ||
} | ||
|
||
// TableName sets the table name for the settings struct | ||
func (s *Setting) TableName() string { | ||
return "system_setting" | ||
} | ||
|
||
func MigrateIniToDatabase(x *xorm.Engine) error { | ||
uiMap, err := util.ConfigSectionToMap( | ||
setting.UI, "ui", | ||
[]string{ | ||
"GraphMaxCommitNum", "ReactionMaxUserNum", "MaxDisplayFileSize", "DefaultShowFullName", "DefaultTheme", "Themes", | ||
"FileIconTheme", "Reactions", "CustomEmojis", "PreferredTimestampTense", "AmbiguousUnicodeDetection", | ||
}..., | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
sess := x.NewSession() | ||
defer sess.Close() | ||
|
||
if err = sess.Begin(); err != nil { | ||
return err | ||
} | ||
|
||
if err = sess.Sync(new(Setting)); err != nil { | ||
return err | ||
} | ||
|
||
_ = getRevision(sess) // prepare the "revision" key ahead | ||
|
||
_, err = sess.Exec("UPDATE system_setting SET version=version+1 WHERE setting_key=?", keyRevision) | ||
if err != nil { | ||
return err | ||
} | ||
for k, v := range uiMap { | ||
res, err := sess.Exec("UPDATE system_setting SET version=version+1, setting_value=? WHERE setting_key=?", v, k) | ||
if err != nil { | ||
return err | ||
} | ||
rows, _ := res.RowsAffected() | ||
if rows == 0 { // if no existing row, insert a new row | ||
if _, err = sess.Insert(&Setting{SettingKey: k, SettingValue: v}); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return sess.Commit() | ||
} | ||
|
||
func getRevision(sess *xorm.Session) int { | ||
revision := &Setting{} | ||
exist, err := sess.Where("setting_key = ?", keyRevision).Get(revision) | ||
if err != nil { | ||
return 0 | ||
} else if !exist { | ||
_, err = sess.Insert(&Setting{SettingKey: keyRevision, Version: 1}) | ||
if err != nil { | ||
return 0 | ||
} | ||
return 1 | ||
} | ||
|
||
if revision.Version <= 0 || revision.Version >= math.MaxInt-1 { | ||
_, err = sess.Exec("UPDATE system_setting SET version=1 WHERE setting_key=?", keyRevision) | ||
if err != nil { | ||
return 0 | ||
} | ||
return 1 | ||
} | ||
return revision.Version | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package v1_24 //nolint | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/migrations/base" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_MigrateIniToDatabase(t *testing.T) { | ||
// Prepare and load the testing database | ||
x, deferable := base.PrepareTestEnv(t, 0, new(Setting)) | ||
defer deferable() | ||
if x == nil || t.Failed() { | ||
return | ||
} | ||
|
||
assert.NoError(t, MigrateIniToDatabase(x)) | ||
|
||
cnt, err := x.Table("system_setting").Where("setting_key LIKE 'ui.%'").Count() | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, 13, cnt) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.