Skip to content

Commit bc1f8d2

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Fix broken link in tests/e2e/README (go-gitea#24576) [skip ci] Updated licenses and gitignores Add goto issue id function (go-gitea#24479) Improve decryption failure message (go-gitea#24573) Simplify template helper functions (go-gitea#24570) Makefile: Use portable !, not GNUish -not, with find(1). (go-gitea#24565) Add org visibility label to non-organization's dashboard (go-gitea#24558) Sort users and orgs on explore by recency by default (go-gitea#24279) Change `add_on` translation to `added_on` and include placeholder for the date (go-gitea#24562) Change `valid_until` translation to `valid_until_date` and include placeholder for the date (go-gitea#24563) Fix docs failing the build on `main` (go-gitea#24561) Improve wiki user title test (go-gitea#24559) Fix incorrect user visibility (go-gitea#24557) Change `join_on` translation to `joined_on` and include placeholder for the date (go-gitea#24550) Require at least one unit to be enabled (go-gitea#24189) Fix broken `README` link (go-gitea#24546) Check latest version on CI (go-gitea#24556)
2 parents 1c9bfb1 + 80765aa commit bc1f8d2

Some content is hidden

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

48 files changed

+279
-149
lines changed

.github/workflows/pull-compliance.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
uses: actions/setup-go@v4
1717
with:
1818
go-version: '>=1.20'
19+
check-latest: true
1920
- name: deps-backend
2021
run: make deps-backend deps-tools
2122
- name: lint backend
@@ -33,6 +34,7 @@ jobs:
3334
uses: actions/setup-go@v4
3435
with:
3536
go-version: '>=1.20'
37+
check-latest: true
3638
- name: deps-backend
3739
run: make deps-backend deps-tools
3840
- name: lint-backend-windows
@@ -52,6 +54,7 @@ jobs:
5254
uses: actions/setup-go@v4
5355
with:
5456
go-version: '>=1.20'
57+
check-latest: true
5558
- name: deps-backend
5659
run: make deps-backend deps-tools
5760
- name: lint-backend-gogit
@@ -71,6 +74,7 @@ jobs:
7174
uses: actions/setup-go@v4
7275
with:
7376
go-version: '>=1.20'
77+
check-latest: true
7478
- name: deps-backend
7579
run: make deps-backend deps-tools
7680
- name: checks backend
@@ -101,6 +105,7 @@ jobs:
101105
uses: actions/setup-go@v4
102106
with:
103107
go-version: '>=1.20'
108+
check-latest: true
104109
- name: setup node
105110
uses: actions/setup-node@v3
106111
with:

.github/workflows/pull-e2e.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
uses: actions/setup-go@v4
1717
with:
1818
go-version: '>=1.20'
19+
check-latest: true
1920
- name: setup node
2021
uses: actions/setup-node@v3
2122
with:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ GO_DIRS := build cmd models modules routers services tests
139139
WEB_DIRS := web_src/js web_src/css
140140

141141
GO_SOURCES := $(wildcard *.go)
142-
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)
142+
GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" ! -path modules/options/bindata.go ! -path modules/public/bindata.go ! -path modules/templates/bindata.go)
143143
GO_SOURCES += $(GENERATED_GO_DEST)
144144
GO_SOURCES_NO_BINDATA := $(GO_SOURCES)
145145

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Translations are done through Crowdin. If you want to translate to a new languag
110110

111111
You can also just create an issue for adding a language or ask on discord on the #translation channel. If you need context or find some translation issues, you can leave a comment on the string or ask on Discord. For general translation questions there is a section in the docs. Currently a bit empty but we hope to fill it as questions pop up.
112112

113-
https://docs.gitea.io/en-us/translation-guidelines/
113+
https://docs.gitea.io/en-us/contributing/translation-guidelines/
114114

