diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-12-07 15:27:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-07 15:27:36 +0800 |
commit | dd30d9d5c0f577cb6e084aae6de2752ad43474d8 (patch) | |
tree | 1e3799a672a23424484b849827ba39eae447856a /models/system/setting_test.go | |
parent | beb71f5ef6e8074dc744ac995c15f7b5947a3f2e (diff) | |
download | gitea-dd30d9d5c0f577cb6e084aae6de2752ad43474d8.tar.gz gitea-dd30d9d5c0f577cb6e084aae6de2752ad43474d8.zip |
Remove GetByBean method because sometimes it's danger when query condition parameter is zero and also introduce new generic methods (#28220)
The function `GetByBean` has an obvious defect that when the fields are
empty values, it will be ignored. Then users will get a wrong result
which is possibly used to make a security problem.
To avoid the possibility, this PR removed function `GetByBean` and all
references.
And some new generic functions have been introduced to be used.
The recommand usage like below.
```go
// if query an object according id
obj, err := db.GetByID[Object](ctx, id)
// query with other conditions
obj, err := db.Get[Object](ctx, builder.Eq{"a": a, "b":b})
```
Diffstat (limited to 'models/system/setting_test.go')
-rw-r--r-- | models/system/setting_test.go | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/models/system/setting_test.go b/models/system/setting_test.go index 0316ea144d..8f04412fb4 100644 --- a/models/system/setting_test.go +++ b/models/system/setting_test.go @@ -41,14 +41,11 @@ func TestSettings(t *testing.T) { assert.EqualValues(t, "false", settings[keyName]) // setting the same value should not trigger DuplicateKey error, and the "version" should be increased - setting := &system.Setting{SettingKey: keyName} - _, err = db.GetByBean(db.DefaultContext, setting) - assert.NoError(t, err) - assert.EqualValues(t, 2, setting.Version) err = system.SetSettings(db.DefaultContext, map[string]string{keyName: "false"}) assert.NoError(t, err) - setting = &system.Setting{SettingKey: keyName} - _, err = db.GetByBean(db.DefaultContext, setting) + + rev, settings, err = system.GetAllSettings(db.DefaultContext) assert.NoError(t, err) - assert.EqualValues(t, 3, setting.Version) + assert.Len(t, settings, 2) + assert.EqualValues(t, 4, rev) } |