Skip to content

Commit 5a6f3ae

Browse files
committed
go part cms-307
1 parent 17a6ef6 commit 5a6f3ae

10 files changed

+99
-8
lines changed

Diff for: backend/editor/OT/operations/application.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ func (op Operation) ApplyTo(document cmsjson.AstNode) (cmsjson.AstNode, error) {
3636
}
3737

3838
applicationIndex := op.Path[len(op.Path)-1]
39-
return op.Operation.Apply(parent, applicationIndex, op.OperationType)
39+
return op.Operation.Apply(parent, applicationIndex, op.Operation.GetEditType())
4040
}

Diff for: backend/editor/OT/operations/array_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// @implements OperationModel
1212
type ArrayOperation struct {
1313
NewValue float64
14+
operationType EditType
1415
}
1516

1617
// TransformAgainst is the ArrayOperation implementation of the operationModel interface
@@ -38,3 +39,9 @@ func (arrOp ArrayOperation) Apply(parentNode cmsjson.AstNode, applicationIndex i
3839

3940
return nil, errors.New("invalid application of an array operation, expected parent node to be an array")
4041
}
42+
43+
// getEditType is the ArrayOperation implementation of the OperationModel interface
44+
func (arrOp ArrayOperation) GetEditType() EditType {
45+
return arrOp.operationType
46+
}
47+

Diff for: backend/editor/OT/operations/boolean_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// @implements OperationModel
1212
type BooleanOperation struct {
1313
NewValue bool
14+
operationType EditType
1415
}
1516

1617
// TransformAgainst is the BooleanOperation implementation of the operationModel interface
@@ -31,3 +32,9 @@ func (boolOp BooleanOperation) Apply(parentNode cmsjson.AstNode, applicationInde
3132
}
3233
return nil, errors.New("invalid application of a primitive operation, expected parent node to be a primitive")
3334
}
35+
36+
// getEditType is the BooleanOperation implementation of the OperationModel interface
37+
func (boolOp BooleanOperation) GetEditType() EditType {
38+
return boolOp.operationType
39+
}
40+

Diff for: backend/editor/OT/operations/integer_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// @implementations of OperationModel
1212
type IntegerOperation struct {
1313
NewValue int
14+
operationType EditType
1415
}
1516

1617
// TransformAgainst is the IntegerOperation implementation of the operationModel interface
@@ -31,3 +32,9 @@ func (intOp IntegerOperation) Apply(parentNode cmsjson.AstNode, applicationIndex
3132
}
3233
return nil, errors.New("invalid application of a primitive operation, expected parent node to be a primitive")
3334
}
35+
36+
// getEditType is the IntegerOperation implementation of the OperationModel interface
37+
func (intOp IntegerOperation) GetEditType() EditType {
38+
return intOp.operationType
39+
}
40+

Diff for: backend/editor/OT/operations/noop_operation.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import "cms.csesoc.unsw.edu.au/pkg/cmsjson"
44

55
// Noop represents a non-existent operation
66
// @implements OperationModel
7-
type Noop struct{}
7+
type Noop struct {
8+
operationType EditType
9+
}
810

911
// TransformAgainst is the noop implementation of the operationModel interface
1012
func (noop Noop) TransformAgainst(operation OperationModel, applicationType EditType) (OperationModel, OperationModel) {
@@ -15,3 +17,8 @@ func (noop Noop) TransformAgainst(operation OperationModel, applicationType Edit
1517
func (noop Noop) Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) (cmsjson.AstNode, error) {
1618
return parentNode, nil
1719
}
20+
21+
// getEditType is the noop implementation of the OperationModel interface
22+
func (noop Noop) GetEditType() EditType {
23+
return noop.operationType
24+
}

Diff for: backend/editor/OT/operations/object_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// ObjectOperation represents an operation we perform on an object
1212
type ObjectOperation struct {
1313
NewValue datamodel.DataType
14+
operationType EditType
1415
}
1516

1617
// TransformAgainst is the ArrayOperation implementation of the operationModel interface
@@ -37,3 +38,9 @@ func (objOp ObjectOperation) Apply(parentNode cmsjson.AstNode, applicationIndex
3738
}
3839
return nil, errors.New("invalid application of an object operation, expected parent node to be an object")
3940
}
41+
42+
// getEditType is the ArrayOperation implementation of the OperationModel interface
43+
func (objOp ObjectOperation) GetEditType() EditType {
44+
return objOp.operationType
45+
}
46+

