Skip to content

Commit 7d14f41

Browse files
committed
Merge remote-tracking branch 'origin/main' into prevent-deadlock-queue-test
2 parents 6246993 + f34151b commit 7d14f41

File tree

28 files changed

+581
-503
lines changed

28 files changed

+581
-503
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ or if sqlite support is required:
7474
The `build` target is split into two sub-targets:
7575

7676
- `make backend` which requires [Go 1.16](https://golang.org/dl/) or greater.
77-
- `make frontend` which requires [Node.js 12.17](https://nodejs.org/en/download/) or greater and Internet connectivity to download npm dependencies.
77+
- `make frontend` which requires [Node.js LTS](https://nodejs.org/en/download/) or greater and Internet connectivity to download npm dependencies.
7878

7979
When building from the official source tarballs which include pre-built frontend files, the `frontend` target will not be triggered, making it possible to build without Node.js and Internet connectivity.
8080

cmd/admin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
auth_service "code.gitea.io/gitea/services/auth"
2727
"code.gitea.io/gitea/services/auth/source/oauth2"
2828
repo_service "code.gitea.io/gitea/services/repository"
29+
user_service "code.gitea.io/gitea/services/user"
2930

3031
"github.com/urfave/cli"
3132
)
@@ -534,7 +535,7 @@ func runDeleteUser(c *cli.Context) error {
534535
return fmt.Errorf("The user %s does not match the provided id %d", user.Name, c.Int64("id"))
535536
}
536537

537-
return models.DeleteUser(user)
538+
return user_service.DeleteUser(user)
538539
}
539540

540541
func runRepoSyncReleases(_ *cli.Context) error {

models/admin/notice.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ func (n *Notice) TrStr() string {
4343
}
4444

4545
// CreateNotice creates new system notice.
46-
func CreateNotice(tp NoticeType, desc string, args ...interface{}) error {
47-
return CreateNoticeCtx(db.DefaultContext, tp, desc, args...)
48-
}
49-
50-
// CreateNoticeCtx creates new system notice.
51-
func CreateNoticeCtx(ctx context.Context, tp NoticeType, desc string, args ...interface{}) error {
46+
func CreateNotice(ctx context.Context, tp NoticeType, desc string, args ...interface{}) error {
5247
if len(args) > 0 {
5348
desc = fmt.Sprintf(desc, args...)
5449
}
@@ -61,38 +56,28 @@ func CreateNoticeCtx(ctx context.Context, tp NoticeType, desc string, args ...in
6156

6257
// CreateRepositoryNotice creates new system notice with type NoticeRepository.
6358
func CreateRepositoryNotice(desc string, args ...interface{}) error {
64-
return CreateNoticeCtx(db.DefaultContext, NoticeRepository, desc, args...)
59+
return CreateNotice(db.DefaultContext, NoticeRepository, desc, args...)
6560
}
6661

6762
// RemoveAllWithNotice removes all directories in given path and
6863
// creates a system notice when error occurs.
69-
func RemoveAllWithNotice(title, path string) {
70-
RemoveAllWithNoticeCtx(db.DefaultContext, title, path)
71-
}
72-
73-
// RemoveStorageWithNotice removes a file from the storage and
74-
// creates a system notice when error occurs.
75-
func RemoveStorageWithNotice(bucket storage.ObjectStorage, title, path string) {
76-
removeStorageWithNotice(db.DefaultContext, bucket, title, path)
77-
}
78-
79-
func removeStorageWithNotice(ctx context.Context, bucket storage.ObjectStorage, title, path string) {
80-
if err := bucket.Delete(path); err != nil {
64+
func RemoveAllWithNotice(ctx context.Context, title, path string) {
65+
if err := util.RemoveAll(path); err != nil {
8166
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
8267
log.Warn(title+" [%s]: %v", path, err)
83-
if err = CreateNoticeCtx(ctx, NoticeRepository, desc); err != nil {
68+
if err = CreateNotice(ctx, NoticeRepository, desc); err != nil {
8469
log.Error("CreateRepositoryNotice: %v", err)
8570
}
8671
}
8772
}
8873

89-
// RemoveAllWithNoticeCtx removes all directories in given path and
74+
// RemoveStorageWithNotice removes a file from the storage and
9075
// creates a system notice when error occurs.
91-
func RemoveAllWithNoticeCtx(ctx context.Context, title, path string) {
92-
if err := util.RemoveAll(path); err != nil {
76+
func RemoveStorageWithNotice(ctx context.Context, bucket storage.ObjectStorage, title, path string) {
77+
if err := bucket.Delete(path); err != nil {
9378
desc := fmt.Sprintf("%s [%s]: %v", title, path, err)
9479
log.Warn(title+" [%s]: %v", path, err)
95-
if err = CreateNoticeCtx(ctx, NoticeRepository, desc); err != nil {
80+
if err = CreateNotice(ctx, NoticeRepository, desc); err != nil {
9681
log.Error("CreateRepositoryNotice: %v", err)
9782
}
9883
}

models/admin/notice_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package admin
77
import (
88
"testing"
99

10+
"code.gitea.io/gitea/models/db"
1011
"code.gitea.io/gitea/models/unittest"
1112

1213
"github.com/stretchr/testify/assert"
@@ -28,7 +29,7 @@ func TestCreateNotice(t *testing.T) {
2829
Description: "test description",
2930
}
3031
unittest.AssertNotExistsBean(t, noticeBean)
31-
assert.NoError(t, CreateNotice(noticeBean.Type, noticeBean.Description))
32+
assert.NoError(t, CreateNotice(db.DefaultContext, noticeBean.Type, noticeBean.Description))
3233
unittest.AssertExistsAndLoadBean(t, noticeBean)
3334
}
3435

models/consistency.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func DeleteOrphanedIssues() error {
128128

129129
// Remove issue attachment files.
130130
for i := range attachmentPaths {
131-
admin_model.RemoveAllWithNoticeCtx(db.DefaultContext, "Delete issue attachment", attachmentPaths[i])
131+
admin_model.RemoveAllWithNotice(db.DefaultContext, "Delete issue attachment", attachmentPaths[i])
132132
}
133133
return nil
134134
}

models/org.go

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package models
77

88
import (
9+
"context"
910
"fmt"
1011
"strings"
1112

@@ -14,9 +15,7 @@ import (
1415
user_model "code.gitea.io/gitea/models/user"
1516
"code.gitea.io/gitea/modules/log"
1617
"code.gitea.io/gitea/modules/setting"
17-
"code.gitea.io/gitea/modules/storage"
1818
"code.gitea.io/gitea/modules/structs"
19-
"code.gitea.io/gitea/modules/util"
2019

2120
"xorm.io/builder"
2221
"xorm.io/xorm"
@@ -254,68 +253,23 @@ func CountOrganizations() int64 {
254253
return count
255254
}
256255

257-
// DeleteOrganization completely and permanently deletes everything of organization.
258-
func DeleteOrganization(org *User) (err error) {
259-
if !org.IsOrganization() {
260-
return fmt.Errorf("%s is a user not an organization", org.Name)
261-
}
262-
263-
sess := db.NewSession(db.DefaultContext)
264-
defer sess.Close()
265-
266-
if err = sess.Begin(); err != nil {
267-
return err
268-
}
269-
270-
if err = deleteOrg(sess, org); err != nil {
271-
if IsErrUserOwnRepos(err) {
272-
return err
273-
} else if err != nil {
274-
return fmt.Errorf("deleteOrg: %v", err)
275-
}
276-
}
277-
278-
return sess.Commit()
279-
}
280-
281-
func deleteOrg(e *xorm.Session, u *User) error {
282-
// Check ownership of repository.
283-
count, err := getRepositoryCount(e, u)
284-
if err != nil {
285-
return fmt.Errorf("GetRepositoryCount: %v", err)
286-
} else if count > 0 {
287-
return ErrUserOwnRepos{UID: u.ID}
288-
}
256+
// DeleteOrganization deletes models associated to an organization.
257+
func DeleteOrganization(ctx context.Context, org *User) error {
258+
e := db.GetEngine(ctx)
289259

290260
if err := deleteBeans(e,
291-
&Team{OrgID: u.ID},
292-
&OrgUser{OrgID: u.ID},
293-
&TeamUser{OrgID: u.ID},
294-
&TeamUnit{OrgID: u.ID},
261+
&Team{OrgID: org.ID},
262+
&OrgUser{OrgID: org.ID},
263+
&TeamUser{OrgID: org.ID},
264+
&TeamUnit{OrgID: org.ID},
295265
); err != nil {
296266
return fmt.Errorf("deleteBeans: %v", err)
297267
}
298268

299-
if _, err = e.ID(u.ID).Delete(new(User)); err != nil {
269+
if _, err := e.ID(org.ID).Delete(new(User)); err != nil {
300270
return fmt.Errorf("Delete: %v", err)
301271
}
302272

303-
// FIXME: system notice
304-
// Note: There are something just cannot be roll back,
305-
// so just keep error logs of those operations.
306-
path := UserPath(u.Name)
307-
308-
if err := util.RemoveAll(path); err != nil {
309-
return fmt.Errorf("Failed to RemoveAll %s: %v", path, err)
310-
}
311-
312-
if len(u.Avatar) > 0 {
313-
avatarPath := u.CustomAvatarRelativePath()
314-
if err := storage.Avatars.Delete(avatarPath); err != nil {
315-
return fmt.Errorf("Failed to remove %s: %v", avatarPath, err)
316-
}
317-
}
318-
319273
return nil
320274
}
321275

models/org_test.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -261,24 +261,6 @@ func TestCountOrganizations(t *testing.T) {
261261
assert.Equal(t, expected, CountOrganizations())
262262
}
263263

264-
func TestDeleteOrganization(t *testing.T) {
265-
assert.NoError(t, unittest.PrepareTestDatabase())
266-
org := unittest.AssertExistsAndLoadBean(t, &User{ID: 6}).(*User)
267-
assert.NoError(t, DeleteOrganization(org))
268-
unittest.AssertNotExistsBean(t, &User{ID: 6})
269-
unittest.AssertNotExistsBean(t, &OrgUser{OrgID: 6})
270-
unittest.AssertNotExistsBean(t, &Team{OrgID: 6})
271-
272-
org = unittest.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
273-
err := DeleteOrganization(org)
274-
assert.Error(t, err)
275-
assert.True(t, IsErrUserOwnRepos(err))
276-
277-
user := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
278-
assert.Error(t, DeleteOrganization(user))
279-
unittest.CheckConsistencyFor(t, &User{}, &Team{})
280-
}
281-
282264
func TestIsOrganizationOwner(t *testing.T) {
283265
assert.NoError(t, unittest.PrepareTestDatabase())
284266
test := func(orgID, userID int64, expected bool) {

models/repo.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func NewRepoContext() {
134134
loadRepoConfig()
135135
unit.LoadUnitConfig()
136136

137-
admin_model.RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
137+
admin_model.RemoveAllWithNotice(db.DefaultContext, "Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
138138
}
139139

140140
// RepositoryStatus defines the status of repository
@@ -1649,36 +1649,36 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
16491649

16501650
// Remove repository files.
16511651
repoPath := repo.RepoPath()
1652-
admin_model.RemoveAllWithNotice("Delete repository files", repoPath)
1652+
admin_model.RemoveAllWithNotice(db.DefaultContext, "Delete repository files", repoPath)
16531653

16541654
// Remove wiki files
16551655
if repo.HasWiki() {
1656-
admin_model.RemoveAllWithNotice("Delete repository wiki", repo.WikiPath())
1656+
admin_model.RemoveAllWithNotice(db.DefaultContext, "Delete repository wiki", repo.WikiPath())
16571657
}
16581658

16591659
// Remove archives
16601660
for i := range archivePaths {
1661-
admin_model.RemoveStorageWithNotice(storage.RepoArchives, "Delete repo archive file", archivePaths[i])
1661+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.RepoArchives, "Delete repo archive file", archivePaths[i])
16621662
}
16631663

16641664
// Remove lfs objects
16651665
for i := range lfsPaths {
1666-
admin_model.RemoveStorageWithNotice(storage.LFS, "Delete orphaned LFS file", lfsPaths[i])
1666+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.LFS, "Delete orphaned LFS file", lfsPaths[i])
16671667
}
16681668

16691669
// Remove issue attachment files.
16701670
for i := range attachmentPaths {
1671-
admin_model.RemoveStorageWithNotice(storage.Attachments, "Delete issue attachment", attachmentPaths[i])
1671+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", attachmentPaths[i])
16721672
}
16731673

16741674
// Remove release attachment files.
16751675
for i := range releaseAttachments {
1676-
admin_model.RemoveStorageWithNotice(storage.Attachments, "Delete release attachment", releaseAttachments[i])
1676+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete release attachment", releaseAttachments[i])
16771677
}
16781678

16791679
// Remove attachment with no issue_id and release_id.
16801680
for i := range newAttachmentPaths {
1681-
admin_model.RemoveStorageWithNotice(storage.Attachments, "Delete issue attachment", attachmentPaths[i])
1681+
admin_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", attachmentPaths[i])
16821682
}
16831683

16841684
if len(repo.Avatar) > 0 {
@@ -1803,8 +1803,8 @@ func getPrivateRepositoryCount(e db.Engine, u *User) (int64, error) {
18031803
}
18041804

18051805
// GetRepositoryCount returns the total number of repositories of user.
1806-
func GetRepositoryCount(u *User) (int64, error) {
1807-
return getRepositoryCount(db.GetEngine(db.DefaultContext), u)
1806+
func GetRepositoryCount(ctx context.Context, u *User) (int64, error) {
1807+
return getRepositoryCount(db.GetEngine(ctx), u)
18081808
}
18091809

18101810
// GetPublicRepositoryCount returns the total number of public repositories of user.

models/repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestMetas(t *testing.T) {
7171
func TestGetRepositoryCount(t *testing.T) {
7272
assert.NoError(t, unittest.PrepareTestDatabase())
7373

74-
count, err1 := GetRepositoryCount(&User{ID: int64(10)})
74+
count, err1 := GetRepositoryCount(db.DefaultContext, &User{ID: int64(10)})
7575
privateCount, err2 := GetPrivateRepositoryCount(&User{ID: int64(10)})
7676
publicCount, err3 := GetPublicRepositoryCount(&User{ID: int64(10)})
7777
assert.NoError(t, err1)

0 commit comments

Comments
 (0)