move
This commit is contained in:
@@ -5,9 +5,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Document struct {
|
type Document struct {
|
||||||
DocumentUUID *string
|
DocumentUUID *string
|
||||||
DocumentName string
|
DocumentType int
|
||||||
DocumentType int
|
DocumentName *string
|
||||||
|
DocumentOriginalName string
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -44,8 +45,24 @@ func NewDocument(documentName string, documentType int) (error, *Document) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return nil, &Document{
|
return nil, &Document{
|
||||||
DocumentName: documentName,
|
DocumentName: &documentName,
|
||||||
DocumentType: documentType,
|
DocumentType: documentType,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Document) GetOriginalName() *string {
|
||||||
|
|
||||||
|
return &d.DocumentOriginalName
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Document) GetName() *string {
|
||||||
|
|
||||||
|
if d.DocumentName == nil {
|
||||||
|
return d.GetOriginalName()
|
||||||
|
}
|
||||||
|
|
||||||
|
return d.DocumentName
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+10
-4
@@ -1,11 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/vaultdrop/backend/config"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// err, config := config.LoadApplicationConfig()
|
err, config := config.LoadApplicationConfig()
|
||||||
|
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ func (s *Services) MoveDocumentIntoDocument(from *entities.Document, to *entitie
|
|||||||
return fmt.Errorf(entities.ERROR_DOCUMENT_NOT_PERCISTED)
|
return fmt.Errorf(entities.ERROR_DOCUMENT_NOT_PERCISTED)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if to.DocumentType != entities.DIRECTORY {
|
||||||
|
return fmt.Errorf("The destination document must be a directory")
|
||||||
|
}
|
||||||
|
|
||||||
if canEdit, _ := UserCanEditDocument(s.ConnectedUser, from); canEdit == false {
|
if canEdit, _ := UserCanEditDocument(s.ConnectedUser, from); canEdit == false {
|
||||||
return fmt.Errorf("You can not edit this folder")
|
return fmt.Errorf("You can not edit this folder")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,40 @@ func TestMoveDocument(t *testing.T) {
|
|||||||
t.Errorf(`Error creating antoine user %v`, err)
|
t.Errorf(`Error creating antoine user %v`, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fakeUUID := "dsqdsq"
|
||||||
err, document := entities.NewDocument("test.pdf", entities.FILE)
|
err, document := entities.NewDocument("test.pdf", entities.FILE)
|
||||||
|
document.DocumentUUID = &fakeUUID
|
||||||
|
|
||||||
err, folder := entities.NewDocument("orga", entities.DIRECTORY)
|
err, folder := entities.NewDocument("orga", entities.DIRECTORY)
|
||||||
|
folder.DocumentUUID = &fakeUUID
|
||||||
|
|
||||||
service := New(userAntoine)
|
service := New(userAntoine)
|
||||||
|
|
||||||
err := service.MoveDocumentIntoDocument(document, folder)
|
err = service.MoveDocumentIntoDocument(document, folder)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMoveDocumentToAFile(t *testing.T) {
|
||||||
|
|
||||||
|
err, userAntoine := entities.NewUser("antoine")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf(`Error creating antoine user %v`, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
err, document := entities.NewDocument("test.pdf", entities.FILE)
|
||||||
|
|
||||||
|
err, notAFolder := entities.NewDocument("orga", entities.FILE)
|
||||||
|
|
||||||
|
service := New(userAntoine)
|
||||||
|
|
||||||
|
err = service.MoveDocumentIntoDocument(document, notAFolder)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user