Skip to content

Commit e50adec

Browse files
committed
Fix
1 parent 7134ad9 commit e50adec

File tree

6 files changed

+29
-20
lines changed

6 files changed

+29
-20
lines changed

models/issues/comment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,9 @@ func UpdateCommentAttachments(ctx context.Context, c *Comment, uuids []string) e
599599
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err)
600600
}
601601
for i := range attachments {
602-
if attachments[i].IssueID != 0 || attachments[i].CommentID != 0 {
602+
if attachments[i].CommentID == c.ID && attachments[i].IssueID == c.IssueID {
603+
continue
604+
} else if attachments[i].IssueID != 0 || attachments[i].CommentID != 0 {
603605
return util.NewPermissionDeniedErrorf("update comment attachments permission denied")
604606
}
605607
attachments[i].IssueID = c.IssueID

models/issues/issue_update.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ func UpdateIssueAttachments(ctx context.Context, issueID int64, uuids []string)
305305
return fmt.Errorf("getAttachmentsByUUIDs [uuids: %v]: %w", uuids, err)
306306
}
307307
for i := range attachments {
308-
if attachments[i].IssueID != 0 {
308+
if attachments[i].IssueID == issueID {
309+
continue
310+
} else if attachments[i].IssueID != 0 {
309311
return util.NewPermissionDeniedErrorf("update issue attachments permission denied")
310312
}
311313
attachments[i].IssueID = issueID

models/migrations/migrations.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"code.gitea.io/gitea/models/migrations/v1_22"
2525
"code.gitea.io/gitea/models/migrations/v1_23"
2626
"code.gitea.io/gitea/models/migrations/v1_24"
27+
"code.gitea.io/gitea/models/migrations/v1_25"
2728
"code.gitea.io/gitea/models/migrations/v1_6"
2829
"code.gitea.io/gitea/models/migrations/v1_7"
2930
"code.gitea.io/gitea/models/migrations/v1_8"
@@ -382,6 +383,9 @@ func prepareMigrationTasks() []*migration {
382383
newMigration(318, "Add anonymous_access_mode for repo_unit", v1_24.AddRepoUnitAnonymousAccessMode),
383384
newMigration(319, "Add ExclusiveOrder to Label table", v1_24.AddExclusiveOrderColumnToLabelTable),
384385
newMigration(320, "Migrate two_factor_policy to login_source table", v1_24.MigrateSkipTwoFactor),
386+
387+
// Gitea 1.24.0-rc0 ends at migration ID number 320 (database version 321)
388+
newMigration(321, "Add file status columns to attachment table", v1_25.AddFileStatusToAttachment),
385389
}
386390
return preparedMigrations
387391
}

models/migrations/v1_25/v321.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type Attachment321 struct {
2222
Name string
2323
DownloadCount int64 `xorm:"DEFAULT 0"`
2424
Status db.FileStatus `xorm:"DEFAULT 1 NOT NULL"` // 1 = normal, 2 = to be deleted
25-
DeleteFailedCount int `xorm:"DEFAULT 0"` // Number of times the deletion failed, used to prevent infinite loop
25+
DeleteFailedCount int `xorm:"DEFAULT 0 NOT NULL"` // Number of times the deletion failed, used to prevent infinite loop
2626
LastDeleteFailedTime timeutil.TimeStamp // Last time the deletion failed, used to prevent infinite loop
2727
Size int64 `xorm:"DEFAULT 0"`
2828
CreatedUnix timeutil.TimeStamp `xorm:"created"`
@@ -34,28 +34,28 @@ func (a *Attachment321) TableName() string {
3434

3535
// TableIndices implements xorm's TableIndices interface
3636
func (a *Attachment321) TableIndices() []*schemas.Index {
37-
uuidIndex := schemas.NewIndex("attachment_uuid", schemas.UniqueType)
37+
uuidIndex := schemas.NewIndex("uuid", schemas.UniqueType)
3838
uuidIndex.AddColumn("uuid")
3939

40-
repoIndex := schemas.NewIndex("attachment_repo_id", schemas.IndexType)
40+
repoIndex := schemas.NewIndex("repo_id", schemas.IndexType)
4141
repoIndex.AddColumn("repo_id")
4242

43-
issueIndex := schemas.NewIndex("attachment_issue_id", schemas.IndexType)
43+
issueIndex := schemas.NewIndex("issue_id", schemas.IndexType)
4444
issueIndex.AddColumn("issue_id")
4545

46-
releaseIndex := schemas.NewIndex("attachment_release_id", schemas.IndexType)
46+
releaseIndex := schemas.NewIndex("release_id", schemas.IndexType)
4747
releaseIndex.AddColumn("release_id")
4848

49-
uploaderIndex := schemas.NewIndex("attachment_uploader_id", schemas.IndexType)
49+
uploaderIndex := schemas.NewIndex("uploader_id", schemas.IndexType)
5050
uploaderIndex.AddColumn("uploader_id")
5151

52-
commentIndex := schemas.NewIndex("attachment_comment_id", schemas.IndexType)
52+
commentIndex := schemas.NewIndex("comment_id", schemas.IndexType)
5353
commentIndex.AddColumn("comment_id")
5454

55-
statusIndex := schemas.NewIndex("attachment_status", schemas.IndexType)
55+
statusIndex := schemas.NewIndex("status", schemas.IndexType)
5656
statusIndex.AddColumn("status")
5757

58-
statusIDIndex := schemas.NewIndex("attachment_status_id", schemas.IndexType)
58+
statusIDIndex := schemas.NewIndex("status_id", schemas.IndexType)
5959
statusIDIndex.AddColumn("status", "id") // For status = ? AND id > ? query
6060

6161
return []*schemas.Index{

models/repo/attachment.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Attachment struct {
3030
Name string
3131
DownloadCount int64 `xorm:"DEFAULT 0"`
3232
Status db.FileStatus `xorm:"DEFAULT 1 NOT NULL"` // 1 = normal, 2 = to be deleted
33-
DeleteFailedCount int `xorm:"DEFAULT 0"` // Number of times the deletion failed, used to prevent infinite loop
33+
DeleteFailedCount int `xorm:"DEFAULT 0 NOT NULL"` // Number of times the deletion failed, used to prevent infinite loop
3434
LastDeleteFailedReason string `xorm:"TEXT"` // Last reason the deletion failed, used to prevent infinite loop
3535
LastDeleteFailedTime timeutil.TimeStamp // Last time the deletion failed, used to prevent infinite loop
3636
Size int64 `xorm:"DEFAULT 0"`
@@ -40,28 +40,28 @@ type Attachment struct {
4040

4141
// TableIndices implements xorm's TableIndices interface
4242
func (a *Attachment) TableIndices() []*schemas.Index {
43-
uuidIndex := schemas.NewIndex("attachment_uuid", schemas.UniqueType)
43+
uuidIndex := schemas.NewIndex("uuid", schemas.UniqueType)
4444
uuidIndex.AddColumn("uuid")
4545

46-
repoIndex := schemas.NewIndex("attachment_repo_id", schemas.IndexType)
46+
repoIndex := schemas.NewIndex("repo_id", schemas.IndexType)
4747
repoIndex.AddColumn("repo_id")
4848

49-
issueIndex := schemas.NewIndex("attachment_issue_id", schemas.IndexType)
49+
issueIndex := schemas.NewIndex("issue_id", schemas.IndexType)
5050
issueIndex.AddColumn("issue_id")
5151

52-
releaseIndex := schemas.NewIndex("attachment_release_id", schemas.IndexType)
52+
releaseIndex := schemas.NewIndex("release_id", schemas.IndexType)
5353
releaseIndex.AddColumn("release_id")
5454

55-
uploaderIndex := schemas.NewIndex("attachment_uploader_id", schemas.IndexType)
55+
uploaderIndex := schemas.NewIndex("uploader_id", schemas.IndexType)
5656
uploaderIndex.AddColumn("uploader_id")
5757

58-
commentIndex := schemas.NewIndex("attachment_comment_id", schemas.IndexType)
58+
commentIndex := schemas.NewIndex("comment_id", schemas.IndexType)
5959
commentIndex.AddColumn("comment_id")
6060

61-
statusIndex := schemas.NewIndex("attachment_status", schemas.IndexType)
61+
statusIndex := schemas.NewIndex("status", schemas.IndexType)
6262
statusIndex.AddColumn("status")
6363

64-
statusIDIndex := schemas.NewIndex("attachment_status_id", schemas.IndexType)
64+
statusIDIndex := schemas.NewIndex("status_id", schemas.IndexType)
6565
statusIDIndex.AddColumn("status", "id") // For status = ? AND id > ? query
6666

6767
return []*schemas.Index{

services/attachment/attachment.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func Init() error {
9292
if cleanQueue == nil {
9393
return errors.New("Unable to create attachments-clean queue")
9494
}
95+
go graceful.GetManager().RunWithCancel(cleanQueue)
9596
return nil
9697
}
9798

0 commit comments

Comments
 (0)