Skip to content

Commit e6e0e71

Browse files
committed
Remove AfterDelete function in comment
1 parent b15d136 commit e6e0e71

Some content is hidden

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

46 files changed

+240
-282
lines changed

cmd/admin_user_delete.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,10 @@ func runDeleteUser(ctx context.Context, c *cli.Command) error {
8080
return fmt.Errorf("the user %s does not match the provided id %d", user.Name, c.Int64("id"))
8181
}
8282

83-
return user_service.DeleteUser(ctx, user, c.Bool("purge"))
83+
adminUser, err := user_model.GetAdminUser(ctx)
84+
if err != nil {
85+
return fmt.Errorf("failed to get admin user: %w", err)
86+
}
87+
88+
return user_service.DeleteUser(ctx, adminUser, user, c.Bool("purge"))
8489
}

models/issues/comment.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,6 @@ func (c *Comment) LoadPoster(ctx context.Context) (err error) {
390390
return err
391391
}
392392

393-
// AfterDelete is invoked from XORM after the object is deleted.
394-
func (c *Comment) AfterDelete(ctx context.Context) {
395-
if c.ID <= 0 {
396-
return
397-
}
398-
399-
_, err := repo_model.DeleteAttachmentsByComment(ctx, c.ID, true)
400-
if err != nil {
401-
log.Info("Could not delete files for comment %d on issue #%d: %s", c.ID, c.IssueID, err)
402-
}
403-
}
404-
405393
// HTMLURL formats a URL-string to the issue-comment
406394
func (c *Comment) HTMLURL(ctx context.Context) string {
407395
err := c.LoadIssue(ctx)

models/repo/attachment.go

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@ import (
88
"errors"
99
"fmt"
1010
"net/url"
11-
"os"
1211
"path"
1312

1413
"code.gitea.io/gitea/models/db"
15-
"code.gitea.io/gitea/modules/log"
1614
"code.gitea.io/gitea/modules/setting"
17-
"code.gitea.io/gitea/modules/storage"
1815
"code.gitea.io/gitea/modules/timeutil"
1916
"code.gitea.io/gitea/modules/util"
2017
)
@@ -166,61 +163,6 @@ func GetAttachmentByReleaseIDFileName(ctx context.Context, releaseID int64, file
166163
return attach, nil
167164
}
168165

169-
// DeleteAttachment deletes the given attachment and optionally the associated file.
170-
func DeleteAttachment(ctx context.Context, a *Attachment, remove bool) error {
171-
_, err := DeleteAttachments(ctx, []*Attachment{a}, remove)
172-
return err
173-
}
174-
175-
// DeleteAttachments deletes the given attachments and optionally the associated files.
176-
func DeleteAttachments(ctx context.Context, attachments []*Attachment, remove bool) (int, error) {
177-
if len(attachments) == 0 {
178-
return 0, nil
179-
}
180-
181-
ids := make([]int64, 0, len(attachments))
182-
for _, a := range attachments {
183-
ids = append(ids, a.ID)
184-
}
185-
186-
cnt, err := db.GetEngine(ctx).In("id", ids).NoAutoCondition().Delete(attachments[0])
187-
if err != nil {
188-
return 0, err
189-
}
190-
191-
if remove {
192-
for i, a := range attachments {
193-
if err := storage.Attachments.Delete(a.RelativePath()); err != nil {
194-
if !errors.Is(err, os.ErrNotExist) {
195-
return i, err
196-
}
197-
log.Warn("Attachment file not found when deleting: %s", a.RelativePath())
198-
}
199-
}
200-
}
201-
return int(cnt), nil
202-
}
203-
204-
// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
205-
func DeleteAttachmentsByIssue(ctx context.Context, issueID int64, remove bool) (int, error) {
206-
attachments, err := GetAttachmentsByIssueID(ctx, issueID)
207-
if err != nil {
208-
return 0, err
209-
}
210-
211-
return DeleteAttachments(ctx, attachments, remove)
212-
}
213-
214-
// DeleteAttachmentsByComment deletes all attachments associated with the given comment.
215-
func DeleteAttachmentsByComment(ctx context.Context, commentID int64, remove bool) (int, error) {
216-
attachments, err := GetAttachmentsByCommentID(ctx, commentID)
217-
if err != nil {
218-
return 0, err
219-
}
220-
221-
return DeleteAttachments(ctx, attachments, remove)
222-
}
223-
224166
// UpdateAttachmentByUUID Updates attachment via uuid
225167
func UpdateAttachmentByUUID(ctx context.Context, attach *Attachment, cols ...string) error {
226168
if attach.UUID == "" {

models/repo/attachment_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,6 @@ func TestGetByCommentOrIssueID(t *testing.T) {
4242
assert.Len(t, attachments, 2)
4343
}
4444

45-
func TestDeleteAttachments(t *testing.T) {
46-
assert.NoError(t, unittest.PrepareTestDatabase())
47-
48-
count, err := repo_model.DeleteAttachmentsByIssue(db.DefaultContext, 4, false)
49-
assert.NoError(t, err)
50-
assert.Equal(t, 2, count)
51-
52-
count, err = repo_model.DeleteAttachmentsByComment(db.DefaultContext, 2, false)
53-
assert.NoError(t, err)
54-
assert.Equal(t, 2, count)
55-
56-
err = repo_model.DeleteAttachment(db.DefaultContext, &repo_model.Attachment{ID: 8}, false)
57-
assert.NoError(t, err)
58-
59-
attachment, err := repo_model.GetAttachmentByUUID(db.DefaultContext, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a18")
60-
assert.Error(t, err)
61-
assert.True(t, repo_model.IsErrAttachmentNotExist(err))
62-
assert.Nil(t, attachment)
63-
}
64-
6545
func TestGetAttachmentByID(t *testing.T) {
6646
assert.NoError(t, unittest.PrepareTestDatabase())
6747

routers/api/v1/admin/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func DeleteUser(ctx *context.APIContext) {
300300
return
301301
}
302302

303-
if err := user_service.DeleteUser(ctx, ctx.ContextUser, ctx.FormBool("purge")); err != nil {
303+
if err := user_service.DeleteUser(ctx, ctx.Doer, ctx.ContextUser, ctx.FormBool("purge")); err != nil {
304304
if repo_model.IsErrUserOwnRepos(err) ||
305305
org_model.IsErrUserHasOrgs(err) ||
306306
packages_model.IsErrUserOwnPackages(err) ||

routers/api/v1/org/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ func Delete(ctx *context.APIContext) {
421421
// "404":
422422
// "$ref": "#/responses/notFound"
423423

424-
if err := org.DeleteOrganization(ctx, ctx.Org.Organization, false); err != nil {
424+
if err := org.DeleteOrganization(ctx, ctx.Doer, ctx.Org.Organization, false); err != nil {
425425
ctx.APIErrorInternal(err)
426426
return
427427
}

routers/api/v1/repo/issue_attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ func DeleteIssueAttachment(ctx *context.APIContext) {
318318
return
319319
}
320320

321-
if err := repo_model.DeleteAttachment(ctx, attachment, true); err != nil {
321+
if err := attachment_service.DeleteAttachment(ctx, attachment); err != nil {
322322
ctx.APIErrorInternal(err)
323323
return
324324
}

routers/api/v1/repo/issue_comment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ func deleteIssueComment(ctx *context.APIContext) {
726726
return
727727
}
728728

729-
if _, err = issue_service.DeleteComment(ctx, ctx.Doer, comment); err != nil {
729+
if _, err = issue_service.DeleteComment(ctx, ctx.Doer, comment, true); err != nil {
730730
ctx.APIErrorInternal(err)
731731
return
732732
}

routers/api/v1/repo/issue_comment_attachment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ func DeleteIssueCommentAttachment(ctx *context.APIContext) {
330330
return
331331
}
332332

333-
if err := repo_model.DeleteAttachment(ctx, attach, true); err != nil {
333+
if err := attachment_service.DeleteAttachment(ctx, attach); err != nil {
334334
ctx.APIErrorInternal(err)
335335
return
336336
}

routers/api/v1/repo/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func Migrate(ctx *context.APIContext) {
203203
}
204204

205205
if repo != nil {
206-
if errDelete := repo_service.DeleteRepositoryDirectly(ctx, repo.ID); errDelete != nil {
206+
if errDelete := repo_service.DeleteRepositoryDirectly(ctx, ctx.Doer, repo.ID); errDelete != nil {
207207
log.Error("DeleteRepository: %v", errDelete)
208208
}
209209
}

0 commit comments

Comments
 (0)