mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-07-13 15:39:19 +02:00
Some checks failed
testing-integration / test-sqlite (push) Has been cancelled
testing / backend-checks (push) Has been cancelled
/ release (push) Has been cancelled
testing-integration / test-unit (push) Has been cancelled
testing / frontend-checks (push) Has been cancelled
testing / test-unit (push) Has been cancelled
testing / test-e2e (push) Has been cancelled
testing / test-remote-cacher (redis) (push) Has been cancelled
testing / test-remote-cacher (valkey) (push) Has been cancelled
testing / test-remote-cacher (garnet) (push) Has been cancelled
testing / test-remote-cacher (redict) (push) Has been cancelled
testing / test-mysql (push) Has been cancelled
testing / test-pgsql (push) Has been cancelled
testing / test-sqlite (push) Has been cancelled
testing / security-check (push) Has been cancelled
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/8258
Closes #8119, follow-up of #8234
#8234 "only" fixed the case when a new wiki setting was applied.
However it lacked 2 aspects:
- fixing the already corrupted unit permission in the database (required a migration)
- fixing the API route
Both aspects should now be covered.
Additionally, I commented out the unused `UnitAccessMode` and indicated that they are only used for the wiki-unit (hopefully saving some time to future code-readers).
### Testing
- go to a commit before #8234 (e.g. 285f66b782
)
- create 3 repositories
- save the wiki settings of the second, without any change
- set the wiki of the third to be globally writable
- verify the `default_permissions` column in the database, of the unit `5`: 0, 2, 3
- stop Forgejo, switch to this PR and start Forgejo
- verify that the logs writes `Migration[35]: Fix wiki unit default permission`
- verify the `default_permissions` column in the database, of the unit `5`: 0, 0, 3
Before:

After:

- [x] I did not document these changes and I do not expect someone else to do it.
- [x] I do not want this change to show in the release notes.
Co-authored-by: oliverpool <git@olivier.pfad.fr>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8439
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
88 lines
2.7 KiB
Go
88 lines
2.7 KiB
Go
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"forgejo.org/models/perm"
|
|
"forgejo.org/modules/setting"
|
|
"forgejo.org/modules/test"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestActionsConfig(t *testing.T) {
|
|
cfg := &ActionsConfig{}
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
|
|
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
|
|
|
|
cfg.EnableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{}, cfg.DisabledWorkflows)
|
|
|
|
cfg.EnableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{}, cfg.DisabledWorkflows)
|
|
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
cfg.DisableWorkflow("test2.yaml")
|
|
cfg.DisableWorkflow("test3.yaml")
|
|
assert.Equal(t, "test1.yaml,test2.yaml,test3.yaml", cfg.ToString())
|
|
}
|
|
|
|
func TestRepoUnitAccessMode(t *testing.T) {
|
|
// assert.Equal(t, perm.AccessModeNone, UnitAccessModeNone.ToAccessMode(perm.AccessModeAdmin))
|
|
// assert.Equal(t, perm.AccessModeRead, UnitAccessModeRead.ToAccessMode(perm.AccessModeAdmin))
|
|
assert.Equal(t, perm.AccessModeWrite, UnitAccessModeWrite.ToAccessMode(perm.AccessModeAdmin))
|
|
assert.Equal(t, perm.AccessModeRead, UnitAccessModeUnset.ToAccessMode(perm.AccessModeRead))
|
|
}
|
|
|
|
func TestRepoPRIsUpdateStyleAllowed(t *testing.T) {
|
|
var cfg PullRequestsConfig
|
|
cfg = PullRequestsConfig{
|
|
AllowRebaseUpdate: true,
|
|
}
|
|
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleMerge))
|
|
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleRebase))
|
|
|
|
cfg = PullRequestsConfig{
|
|
AllowRebaseUpdate: false,
|
|
}
|
|
assert.True(t, cfg.IsUpdateStyleAllowed(UpdateStyleMerge))
|
|
assert.False(t, cfg.IsUpdateStyleAllowed(UpdateStyleRebase))
|
|
}
|
|
|
|
func TestRepoPRGetDefaultUpdateStyle(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.Repository.PullRequest.DefaultUpdateStyle, "merge")()
|
|
|
|
var cfg PullRequestsConfig
|
|
cfg = PullRequestsConfig{
|
|
DefaultUpdateStyle: "",
|
|
}
|
|
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
|
cfg = PullRequestsConfig{
|
|
DefaultUpdateStyle: "rebase",
|
|
}
|
|
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
|
cfg = PullRequestsConfig{
|
|
DefaultUpdateStyle: "merge",
|
|
}
|
|
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
|
|
|
setting.Repository.PullRequest.DefaultUpdateStyle = "rebase"
|
|
cfg = PullRequestsConfig{
|
|
DefaultUpdateStyle: "",
|
|
}
|
|
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
|
cfg = PullRequestsConfig{
|
|
DefaultUpdateStyle: "rebase",
|
|
}
|
|
assert.Equal(t, UpdateStyleRebase, cfg.GetDefaultUpdateStyle())
|
|
cfg = PullRequestsConfig{
|
|
DefaultUpdateStyle: "merge",
|
|
}
|
|
assert.Equal(t, UpdateStyleMerge, cfg.GetDefaultUpdateStyle())
|
|
}
|