forked from forgejo/forgejo
Add repo_id for attachment (#16958)
When create a new issue or comment and paste/upload an attachment/image, it will not assign an issue id before submit. So if user give up the creating, the attachments will lost key feature and become dirty content. We don't know if we need to delete the attachment even if the repository deleted. This PR add a repo_id in attachment table so that even if a new upload attachment with no issue_id or release_id but should have repo_id. When deleting a repository, they could also be deleted. Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
f55cd033ed
commit
ddc709ff7f
15 changed files with 306 additions and 124 deletions
|
@ -5,40 +5,11 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUploadAttachment(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
fPath := "./attachment_test.go"
|
||||
f, err := os.Open(fPath)
|
||||
assert.NoError(t, err)
|
||||
defer f.Close()
|
||||
|
||||
buf := make([]byte, 1024)
|
||||
n, err := f.Read(buf)
|
||||
assert.NoError(t, err)
|
||||
buf = buf[:n]
|
||||
|
||||
attach, err := NewAttachment(&Attachment{
|
||||
UploaderID: user.ID,
|
||||
Name: filepath.Base(fPath),
|
||||
}, buf, f)
|
||||
assert.NoError(t, err)
|
||||
|
||||
attachment, err := GetAttachmentByUUID(attach.UUID)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, user.ID, attachment.UploaderID)
|
||||
assert.Equal(t, int64(0), attachment.DownloadCount)
|
||||
}
|
||||
|
||||
func TestIncreaseDownloadCount(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue