Skip to content

Commit 564222a

Browse files
authored
Merge branch 'main' into fix-13939-make-2fa-optional-inc-ldap
2 parents bbccfc7 + 358555f commit 564222a

Some content is hidden

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

51 files changed

+647
-723
lines changed

cmd/doctor.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ func runRecreateTable(ctx *cli.Context) error {
124124
}
125125

126126
func runDoctor(ctx *cli.Context) error {
127-
128127
// Silence the default loggers
129128
log.DelNamedLogger("console")
130129
log.DelNamedLogger(log.DEFAULT)

custom/conf/app.example.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,6 @@ PATH =
800800
;; Prefix archive files by placing them in a directory named after the repository
801801
;PREFIX_ARCHIVE_FILES = true
802802
;;
803-
;; Disable the creation of new mirrors. Pre-existing mirrors remain valid.
804-
;DISABLE_MIRRORS = false
805-
;;
806803
;; Disable migrating feature.
807804
;DISABLE_MIGRATIONS = false
808805
;;
@@ -1945,6 +1942,12 @@ PATH =
19451942
;[mirror]
19461943
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19471944
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1945+
;; Enables the mirror functionality. Set to **false** to disable all mirrors.
1946+
;ENABLED = true
1947+
;; Disable the creation of **new** pull mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
1948+
;DISABLE_NEW_PULL = false
1949+
;; Disable the creation of **new** push mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
1950+
;DISABLE_NEW_PUSH = false
19481951
;; Default interval as a duration between each check
19491952
;DEFAULT_INTERVAL = 8h
19501953
;; Min interval as a duration must be > 1m

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
7373
- `DISABLED_REPO_UNITS`: **_empty_**: Comma separated list of globally disabled repo units. Allowed values: \[repo.issues, repo.ext_issues, repo.pulls, repo.wiki, repo.ext_wiki, repo.projects\]
7474
- `DEFAULT_REPO_UNITS`: **repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects**: Comma separated list of default repo units. Allowed values: \[repo.code, repo.releases, repo.issues, repo.pulls, repo.wiki, repo.projects\]. Note: Code and Releases can currently not be deactivated. If you specify default repo units you should still list them for future compatibility. External wiki and issue tracker can't be enabled by default as it requires additional settings. Disabled repo units will not be added to new repositories regardless if it is in the default list.
7575
- `PREFIX_ARCHIVE_FILES`: **true**: Prefix archive files by placing them in a directory named after the repository.
76-
- `DISABLE_MIRRORS`: **false**: Disable the creation of **new** mirrors. Pre-existing mirrors remain valid.
7776
- `DISABLE_MIGRATIONS`: **false**: Disable migrating feature.
7877
- `DISABLE_STARS`: **false**: Disable stars feature.
7978
- `DEFAULT_BRANCH`: **master**: Default branch name of all repositories.
@@ -955,6 +954,9 @@ Task queue configuration has been moved to `queue.task`. However, the below conf
955954

956955
## Mirror (`mirror`)
957956

957+
- `ENABLED`: **true**: Enables the mirror functionality. Set to **false** to disable all mirrors.
958+
- `DISABLE_NEW_PULL`: **false**: Disable the creation of **new** pull mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
959+
- `DISABLE_NEW_PUSH`: **false**: Disable the creation of **new** push mirrors. Pre-existing mirrors remain valid. Will be ignored if `mirror.ENABLED` is `false`.
958960
- `DEFAULT_INTERVAL`: **8h**: Default interval between each check
959961
- `MIN_INTERVAL`: **10m**: Minimum interval for checking. (Must be >1m).
960962

docs/content/page/index.de-de.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ Gitea ist ein [Gogs](http://gogs.io)-Fork.
2222

2323
## System Voraussetzungen
2424

25-
- A Raspberry Pi 3 is powerful enough to run Gitea for small workloads.
26-
- 2 CPU cores and 1GB RAM is typically sufficient for small teams/projects.
27-
- Gitea should be run with a dedicated non-root system account on UNIX-type systems.
28-
- Note: Gitea manages the `~/.ssh/authorized_keys` file. Running Gitea as a regular user could break that user's ability to log in.
29-
- [Git](https://git-scm.com/) version 1.7.2 or later is required. Version 1.9.0 or later is recommended. Also please note:
30-
- Git [large file storage](https://git-lfs.github.com/) will be available if enabled when git >= 2.1.2.
31-
- Git commit-graph rendering will be enabled automatically when git >= 2.18.
25+
- Ein Raspberry Pi 3 ist leistungsstark genug, um Gitea für kleine Belastungen laufen zu lassen.
26+
- 2 CPU Kerne und 1GB RAM sind für kleine Teams/Projekte ausreichend.
27+
- Gitea sollte unter einem seperaten nicht-root Account auf UNIX-Systemen ausgeführt werden.
28+
- Achtung: Gitea verwaltet die `~/.ssh/authorized_keys` Datei. Gitea unter einem normalen Benutzer auszuführen könnte dazu führen, dass dieser sich nicht mehr anmelden kann.
29+
- [Git](https://git-scm.com/) Version 1.7.2 oder später wird benötigt. Version 1.9.0 oder später wird empfohlen. Außerdem zu beachten:
30+
- Wenn git >= 2.1.2. und [Git large file storage](https://git-lfs.github.com/) aktiviert ist, dann wird es auch in Gitea verwendbar sein.
31+
- Wenn git >= 2.18, dann wird das Rendern von Commit-Graphen automatisch aktiviert.
3232

3333
## Browser Unterstützung
3434

integrations/api_settings_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestAPIExposedSettings(t *testing.T) {
4343

4444
DecodeJSON(t, resp, &repo)
4545
assert.EqualValues(t, &api.GeneralRepoSettings{
46-
MirrorsDisabled: setting.Repository.DisableMirrors,
46+
MirrorsDisabled: !setting.Mirror.Enabled,
4747
HTTPGitDisabled: setting.Repository.DisableHTTPGit,
4848
MigrationsDisabled: setting.Repository.DisableMigrations,
4949
TimeTrackingDisabled: false,

models/attachment.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55
package models
66

77
import (
8-
"bytes"
98
"fmt"
10-
"io"
119
"path"
1210

1311
"code.gitea.io/gitea/modules/setting"
1412
"code.gitea.io/gitea/modules/storage"
1513
"code.gitea.io/gitea/modules/timeutil"
1614

17-
gouuid "github.com/google/uuid"
1815
"xorm.io/xorm"
1916
)
2017

2118
// Attachment represent a attachment of issue/comment/release.
2219
type Attachment struct {
2320
ID int64 `xorm:"pk autoincr"`
2421
UUID string `xorm:"uuid UNIQUE"`
25-
IssueID int64 `xorm:"INDEX"`
26-
ReleaseID int64 `xorm:"INDEX"`
22+
RepoID int64 `xorm:"INDEX"` // this should not be zero
23+
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
24+
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
2725
UploaderID int64 `xorm:"INDEX DEFAULT 0"` // Notice: will be zero before this column added
2826
CommentID int64
2927
Name string
@@ -81,23 +79,6 @@ func (a *Attachment) LinkedRepository() (*Repository, UnitType, error) {
8179
return nil, -1, nil
8280
}
8381

84-
// NewAttachment creates a new attachment object.
85-
func NewAttachment(attach *Attachment, buf []byte, file io.Reader) (_ *Attachment, err error) {
86-
attach.UUID = gouuid.New().String()
87-
88-
size, err := storage.Attachments.Save(attach.RelativePath(), io.MultiReader(bytes.NewReader(buf), file), -1)
89-
if err != nil {
90-
return nil, fmt.Errorf("Create: %v", err)
91-
}
92-
attach.Size = size
93-
94-
if _, err := x.Insert(attach); err != nil {
95-
return nil, err
96-
}
97-
98-
return attach, nil
99-
}
100-
10182
// GetAttachmentByID returns attachment by given id
10283
func GetAttachmentByID(id int64) (*Attachment, error) {
10384
return getAttachmentByID(x, id)
@@ -144,6 +125,11 @@ func GetAttachmentByUUID(uuid string) (*Attachment, error) {
144125
return getAttachmentByUUID(x, uuid)
145126
}
146127

128+
// ExistAttachmentsByUUID returns true if attachment is exist by given UUID
129+
func ExistAttachmentsByUUID(uuid string) (bool, error) {
130+
return x.Where("`uuid`=?", uuid).Exist(new(Attachment))
131+
}
132+
147133
// GetAttachmentByReleaseIDFileName returns attachment by given releaseId and fileName.
148134
func GetAttachmentByReleaseIDFileName(releaseID int64, fileName string) (*Attachment, error) {
149135
return getAttachmentByReleaseIDFileName(x, releaseID, fileName)

models/attachment_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,11 @@
55
package models
66

77
import (
8-
"os"
9-
"path/filepath"
108
"testing"
119

1210
"github.com/stretchr/testify/assert"
1311
)
1412

15-
func TestUploadAttachment(t *testing.T) {
16-
assert.NoError(t, PrepareTestDatabase())
17-
18-
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
19-
20-
fPath := "./attachment_test.go"
21-
f, err := os.Open(fPath)
22-
assert.NoError(t, err)
23-
defer f.Close()
24-
25-
buf := make([]byte, 1024)
26-
n, err := f.Read(buf)
27-
assert.NoError(t, err)
28-
buf = buf[:n]
29-
30-
attach, err := NewAttachment(&Attachment{
31-
UploaderID: user.ID,
32-
Name: filepath.Base(fPath),
33-
}, buf, f)
34-
assert.NoError(t, err)
35-
36-
attachment, err := GetAttachmentByUUID(attach.UUID)
37-
assert.NoError(t, err)
38-
assert.EqualValues(t, user.ID, attachment.UploaderID)
39-
assert.Equal(t, int64(0), attachment.DownloadCount)
40-
}
41-
4213
func TestIncreaseDownloadCount(t *testing.T) {
4314
assert.NoError(t, PrepareTestDatabase())
4415

models/context.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ func Iterate(ctx DBContext, tableBean interface{}, cond builder.Cond, fun func(i
6666
BufferSize(setting.Database.IterateBufferSize).
6767
Iterate(tableBean, fun)
6868
}
69+
70+
// Insert inserts records into database
71+
func Insert(ctx DBContext, beans ...interface{}) error {
72+
_, err := ctx.e.Insert(beans...)
73+
return err
74+
}

models/fixtures/attachment.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-
22
id: 1
33
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
4+
repo_id: 1
45
issue_id: 1
56
comment_id: 0
67
name: attach1
@@ -10,6 +11,7 @@
1011
-
1112
id: 2
1213
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12
14+
repo_id: 2
1315
issue_id: 4
1416
comment_id: 0
1517
name: attach2
@@ -19,6 +21,7 @@
1921
-
2022
id: 3
2123
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a13
24+
repo_id: 1
2225
issue_id: 2
2326
comment_id: 1
2427
name: attach1
@@ -28,6 +31,7 @@
2831
-
2932
id: 4
3033
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14
34+
repo_id: 1
3135
issue_id: 3
3236
comment_id: 1
3337
name: attach2
@@ -37,6 +41,7 @@
3741
-
3842
id: 5
3943
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a15
44+
repo_id: 2
4045
issue_id: 4
4146
comment_id: 0
4247
name: attach1
@@ -46,6 +51,7 @@
4651
-
4752
id: 6
4853
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a16
54+
repo_id: 1
4955
issue_id: 5
5056
comment_id: 2
5157
name: attach1
@@ -55,6 +61,7 @@
5561
-
5662
id: 7
5763
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17
64+
repo_id: 1
5865
issue_id: 5
5966
comment_id: 2
6067
name: attach1
@@ -64,6 +71,7 @@
6471
-
6572
id: 8
6673
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a18
74+
repo_id: 3
6775
issue_id: 6
6876
comment_id: 0
6977
name: attach1
@@ -73,6 +81,7 @@
7381
-
7482
id: 9
7583
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a19
84+
repo_id: 1
7685
release_id: 1
7786
name: attach1
7887
download_count: 0
@@ -81,6 +90,7 @@
8190
-
8291
id: 10
8392
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a20
93+
repo_id: 0 # TestGetAttachment/NotLinked
8494
uploader_id: 8
8595
name: attach1
8696
download_count: 0
@@ -89,6 +99,7 @@
8999
-
90100
id: 11
91101
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a21
102+
repo_id: 40
92103
release_id: 2
93104
name: attach1
94105
download_count: 0

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@ var migrations = []Migration{
338338
NewMigration("Alter issue/comment table TEXT fields to LONGTEXT", alterIssueAndCommentTextFieldsToLongText),
339339
// v192 -> v193
340340
NewMigration("RecreateIssueResourceIndexTable to have a primary key instead of an unique index", recreateIssueResourceIndexTable),
341+
// v193 -> v194
342+
NewMigration("Add repo id column for attachment table", addRepoIDForAttachment),
341343
}
342344

343345
// GetCurrentDBVersion returns the current db version

models/migrations/v193.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"xorm.io/xorm"
9+
)
10+
11+
func addRepoIDForAttachment(x *xorm.Engine) error {
12+
type Attachment struct {
13+
ID int64 `xorm:"pk autoincr"`
14+
UUID string `xorm:"uuid UNIQUE"`
15+
RepoID int64 `xorm:"INDEX"` // this should not be zero
16+
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
17+
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
18+
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
19+
}
20+
if err := x.Sync2(new(Attachment)); err != nil {
21+
return err
22+
}
23+
24+
if _, err := x.Exec("UPDATE `attachment` set repo_id = (SELECT repo_id FROM `issue` WHERE `issue`.id = `attachment`.issue_id) WHERE `attachment`.issue_id > 0"); err != nil {
25+
return err
26+
}
27+
28+
if _, err := x.Exec("UPDATE `attachment` set repo_id = (SELECT repo_id FROM `release` WHERE `release`.id = `attachment`.release_id) WHERE `attachment`.release_id > 0"); err != nil {
29+
return err
30+
}
31+
32+
return nil
33+
}

models/migrations/v193_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func Test_addRepoIDForAttachment(t *testing.T) {
14+
type Attachment struct {
15+
ID int64 `xorm:"pk autoincr"`
16+
UUID string `xorm:"uuid UNIQUE"`
17+
RepoID int64 `xorm:"INDEX"` // this should not be zero
18+
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
19+
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
20+
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
21+
}
22+
23+
type Issue struct {
24+
ID int64
25+
RepoID int64
26+
}
27+
28+
type Release struct {
29+
ID int64
30+
RepoID int64
31+
}
32+
33+
// Prepare and load the testing database
34+
x, deferrable := prepareTestEnv(t, 0, new(Attachment), new(Issue), new(Release))
35+
defer deferrable()
36+
if x == nil || t.Failed() {
37+
return
38+
}
39+
40+
// Run the migration
41+
if err := addRepoIDForAttachment(x); err != nil {
42+
assert.NoError(t, err)
43+
return
44+
}
45+
46+
var issueAttachments []*Attachment
47+
err := x.Where("issue_id > 0").Find(&issueAttachments)
48+
assert.NoError(t, err)
49+
for _, attach := range issueAttachments {
50+
assert.Greater(t, attach.RepoID, 0)
51+
assert.Greater(t, attach.IssueID, 0)
52+
var issue Issue
53+
has, err := x.ID(attach.IssueID).Get(&issue)
54+
assert.NoError(t, err)
55+
assert.True(t, has)
56+
assert.EqualValues(t, attach.RepoID, issue.RepoID)
57+
}
58+
59+
var releaseAttachments []*Attachment
60+
err = x.Where("release_id > 0").Find(&releaseAttachments)
61+
assert.NoError(t, err)
62+
for _, attach := range releaseAttachments {
63+
assert.Greater(t, attach.RepoID, 0)
64+
assert.Greater(t, attach.IssueID, 0)
65+
var release Release
66+
has, err := x.ID(attach.ReleaseID).Get(&release)
67+
assert.NoError(t, err)
68+
assert.True(t, has)
69+
assert.EqualValues(t, attach.RepoID, release.RepoID)
70+
}
71+
}

0 commit comments

Comments
 (0)