Diff for: backend/editor/OT/operations/operation_model.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@ type (
1212
OperationModel interface {
1313
TransformAgainst(op OperationModel, applicationType EditType) (OperationModel, OperationModel)
1414
Apply(parentNode cmsjson.AstNode, applicationIndex int, applicationType EditType) (cmsjson.AstNode, error)
15+
GetEditType() EditType
1516
}
1617

1718
// Operation is the fundamental incoming type from the frontend
1819
Operation struct {
1920
Path []int
20-
OperationType EditType
2121
AcknowledgedServerOps int
22-
23-
IsNoOp bool
24-
Operation OperationModel
22+
IsNoOp bool
23+
Operation OperationModel
2524
}
2625
)
2726

Diff for: backend/editor/OT/operations/string_operation.go

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
type StringOperation struct {
1313
RangeStart, RangeEnd int
1414
NewValue string
15+
operationType EditType
1516
}
1617

1718
// If NewValue == "", delete every character between RangeStart and RangeEnd
@@ -139,3 +140,9 @@ func deleteDelete(o1 StringOperation, o2 StringOperation, isLast bool) StringOpe
139140
}
140141
return o1
141142
}
143+
144+
// getEditType is the ArrayOperation implementation of the OperationModel interface
145+
func (arrOp StringOperation) GetEditType() EditType {
146+
return arrOp.operationType
147+
}
148+

Diff for: backend/editor/OT/operations/transform.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ package operations
55
func TransformPipeline(x Operation, y Operation) (Operation, Operation) {
66
// Finally normalise the operations to account for no-op return values
77
needsAppSpecific := false
8-
x.Path, y.Path, needsAppSpecific = transformPaths(x.Path, y.Path, x.OperationType, y.OperationType)
8+
x.Path, y.Path, needsAppSpecific = transformPaths(x.Path, y.Path, x.Operation.GetEditType(), y.Operation.GetEditType())
99
x, y = normaliseOperation(x), normaliseOperation(y)
1010

1111
if needsAppSpecific {
12-
x.Operation.TransformAgainst(y.Operation, x.OperationType)
12+
x.Operation.TransformAgainst(y.Operation, x.Operation.GetEditType())
1313
}
1414

1515
return x, y

Diff for: backend/endpoints/tests/volume_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,56 @@ import (
1616
)
1717

1818
func TestUploadDocument(t *testing.T) {
19+
controller := gomock.NewController(t)
20+
assert := assert.New(t)
21+
defer controller.Finish()
22+
23+
// ==== test setup =====
24+
entityID := uuid.New()
25+
parentID := uuid.New()
26+
entityToCreate := repositories.FilesystemEntry{
27+
LogicalName: "file",
28+
ParentFileID: parentID,
29+
IsDocument: true,
30+
OwnerUserId: 1,
31+
}
32+
33+
mockFileRepo := repMocks.NewMockIFilesystemRepository(controller)
34+
mockFileRepo.EXPECT().CreateEntry(entityToCreate).Return(repositories.FilesystemEntry{
35+
EntityID: entityID,
36+
LogicalName: "file",
37+
ParentFileID: parentID,
38+
IsDocument: true,
39+
OwnerUserId: 1,
40+
}, nil).Times(1)
41+
42+
temp, _ := ioutil.TempFile(os.TempDir(), "expected")
43+
defer os.Remove(temp.Name())
44+
45+
mockDockerFileSystemRepo := repMocks.NewMockIUnpublishedVolumeRepository(controller)
46+
mockDockerFileSystemRepo.EXPECT().GetFromVolume(entityID.String()).Return(temp, nil).Times(1)
47+
48+
mockDepFactory := createMockDependencyFactory(controller, mockFileRepo, true)
49+
mockDepFactory.EXPECT().GetUnpublishedVolumeRepo().Return(mockDockerFileSystemRepo)
50+
51+
const fileContent = "Hello World"
52+
53+
form := models.ValidDocumentUploadRequest{
54+
Parent: parentID,
55+
DocumentName: "file",
56+
Content: fileContent,
57+
}
58+
59+
response := endpoints.UploadDocument(form, mockDepFactory)
60+
assert.Equal(response.Status, http.StatusOK)
61+
assert.Equal(response.Response, models.NewEntityResponse{
62+
NewID: entityID,
63+
})
64+
65+
// check that the file was written to the docker volume
66+
actual, _ := ioutil.ReadFile(temp.Name())
67+
assert.Equal(actual, []byte(fileContent))
68+
1969
}
2070

2171
func TestGetPublishedDocument(t *testing.T) {

0 commit comments

Comments
 (0)