Skip to content

Commit b3c062e

Browse files
authored
Merge branch 'main' into deps-86
2 parents 2121b4d + 2483a93 commit b3c062e

File tree

105 files changed

+1272
-1070
lines changed

Some content is hidden

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

105 files changed

+1272
-1070
lines changed

models/fixtures/access.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,9 @@
171171
user_id: 40
172172
repo_id: 61
173173
mode: 4
174+
175+
-
176+
id: 30
177+
user_id: 40
178+
repo_id: 1
179+
mode: 2

models/perm/access/repo_permission.go

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,14 @@ func (p *Permission) LogString() string {
175175
return fmt.Sprintf(format, args...)
176176
}
177177

178-
func applyEveryoneRepoPermission(user *user_model.User, perm *Permission) {
178+
func finalProcessRepoUnitPermission(user *user_model.User, perm *Permission) {
179179
if user == nil || user.ID <= 0 {
180+
// for anonymous access, it could be:
181+
// AccessMode is None or Read, units has repo units, unitModes is nil
180182
return
181183
}
184+
185+
// apply everyone access permissions
182186
for _, u := range perm.units {
183187
if u.EveryoneAccessMode >= perm_model.AccessModeRead && u.EveryoneAccessMode > perm.everyoneAccessMode[u.Type] {
184188
if perm.everyoneAccessMode == nil {
@@ -187,17 +191,40 @@ func applyEveryoneRepoPermission(user *user_model.User, perm *Permission) {
187191
perm.everyoneAccessMode[u.Type] = u.EveryoneAccessMode
188192
}
189193
}
194+
195+
if perm.unitsMode == nil {
196+
// if unitsMode is not set, then it means that the default p.AccessMode applies to all units
197+
return
198+
}
199+
200+
// remove no permission units
201+
origPermUnits := perm.units
202+
perm.units = make([]*repo_model.RepoUnit, 0, len(perm.units))
203+
for _, u := range origPermUnits {
204+
shouldKeep := false
205+
for t := range perm.unitsMode {
206+
if shouldKeep = u.Type == t; shouldKeep {
207+
break
208+
}
209+
}
210+
for t := range perm.everyoneAccessMode {
211+
if shouldKeep = shouldKeep || u.Type == t; shouldKeep {
212+
break
213+
}
214+
}
215+
if shouldKeep {
216+
perm.units = append(perm.units, u)
217+
}
218+
}
190219
}
191220

192221
// GetUserRepoPermission returns the user permissions to the repository
193222
func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, user *user_model.User) (perm Permission, err error) {
194223
defer func() {
195224
if err == nil {
196-
applyEveryoneRepoPermission(user, &perm)
197-
}
198-
if log.IsTrace() {
199-
log.Trace("Permission Loaded for user %-v in repo %-v, permissions: %-+v", user, repo, perm)
225+
finalProcessRepoUnitPermission(user, &perm)
200226
}
227+
log.Trace("Permission Loaded for user %-v in repo %-v, permissions: %-+v", user, repo, perm)
201228
}()
202229

203230
if err = repo.LoadUnits(ctx); err != nil {
@@ -294,16 +321,6 @@ func GetUserRepoPermission(ctx context.Context, repo *repo_model.Repository, use
294321
}
295322
}
296323

297-
// remove no permission units
298-
perm.units = make([]*repo_model.RepoUnit, 0, len(repo.Units))
299-
for t := range perm.unitsMode {
300-
for _, u := range repo.Units {
301-
if u.Type == t {
302-
perm.units = append(perm.units, u)
303-
}
304-
}
305-
}
306-
307324
return perm, err
308325
}
309326

models/perm/access/repo_permission_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestApplyEveryoneRepoPermission(t *testing.T) {
5050
{Type: unit.TypeWiki, EveryoneAccessMode: perm_model.AccessModeRead},
5151
},
5252
}
53-
applyEveryoneRepoPermission(nil, &perm)
53+
finalProcessRepoUnitPermission(nil, &perm)
5454
assert.False(t, perm.CanRead(unit.TypeWiki))
5555

5656
perm = Permission{
@@ -59,7 +59,7 @@ func TestApplyEveryoneRepoPermission(t *testing.T) {
5959
{Type: unit.TypeWiki, EveryoneAccessMode: perm_model.AccessModeRead},
6060
},
6161
}
62-
applyEveryoneRepoPermission(&user_model.User{ID: 0}, &perm)
62+
finalProcessRepoUnitPermission(&user_model.User{ID: 0}, &perm)
6363
assert.False(t, perm.CanRead(unit.TypeWiki))
6464

6565
perm = Permission{
@@ -68,7 +68,7 @@ func TestApplyEveryoneRepoPermission(t *testing.T) {
6868
{Type: unit.TypeWiki, EveryoneAccessMode: perm_model.AccessModeRead},
6969
},
7070
}
71-
applyEveryoneRepoPermission(&user_model.User{ID: 1}, &perm)
71+
finalProcessRepoUnitPermission(&user_model.User{ID: 1}, &perm)
7272
assert.True(t, perm.CanRead(unit.TypeWiki))
7373

7474
perm = Permission{
@@ -77,20 +77,22 @@ func TestApplyEveryoneRepoPermission(t *testing.T) {
7777
{Type: unit.TypeWiki, EveryoneAccessMode: perm_model.AccessModeRead},
7878
},
7979
}
80-
applyEveryoneRepoPermission(&user_model.User{ID: 1}, &perm)
80+
finalProcessRepoUnitPermission(&user_model.User{ID: 1}, &perm)
8181
// it should work the same as "EveryoneAccessMode: none" because the default AccessMode should be applied to units
8282
assert.True(t, perm.CanWrite(unit.TypeWiki))
8383

8484
perm = Permission{
8585
units: []*repo_model.RepoUnit{
86+
{Type: unit.TypeCode}, // will be removed
8687
{Type: unit.TypeWiki, EveryoneAccessMode: perm_model.AccessModeRead},
8788
},
8889
unitsMode: map[unit.Type]perm_model.AccessMode{
8990
unit.TypeWiki: perm_model.AccessModeWrite,
9091
},
9192
}
92-
applyEveryoneRepoPermission(&user_model.User{ID: 1}, &perm)
93+
finalProcessRepoUnitPermission(&user_model.User{ID: 1}, &perm)
9394
assert.True(t, perm.CanWrite(unit.TypeWiki))
95+
assert.Len(t, perm.units, 1)
9496
}
9597

