Skip to content

Commit 0f95747

Browse files
authored
Merge branch 'main' into bugfix/issue-31539
2 parents b02fffe + aebb741 commit 0f95747

Some content is hidden

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

73 files changed

+549
-316
lines changed

models/user/user.go

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -565,42 +565,43 @@ var (
565565
".",
566566
"..",
567567
".well-known",
568-
"admin",
569-
"api",
570-
"assets",
571-
"attachments",
572-
"avatar",
573-
"avatars",
568+
569+
"api", // gitea api
570+
"metrics", // prometheus metrics api
571+
"v2", // container registry api
572+
573+
"assets", // static asset files
574+
"attachments", // issue attachments
575+
576+
"avatar", // avatar by email hash
577+
"avatars", // user avatars by file name
578+
"repo-avatars",
579+
574580
"captcha",
575-
"commits",
576-
"debug",
577-
"error",
581+
"login", // oauth2 login
582+
"org", // org create/manage, or "/org/{org}", BUT if an org is named as "invite" then it goes wrong
583+
"repo", // repo create/migrate, etc
584+
"user", // user login/activate/settings, etc
585+
578586
"explore",
579-
"favicon.ico",
580-
"ghost",
581587
"issues",
582-
"login",
583-
"manifest.json",
584-
"metrics",
588+
"pulls",
585589
"milestones",
586-
"new",
587590
"notifications",
588-
"org",
589-
"pulls",
590-
"raw",
591-
"repo",
592-
"repo-avatars",
593-
"robots.txt",
594-
"search",
595-
"serviceworker.js",
596-
"ssh_info",
591+
592+
"favicon.ico",
593+
"manifest.json", // web app manifests
594+
"robots.txt", // search engine robots
595+
"sitemap.xml", // search engine sitemap
596+
"ssh_info", // agit info
597597
"swagger.v1.json",
598-
"user",
599-
"v2",
600-
"gitea-actions",
598+
599+
"ghost", // reserved name for deleted users (id: -1)
600+
"gitea-actions", // gitea builtin user (id: -2)
601601
}
602602

603-
// DON'T ADD ANY NEW STUFF, WE SOLVE THIS WITH `/user/{obj}` PATHS!
603+
// These names are reserved for user accounts: user's keys, user's rss feed, user's avatar, etc.
604+
// DO NOT add any new stuff! The paths with these names are processed by `/{username}` handler (UsernameSubRoute) manually.
604605
reservedUserPatterns = []string{"*.keys", "*.gpg", "*.rss", "*.atom", "*.png"}
605606
)
606607

options/locale/locale_ga-IE.ini

Lines changed: 293 additions & 5 deletions
Large diffs are not rendered by default.

routers/api/packages/container/blob.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,18 @@ import (
1010
"fmt"
1111
"os"
1212
"strings"
13-
"sync"
1413

1514
"code.gitea.io/gitea/models/db"
1615
packages_model "code.gitea.io/gitea/models/packages"
1716
container_model "code.gitea.io/gitea/models/packages/container"
17+
"code.gitea.io/gitea/modules/globallock"
1818
"code.gitea.io/gitea/modules/log"
1919
packages_module "code.gitea.io/gitea/modules/packages"
2020
container_module "code.gitea.io/gitea/modules/packages/container"
2121
"code.gitea.io/gitea/modules/util"
2222
packages_service "code.gitea.io/gitea/services/packages"
2323
)
2424

25-
var uploadVersionMutex sync.Mutex
26-
2725
// saveAsPackageBlob creates a package blob from an upload
2826
// The uploaded blob gets stored in a special upload version to link them to the package/image
2927
func saveAsPackageBlob(ctx context.Context, hsr packages_module.HashedSizeReader, pci *packages_service.PackageCreationInfo) (*packages_model.PackageBlob, error) { //nolint:unparam
@@ -90,13 +88,20 @@ func mountBlob(ctx context.Context, pi *packages_service.PackageInfo, pb *packag
9088
})
9189
}
9290