115115
[![Crowdin](https://badges.crowdin.net/gitea/localized.svg)](https://crowdin.com/project/gitea)
116116

docs/content/doc/usage/packages/rpm.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dnf config-manager --add-repo https://gitea.example.com/api/packages/{owner}/rpm
3838
| ----------- | ----------- |
3939
| `owner` | The owner of the package. |
4040

41-
If the registry is private, provide credentials in the url. You can use a password or a [personal access token]({{< relref "doc/developers/api-usage.en-us.md#authentication" >}}):
41+
If the registry is private, provide credentials in the url. You can use a password or a [personal access token]({{< relref "doc/development/api-usage.en-us.md#authentication" >}}):
4242

4343
```shell
4444
dnf config-manager --add-repo https://{username}:{your_password_or_token}@gitea.example.com/api/packages/{owner}/rpm.repo
@@ -66,7 +66,7 @@ curl --user your_username:your_password_or_token \
6666
https://gitea.example.com/api/packages/testuser/rpm/upload
6767
```
6868

69-
If you are using 2FA or OAuth use a [personal access token]({{< relref "doc/developers/api-usage.en-us.md#authentication" >}}) instead of the password.
69+
If you are using 2FA or OAuth use a [personal access token]({{< relref "doc/development/api-usage.en-us.md#authentication" >}}) instead of the password.
7070
You cannot publish a file with the same name twice to a package. You must delete the existing package version first.
7171

7272
The server reponds with the following HTTP Status codes.

models/repo.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ var ItemsPerPage = 40
4040

4141
// Init initialize model
4242
func Init(ctx context.Context) error {
43-
unit.LoadUnitConfig()
43+
if err := unit.LoadUnitConfig(); err != nil {
44+
return err
45+
}
4446
return system_model.Init(ctx)
4547
}
4648

models/unit/unit.go

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package unit
55

66
import (
7+
"errors"
78
"fmt"
89
"strings"
910

@@ -106,12 +107,6 @@ var (
106107
TypeExternalTracker,
107108
}
108109

109-
// MustRepoUnits contains the units could not be disabled currently
110-
MustRepoUnits = []Type{
111-
TypeCode,
112-
TypeReleases,
113-
}
114-
115110
// DisabledRepoUnits contains the units that have been globally disabled
116111
DisabledRepoUnits = []Type{}
117112
)
@@ -122,18 +117,13 @@ func validateDefaultRepoUnits(defaultUnits, settingDefaultUnits []Type) []Type {
122117

123118
// Use setting if not empty
124119
if len(settingDefaultUnits) > 0 {
125-
// MustRepoUnits required as default
126-
units = make([]Type, len(MustRepoUnits))
127-
copy(units, MustRepoUnits)
120+
units = make([]Type, 0, len(settingDefaultUnits))
128121
for _, settingUnit := range settingDefaultUnits {
129122
if !settingUnit.CanBeDefault() {
130123
log.Warn("Not allowed as default unit: %s", settingUnit.String())
131124
continue
132125
}
133-
// MustRepoUnits already added
134-
if settingUnit.CanDisable() {
135-
units = append(units, settingUnit)
136-
}
126+
units = append(units, settingUnit)
137127
}
138128
}
139129

@@ -150,30 +140,30 @@ func validateDefaultRepoUnits(defaultUnits, settingDefaultUnits []Type) []Type {
150140
}
151141

152142
// LoadUnitConfig load units from settings
153-
func LoadUnitConfig() {
143+
func LoadUnitConfig() error {
154144
var invalidKeys []string
155145
DisabledRepoUnits, invalidKeys = FindUnitTypes(setting.Repository.DisabledRepoUnits...)
156146
if len(invalidKeys) > 0 {
157147
log.Warn("Invalid keys in disabled repo units: %s", strings.Join(invalidKeys, ", "))
158148
}
159-
// Check that must units are not disabled
160-
for i, disabledU := range DisabledRepoUnits {
161-
if !disabledU.CanDisable() {
162-
log.Warn("Not allowed to global disable unit %s", disabledU.String())
163-
DisabledRepoUnits = append(DisabledRepoUnits[:i], DisabledRepoUnits[i+1:]...)
164-
}
165-
}
166149

167150
setDefaultRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultRepoUnits...)
168151
if len(invalidKeys) > 0 {
169152
log.Warn("Invalid keys in default repo units: %s", strings.Join(invalidKeys, ", "))
170153
}
171154
DefaultRepoUnits = validateDefaultRepoUnits(DefaultRepoUnits, setDefaultRepoUnits)
155+
if len(DefaultRepoUnits) == 0 {
156+
return errors.New("no default repository units found")
157+
}
172158
setDefaultForkRepoUnits, invalidKeys := FindUnitTypes(setting.Repository.DefaultForkRepoUnits...)
173159
if len(invalidKeys) > 0 {
174160
log.Warn("Invalid keys in default fork repo units: %s", strings.Join(invalidKeys, ", "))
175161
}
176162
DefaultForkRepoUnits = validateDefaultRepoUnits(DefaultForkRepoUnits, setDefaultForkRepoUnits)
163+
if len(DefaultForkRepoUnits) == 0 {
164+
return errors.New("no default fork repository units found")
165+
}
166+
return nil
177167
}
178168

179169
// UnitGlobalDisabled checks if unit type is global disabled
@@ -186,16 +176,6 @@ func (u Type) UnitGlobalDisabled() bool {
186176
return false
187177
}
188178

189-
// CanDisable checks if this unit type can be disabled.
190-
func (u *Type) CanDisable() bool {
191-
for _, mu := range MustRepoUnits {
192-
if *u == mu {
193-
return false
194-
}
195-
}
196-
return true
197-
}
198-
199179
// CanBeDefault checks if the unit type can be a default repo unit
200180
func (u *Type) CanBeDefault() bool {
201181
for _, nadU := range NotAllowedDefaultRepoUnits {
@@ -216,11 +196,6 @@ type Unit struct {
216196
MaxAccessMode perm.AccessMode // The max access mode of the unit. i.e. Read means this unit can only be read.
217197
}
218198

219-
// CanDisable returns if this unit could be disabled.
220-
func (u *Unit) CanDisable() bool {
221-
return u.Type.CanDisable()
222-
}
223-
224199
// IsLessThan compares order of two units
225200
func (u Unit) IsLessThan(unit Unit) bool {
226201
if (u.Type == TypeExternalTracker || u.Type == TypeExternalWiki) && unit.Type != TypeExternalTracker && unit.Type != TypeExternalWiki {

models/unit/unit_test.go

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,84 @@ import (
1212
)
1313

1414
func TestLoadUnitConfig(t *testing.T) {
15-
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []Type) {
16-
DisabledRepoUnits = disabledRepoUnits
17-
DefaultRepoUnits = defaultRepoUnits
18-
DefaultForkRepoUnits = defaultForkRepoUnits
19-
}(DisabledRepoUnits, DefaultRepoUnits, DefaultForkRepoUnits)
20-
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []string) {
21-
setting.Repository.DisabledRepoUnits = disabledRepoUnits
22-
setting.Repository.DefaultRepoUnits = defaultRepoUnits
23-
setting.Repository.DefaultForkRepoUnits = defaultForkRepoUnits
24-
}(setting.Repository.DisabledRepoUnits, setting.Repository.DefaultRepoUnits, setting.Repository.DefaultForkRepoUnits)
25-
2615
t.Run("regular", func(t *testing.T) {
16+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []Type) {
17+
DisabledRepoUnits = disabledRepoUnits
18+
DefaultRepoUnits = defaultRepoUnits
19+
DefaultForkRepoUnits = defaultForkRepoUnits
20+
}(DisabledRepoUnits, DefaultRepoUnits, DefaultForkRepoUnits)
21+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []string) {
22+
setting.Repository.DisabledRepoUnits = disabledRepoUnits
23+
setting.Repository.DefaultRepoUnits = defaultRepoUnits
24+
setting.Repository.DefaultForkRepoUnits = defaultForkRepoUnits
25+
}(setting.Repository.DisabledRepoUnits, setting.Repository.DefaultRepoUnits, setting.Repository.DefaultForkRepoUnits)
26+
2727
setting.Repository.DisabledRepoUnits = []string{"repo.issues"}
2828
setting.Repository.DefaultRepoUnits = []string{"repo.code", "repo.releases", "repo.issues", "repo.pulls"}
2929
setting.Repository.DefaultForkRepoUnits = []string{"repo.releases"}
30-
LoadUnitConfig()
30+
assert.NoError(t, LoadUnitConfig())
3131
assert.Equal(t, []Type{TypeIssues}, DisabledRepoUnits)
3232
assert.Equal(t, []Type{TypeCode, TypeReleases, TypePullRequests}, DefaultRepoUnits)
33-
assert.Equal(t, []Type{TypeCode, TypeReleases}, DefaultForkRepoUnits)
33+
assert.Equal(t, []Type{TypeReleases}, DefaultForkRepoUnits)
3434
})
3535
t.Run("invalid", func(t *testing.T) {
36+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []Type) {
37+
DisabledRepoUnits = disabledRepoUnits
38+
DefaultRepoUnits = defaultRepoUnits
39+
DefaultForkRepoUnits = defaultForkRepoUnits
40+
}(DisabledRepoUnits, DefaultRepoUnits, DefaultForkRepoUnits)
41+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []string) {
42+
setting.Repository.DisabledRepoUnits = disabledRepoUnits
43+
setting.Repository.DefaultRepoUnits = defaultRepoUnits
44+
setting.Repository.DefaultForkRepoUnits = defaultForkRepoUnits
45+
}(setting.Repository.DisabledRepoUnits, setting.Repository.DefaultRepoUnits, setting.Repository.DefaultForkRepoUnits)
46+
3647
setting.Repository.DisabledRepoUnits = []string{"repo.issues", "invalid.1"}
3748
setting.Repository.DefaultRepoUnits = []string{"repo.code", "invalid.2", "repo.releases", "repo.issues", "repo.pulls"}
3849
setting.Repository.DefaultForkRepoUnits = []string{"invalid.3", "repo.releases"}
39-
LoadUnitConfig()
50+
assert.NoError(t, LoadUnitConfig())
4051
assert.Equal(t, []Type{TypeIssues}, DisabledRepoUnits)
4152
assert.Equal(t, []Type{TypeCode, TypeReleases, TypePullRequests}, DefaultRepoUnits)
42-
assert.Equal(t, []Type{TypeCode, TypeReleases}, DefaultForkRepoUnits)
53+
assert.Equal(t, []Type{TypeReleases}, DefaultForkRepoUnits)
4354
})
4455
t.Run("duplicate", func(t *testing.T) {
56+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []Type) {
57+
DisabledRepoUnits = disabledRepoUnits
58+
DefaultRepoUnits = defaultRepoUnits
59+
DefaultForkRepoUnits = defaultForkRepoUnits
60+
}(DisabledRepoUnits, DefaultRepoUnits, DefaultForkRepoUnits)
61+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []string) {
62+
setting.Repository.DisabledRepoUnits = disabledRepoUnits
63+
setting.Repository.DefaultRepoUnits = defaultRepoUnits
64+
setting.Repository.DefaultForkRepoUnits = defaultForkRepoUnits
65+
}(setting.Repository.DisabledRepoUnits, setting.Repository.DefaultRepoUnits, setting.Repository.DefaultForkRepoUnits)
66+
4567
setting.Repository.DisabledRepoUnits = []string{"repo.issues", "repo.issues"}
4668
setting.Repository.DefaultRepoUnits = []string{"repo.code", "repo.releases", "repo.issues", "repo.pulls", "repo.code"}
4769
setting.Repository.DefaultForkRepoUnits = []string{"repo.releases", "repo.releases"}
48-
LoadUnitConfig()
70+
assert.NoError(t, LoadUnitConfig())
4971
assert.Equal(t, []Type{TypeIssues}, DisabledRepoUnits)
5072
assert.Equal(t, []Type{TypeCode, TypeReleases, TypePullRequests}, DefaultRepoUnits)
51-
assert.Equal(t, []Type{TypeCode, TypeReleases}, DefaultForkRepoUnits)
73+
assert.Equal(t, []Type{TypeReleases}, DefaultForkRepoUnits)
74+
})
75+
t.Run("empty_default", func(t *testing.T) {
76+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []Type) {
77+
DisabledRepoUnits = disabledRepoUnits
78+
DefaultRepoUnits = defaultRepoUnits
79+
DefaultForkRepoUnits = defaultForkRepoUnits
80+
}(DisabledRepoUnits, DefaultRepoUnits, DefaultForkRepoUnits)
81+
defer func(disabledRepoUnits, defaultRepoUnits, defaultForkRepoUnits []string) {
82+
setting.Repository.DisabledRepoUnits = disabledRepoUnits
83+
setting.Repository.DefaultRepoUnits = defaultRepoUnits
84+
setting.Repository.DefaultForkRepoUnits = defaultForkRepoUnits
85+
}(setting.Repository.DisabledRepoUnits, setting.Repository.DefaultRepoUnits, setting.Repository.DefaultForkRepoUnits)
86+
87+
setting.Repository.DisabledRepoUnits = []string{"repo.issues", "repo.issues"}
88+
setting.Repository.DefaultRepoUnits = []string{}
89+
setting.Repository.DefaultForkRepoUnits = []string{"repo.releases", "repo.releases"}
90+
assert.NoError(t, LoadUnitConfig())
91+
assert.Equal(t, []Type{TypeIssues}, DisabledRepoUnits)
92+
assert.ElementsMatch(t, []Type{TypeCode, TypePullRequests, TypeReleases, TypeWiki, TypePackages, TypeProjects}, DefaultRepoUnits)
93+
assert.Equal(t, []Type{TypeReleases}, DefaultForkRepoUnits)
5294
})
5395
}