9698
func TestUnitAccessMode(t *testing.T) {

models/repo/license.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func UpdateRepoLicenses(ctx context.Context, repo *Repository, commitID string,
5454
for _, o := range oldLicenses {
5555
// Update already existing license
5656
if o.License == license {
57+
o.CommitID = commitID
5758
if _, err := db.GetEngine(ctx).ID(o.ID).Cols("`commit_id`").Update(o); err != nil {
5859
return err
5960
}

models/unittest/fscopy.go

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,13 @@ import (
1111
"code.gitea.io/gitea/modules/util"
1212
)
1313

14-
// Copy copies file from source to target path.
15-
func Copy(src, dest string) error {
16-
// Gather file information to set back later.
17-
si, err := os.Lstat(src)
18-
if err != nil {
19-
return err
20-
}
21-
22-
// Handle symbolic link.
23-
if si.Mode()&os.ModeSymlink != 0 {
24-
target, err := os.Readlink(src)
25-
if err != nil {
26-
return err
27-
}
28-
// NOTE: os.Chmod and os.Chtimes don't recognize symbolic link,
29-
// which will lead "no such file or directory" error.
30-
return os.Symlink(target, dest)
31-
}
32-
33-
return util.CopyFile(src, dest)
34-
}
35-
36-
// Sync synchronizes the two files. This is skipped if both files
14+
// SyncFile synchronizes the two files. This is skipped if both files
3715
// exist and the size, modtime, and mode match.
38-
func Sync(srcPath, destPath string) error {
16+
func SyncFile(srcPath, destPath string) error {
3917
dest, err := os.Stat(destPath)
4018
if err != nil {
4119
if os.IsNotExist(err) {
42-
return Copy(srcPath, destPath)
20+
return util.CopyFile(srcPath, destPath)
4321
}
4422
return err
4523
}
@@ -55,7 +33,7 @@ func Sync(srcPath, destPath string) error {
5533
return nil
5634
}
5735

58-
return Copy(srcPath, destPath)
36+
return util.CopyFile(srcPath, destPath)
5937
}
6038

6139
// SyncDirs synchronizes files recursively from source to target directory.
@@ -66,23 +44,31 @@ func SyncDirs(srcPath, destPath string) error {
6644
return err
6745
}
6846

47+
// the keep file is used to keep the directory in a git repository, it doesn't need to be synced
48+
// and go-git doesn't work with the ".keep" file (it would report errors like "ref is empty")
49+
const keepFile = ".keep"
50+
6951
// find and delete all untracked files
7052
destFiles, err := util.ListDirRecursively(destPath, &util.ListDirOptions{IncludeDir: true})
7153
if err != nil {
7254
return err
7355
}
7456
for _, destFile := range destFiles {
7557
destFilePath := filepath.Join(destPath, destFile)
58+
shouldRemove := filepath.Base(destFilePath) == keepFile
7659
if _, err = os.Stat(filepath.Join(srcPath, destFile)); err != nil {
7760
if os.IsNotExist(err) {
78-
// if src file does not exist, remove dest file
79-
if err = os.RemoveAll(destFilePath); err != nil {
80-
return err
81-
}
61+
shouldRemove = true
8262
} else {
8363
return err
8464
}
8565
}
66+
// if src file does not exist, remove dest file
67+
if shouldRemove {
68+
if err = os.RemoveAll(destFilePath); err != nil {
69+
return err
70+
}
71+
}
8672
}
8773

8874
// sync src files to dest
@@ -95,8 +81,8 @@ func SyncDirs(srcPath, destPath string) error {
9581
// util.ListDirRecursively appends a slash to the directory name
9682
if strings.HasSuffix(srcFile, "/") {
9783
err = os.MkdirAll(destFilePath, os.ModePerm)
98-
} else {
99-
err = Sync(filepath.Join(srcPath, srcFile), destFilePath)
84+
} else if filepath.Base(destFilePath) != keepFile {
85+
err = SyncFile(filepath.Join(srcPath, srcFile), destFilePath)
10086
}
10187
if err != nil {
10288
return err

modules/web/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ func wrapHandlerProvider[T http.Handler](hp func(next http.Handler) T, funcInfo
121121
return func(next http.Handler) http.Handler {
122122
h := hp(next) // this handle could be dynamically generated, so we can't use it for debug info
123123
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
124-
routing.UpdateFuncInfo(req.Context(), funcInfo)
124+
defer routing.RecordFuncInfo(req.Context(), funcInfo)()
125125
h.ServeHTTP(resp, req)
126126
})
127127
}
@@ -157,7 +157,7 @@ func toHandlerProvider(handler any) func(next http.Handler) http.Handler {
157157
return // it's doing pre-check, just return
158158
}
159159

160-
routing.UpdateFuncInfo(req.Context(), funcInfo)
160+
defer routing.RecordFuncInfo(req.Context(), funcInfo)()
161161
ret := fn.Call(argsIn)
162162

163163
// handle the return value (no-op at the moment)

modules/web/routing/context.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ type contextKeyType struct{}
1212

1313
var contextKey contextKeyType
1414

15-
// UpdateFuncInfo updates a context's func info
16-
func UpdateFuncInfo(ctx context.Context, funcInfo *FuncInfo) {
17-
record, ok := ctx.Value(contextKey).(*requestRecord)
18-
if !ok {
19-
return
15+
// RecordFuncInfo records a func info into context
16+
func RecordFuncInfo(ctx context.Context, funcInfo *FuncInfo) (end func()) {
17+
// TODO: reqCtx := reqctx.FromContext(ctx), add trace support
18+
end = func() {}
19+
20+
// save the func info into the context record
21+
if record, ok := ctx.Value(contextKey).(*requestRecord); ok {
22+
record.lock.Lock()
23+
record.funcInfo = funcInfo
24+
record.lock.Unlock()
2025
}
21-
22-
record.lock.Lock()
23-
record.funcInfo = funcInfo
24-
record.lock.Unlock()
26+
return end
2527
}
2628

2729
// MarkLongPolling marks the request is a long-polling request, and the logger may output different message for it

options/locale/locale_cs-CZ.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,9 +1115,6 @@ blame.ignore_revs=Ignorování revizí v <a href="%s">.git-blame-ignorerevs</a>.
11151115
blame.ignore_revs.failed=Nepodařilo se ignorovat revize v <a href="%s">.git-blame-ignore-revs</a>.
11161116
user_search_tooltip=Zobrazí maximálně 30 uživatelů
11171117

1118-
tree_path_not_found_commit=Cesta %[1]s v commitu %[2]s neexistuje
1119-
tree_path_not_found_branch=Cesta %[1]s ve větvi %[2]s neexistuje
1120-
tree_path_not_found_tag=Cesta %[1]s ve značce %[2]s neexistuje
11211118

11221119
transfer.accept=Přijmout převod
11231120
transfer.accept_desc=Převést do „%s“
@@ -2158,7 +2155,6 @@ settings.advanced_settings=Pokročilá nastavení
21582155
settings.wiki_desc=Povolit Wiki repozitáře
21592156
settings.use_internal_wiki=Používat vestavěnou Wiki
21602157
settings.default_wiki_branch_name=Výchozí název větve Wiki
2161-
settings.default_wiki_everyone_access=Výchozí přístupová práva pro přihlášené uživatele:
21622158
settings.failed_to_change_default_wiki_branch=Změna výchozí větve wiki se nezdařila.
21632159
settings.use_external_wiki=Používat externí Wiki
21642160
settings.external_wiki_url=URL externí Wiki

options/locale/locale_de-DE.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,6 @@ blame.ignore_revs=Revisionen in <a href="%s">.git-blame-ignore-revs</a> werden i
11111111
blame.ignore_revs.failed=Fehler beim Ignorieren der Revisionen in <a href="%s">.git-blame-ignore-revs</a>.
11121112
user_search_tooltip=Zeigt maximal 30 Benutzer
11131113
1114-
tree_path_not_found_commit=Pfad %[1]s existiert nicht in Commit%[2]s
1115-
tree_path_not_found_branch=Pfad %[1]s existiert nicht in Branch %[2]s
1116-
tree_path_not_found_tag=Pfad %[1]s existiert nicht in Tag %[2]s
11171114
11181115
transfer.accept=Übertragung Akzeptieren
11191116
transfer.accept_desc=`Übertragung nach "%s"`
@@ -2154,7 +2151,6 @@ settings.advanced_settings=Erweiterte Einstellungen
21542151
settings.wiki_desc=Repository-Wiki aktivieren
21552152
settings.use_internal_wiki=Eingebautes Wiki verwenden
21562153
settings.default_wiki_branch_name=Standardbezeichnung für Wiki-Branch
2157-
settings.default_wiki_everyone_access=Standard-Zugriffsberechtigung für angemeldete Benutzer:
21582154
settings.failed_to_change_default_wiki_branch=Das Ändern des Standard-Wiki-Branches ist fehlgeschlagen.
21592155
settings.use_external_wiki=Externes Wiki verwenden
21602156
settings.external_wiki_url=Externe Wiki-URL

options/locale/locale_el-GR.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,9 +992,6 @@ blame_prior=Προβολή ευθύνης πριν από αυτή την αλλ
992992
blame.ignore_revs=Αγνόηση των αναθεωρήσεων στο <a href="%s">.git-blame-ignore-revs</a>. Πατήστε <a href="%s">εδώ</a> για να το παρακάμψετε και να δείτε την κανονική προβολή ευθυνών.
993993
blame.ignore_revs.failed=Αποτυχία αγνόησης των αναθεωρήσεων στο <a href="%s">.git-blame-ignore-revs</a>.
994994

995-
tree_path_not_found_commit=Η διαδρομή %[1]s δεν υπάρχει στην υποβολή %[2]s
996-
tree_path_not_found_branch=Η διαδρομή %[1]s δεν υπάρχει στον κλάδο %[2]s
997-
tree_path_not_found_tag=Η διαδρομή %[1]s δεν υπάρχει στην ετικέτα %[2]s
998995

999996
transfer.accept=Αποδοχή Μεταφοράς
1000997
transfer.reject=Απόρριψη Μεταφοράς

0 commit comments

Comments
 (0)