91+
func containerPkgName(piOwnerID int64, piName string) string {
92+
return fmt.Sprintf("pkg_%d_container_%s", piOwnerID, strings.ToLower(piName))
93+
}
94+
9395
func getOrCreateUploadVersion(ctx context.Context, pi *packages_service.PackageInfo) (*packages_model.PackageVersion, error) {
9496
var uploadVersion *packages_model.PackageVersion
9597

96-
// FIXME: Replace usage of mutex with database transaction
97-
// https://github.com/go-gitea/gitea/pull/21862
98-
uploadVersionMutex.Lock()
99-
err := db.WithTx(ctx, func(ctx context.Context) error {
98+
releaser, err := globallock.Lock(ctx, containerPkgName(pi.Owner.ID, pi.Name))
99+
if err != nil {
100+
return nil, err
101+
}
102+
defer releaser()
103+
104+
err = db.WithTx(ctx, func(ctx context.Context) error {
100105
created := true
101106
p := &packages_model.Package{
102107
OwnerID: pi.Owner.ID,
@@ -140,7 +145,6 @@ func getOrCreateUploadVersion(ctx context.Context, pi *packages_service.PackageI
140145

141146
return nil
142147
})
143-
uploadVersionMutex.Unlock()
144148

145149
return uploadVersion, err
146150
}
@@ -173,6 +177,12 @@ func createFileForBlob(ctx context.Context, pv *packages_model.PackageVersion, p
173177
}
174178

175179
func deleteBlob(ctx context.Context, ownerID int64, image, digest string) error {
180+
releaser, err := globallock.Lock(ctx, containerPkgName(ownerID, image))
181+
if err != nil {
182+
return err
183+
}
184+
defer releaser()
185+
176186
return db.WithTx(ctx, func(ctx context.Context) error {
177187
pfds, err := container_model.GetContainerBlobs(ctx, &container_model.BlobSearchOptions{
178188
OwnerID: ownerID,

routers/api/v1/admin/hooks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func ListHooks(ctx *context.APIContext) {
4545
}
4646
hooks := make([]*api.Hook, len(sysHooks))
4747
for i, hook := range sysHooks {
48-
h, err := webhook_service.ToHook(setting.AppURL+"/admin", hook)
48+
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", hook)
4949
if err != nil {
5050
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
5151
return
@@ -83,7 +83,7 @@ func GetHook(ctx *context.APIContext) {
8383
}
8484
return
8585
}
86-
h, err := webhook_service.ToHook("/admin/", hook)
86+
h, err := webhook_service.ToHook("/-/admin/", hook)
8787
if err != nil {
8888
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
8989
return

routers/api/v1/utils/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func checkCreateHookOption(ctx *context.APIContext, form *api.CreateHookOption)
100100
func AddSystemHook(ctx *context.APIContext, form *api.CreateHookOption) {
101101
hook, ok := addHook(ctx, form, 0, 0)
102102
if ok {
103-
h, err := webhook_service.ToHook(setting.AppSubURL+"/admin", hook)
103+
h, err := webhook_service.ToHook(setting.AppSubURL+"/-/admin", hook)
104104
if err != nil {
105105
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
106106
return
@@ -268,7 +268,7 @@ func EditSystemHook(ctx *context.APIContext, form *api.EditHookOption, hookID in
268268
ctx.Error(http.StatusInternalServerError, "GetSystemOrDefaultWebhook", err)
269269
return
270270
}
271-
h, err := webhook_service.ToHook(setting.AppURL+"/admin", updated)
271+
h, err := webhook_service.ToHook(setting.AppURL+"/-/admin", updated)
272272
if err != nil {
273273
ctx.Error(http.StatusInternalServerError, "convert.ToHook", err)
274274
return

routers/web/admin/admin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ func DashboardPost(ctx *context.Context) {
185185
}
186186
}
187187
if form.From == "monitor" {
188-
ctx.Redirect(setting.AppSubURL + "/admin/monitor/cron")
188+
ctx.Redirect(setting.AppSubURL + "/-/admin/monitor/cron")
189189
} else {
190-
ctx.Redirect(setting.AppSubURL + "/admin")
190+
ctx.Redirect(setting.AppSubURL + "/-/admin")
191191
}
192192
}
193193

routers/web/admin/applications.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var (
2323
func newOAuth2CommonHandlers() *user_setting.OAuth2CommonHandlers {
2424
return &user_setting.OAuth2CommonHandlers{
2525
OwnerID: 0,
26-
BasePathList: fmt.Sprintf("%s/admin/applications", setting.AppSubURL),
27-
BasePathEditPrefix: fmt.Sprintf("%s/admin/applications/oauth2", setting.AppSubURL),
26+
BasePathList: fmt.Sprintf("%s/-/admin/applications", setting.AppSubURL),
27+
BasePathEditPrefix: fmt.Sprintf("%s/-/admin/applications/oauth2", setting.AppSubURL),
2828
TplAppEdit: tplSettingsOauth2ApplicationEdit,
2929
}
3030
}

routers/web/admin/auths.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ func NewAuthSourcePost(ctx *context.Context) {
324324
log.Trace("Authentication created by admin(%s): %s", ctx.Doer.Name, form.Name)
325325

326326
ctx.Flash.Success(ctx.Tr("admin.auths.new_success", form.Name))
327-
ctx.Redirect(setting.AppSubURL + "/admin/auths")
327+
ctx.Redirect(setting.AppSubURL + "/-/admin/auths")
328328
}
329329

330330
// EditAuthSource render editing auth source page
@@ -437,7 +437,7 @@ func EditAuthSourcePost(ctx *context.Context) {
437437
log.Trace("Authentication changed by admin(%s): %d", ctx.Doer.Name, source.ID)
438438

439439
ctx.Flash.Success(ctx.Tr("admin.auths.update_success"))
440-
ctx.Redirect(setting.AppSubURL + "/admin/auths/" + strconv.FormatInt(form.ID, 10))
440+
ctx.Redirect(setting.AppSubURL + "/-/admin/auths/" + strconv.FormatInt(form.ID, 10))
441441
}
442442

443443
// DeleteAuthSource response for deleting an auth source
@@ -454,11 +454,11 @@ func DeleteAuthSource(ctx *context.Context) {
454454
} else {
455455
ctx.Flash.Error(fmt.Sprintf("auth_service.DeleteSource: %v", err))
456456
}
457-
ctx.JSONRedirect(setting.AppSubURL + "/admin/auths/" + url.PathEscape(ctx.PathParam(":authid")))
457+
ctx.JSONRedirect(setting.AppSubURL + "/-/admin/auths/" + url.PathEscape(ctx.PathParam(":authid")))
458458
return
459459
}
460460
log.Trace("Authentication deleted by admin(%s): %d", ctx.Doer.Name, source.ID)
461461

462462
ctx.Flash.Success(ctx.Tr("admin.auths.deletion_success"))
463-
ctx.JSONRedirect(setting.AppSubURL + "/admin/auths")
463+
ctx.JSONRedirect(setting.AppSubURL + "/-/admin/auths")
464464
}

routers/web/admin/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func SendTestMail(ctx *context.Context) {
4040
ctx.Flash.Info(ctx.Tr("admin.config.test_mail_sent", email))
4141
}
4242

43-
ctx.Redirect(setting.AppSubURL + "/admin/config")
43+
ctx.Redirect(setting.AppSubURL + "/-/admin/config")
4444
}
4545

4646
// TestCache test the cache settings
@@ -56,7 +56,7 @@ func TestCache(ctx *context.Context) {
5656
}
5757
}
5858

59-
ctx.Redirect(setting.AppSubURL + "/admin/config")
59+
ctx.Redirect(setting.AppSubURL + "/-/admin/config")
6060
}
6161

6262
func shadowPasswordKV(cfgItem, splitter string) string {

routers/web/admin/emails.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func ActivateEmail(ctx *context.Context) {
134134
ctx.Flash.Info(ctx.Tr("admin.emails.updated"))
135135
}
136136

137-
redirect, _ := url.Parse(setting.AppSubURL + "/admin/emails")
137+
redirect, _ := url.Parse(setting.AppSubURL + "/-/admin/emails")
138138
q := url.Values{}
139139
if val := ctx.FormTrim("q"); len(val) > 0 {
140140
q.Set("q", val)

0 commit comments

Comments
 (0)