modules/context/form.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,8 @@ func (ctx *Context) FormOptionalBool(key string) util.OptionalBool {
6565
v = v || strings.EqualFold(s, "on")
6666
return util.OptionalBoolOf(v)
6767
}
68+
69+
func (ctx *Context) SetFormString(key, value string) {
70+
_ = ctx.Req.FormValue(key) // force parse form
71+
ctx.Req.Form.Set(key, value)
72+
}

modules/secret/secret.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/base64"
1111
"encoding/hex"
1212
"errors"
13+
"fmt"
1314
"io"
1415

1516
"github.com/minio/sha256-simd"
@@ -19,13 +20,13 @@ import (
1920
func AesEncrypt(key, text []byte) ([]byte, error) {
2021
block, err := aes.NewCipher(key)
2122
if err != nil {
22-
return nil, err
23+
return nil, fmt.Errorf("AesEncrypt invalid key: %v", err)
2324
}
2425
b := base64.StdEncoding.EncodeToString(text)
2526
ciphertext := make([]byte, aes.BlockSize+len(b))
2627
iv := ciphertext[:aes.BlockSize]
27-
if _, err := io.ReadFull(rand.Reader, iv); err != nil {
28-
return nil, err
28+
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
29+
return nil, fmt.Errorf("AesEncrypt unable to read IV: %w", err)
2930
}
3031
cfb := cipher.NewCFBEncrypter(block, iv)
3132
cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
@@ -39,15 +40,15 @@ func AesDecrypt(key, text []byte) ([]byte, error) {
3940
return nil, err
4041
}
4142
if len(text) < aes.BlockSize {
42-
return nil, errors.New("ciphertext too short")
43+
return nil, errors.New("AesDecrypt ciphertext too short")
4344
}
4445
iv := text[:aes.BlockSize]
4546
text = text[aes.BlockSize:]
4647
cfb := cipher.NewCFBDecrypter(block, iv)
4748
cfb.XORKeyStream(text, text)
4849
data, err := base64.StdEncoding.DecodeString(string(text))
4950
if err != nil {
50-
return nil, err
51+
return nil, fmt.Errorf("AesDecrypt invalid decrypted base64 string: %w", err)
5152
}
5253
return data, nil
5354
}
@@ -58,21 +59,21 @@ func EncryptSecret(key, str string) (string, error) {
5859
plaintext := []byte(str)
5960
ciphertext, err := AesEncrypt(keyHash[:], plaintext)
6061
if err != nil {
61-
return "", err
62+
return "", fmt.Errorf("failed to encrypt by secret: %w", err)
6263
}
6364
return hex.EncodeToString(ciphertext), nil
6465
}
6566

6667
// DecryptSecret decrypts a previously encrypted hex string
67-
func DecryptSecret(key, cipherhex string) (string, error) {
68+
func DecryptSecret(key, cipherHex string) (string, error) {
6869
keyHash := sha256.Sum256([]byte(key))
69-
ciphertext, err := hex.DecodeString(cipherhex)
70+
ciphertext, err := hex.DecodeString(cipherHex)
7071
if err != nil {
71-
return "", err
72+
return "", fmt.Errorf("failed to decrypt by secret, invalid hex string: %w", err)
7273
}
7374
plaintext, err := AesDecrypt(keyHash[:], ciphertext)
7475
if err != nil {
75-
return "", err
76+
return "", fmt.Errorf("failed to decrypt by secret, the key (maybe SECRET_KEY?) might be incorrect: %w", err)
7677
}
7778
return string(plaintext), nil
7879
}

0 commit comments

Comments
 (0)