Skip to content

Commit

Permalink
fix: rm write access (#1433)
Browse files Browse the repository at this point in the history
* fix document_id param

* check fingerprint in testworld test

* rm default write access for document creator

* rm unnecessary DID generation
  • Loading branch information
charleenfei authored Aug 25, 2020
1 parent b0073bd commit ad2d178
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
6 changes: 0 additions & 6 deletions documents/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,11 @@ func (s service) UpdateModel(ctx context.Context, payload UpdatePayload) (Model,
// Derive looks for specific document type service based in the schema and delegates the Derivation to that service.˜
func (s service) Derive(ctx context.Context, payload UpdatePayload) (Model, error) {
if len(payload.DocumentID) == 0 {
did, err := contextutil.AccountDID(ctx)
if err != nil {
return nil, ErrDocumentConfigAccountID
}

doc, err := s.New(payload.Scheme)
if err != nil {
return nil, err
}

payload.Collaborators.ReadWriteCollaborators = append(payload.Collaborators.ReadWriteCollaborators, did)
if err := doc.(Deriver).DeriveFromCreatePayload(ctx, payload.CreatePayload); err != nil {
return nil, errors.NewTypedError(ErrDocumentInvalid, err)
}
Expand Down
15 changes: 8 additions & 7 deletions documents/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/centrifuge/go-centrifuge/errors"
"github.com/centrifuge/go-centrifuge/identity"
"github.com/centrifuge/go-centrifuge/jobs"
testingconfig "github.com/centrifuge/go-centrifuge/testingutils/config"
"github.com/centrifuge/go-centrifuge/testingutils/testingjobs"
Expand Down Expand Up @@ -160,20 +161,20 @@ func TestService_Derive(t *testing.T) {
attrs := map[AttrKey]Attribute{
attr.Key: attr,
}
cid, err := identity.NewDIDFromString("0xBAEb33a61f05e6F269f1c4b4CFF91A901B54DaF7")
assert.NoError(t, err)
payload := UpdatePayload{CreatePayload: CreatePayload{
Scheme: scheme,
Attributes: attrs,
Collaborators: CollaboratorsAccess{
ReadCollaborators: nil,
ReadWriteCollaborators: []identity.DID{cid},
},
}}
s := service{}

// missing account ctx
ctx := context.Background()
_, err = s.Derive(ctx, payload)
assert.Error(t, err)
assert.True(t, errors.IsOfType(ErrDocumentConfigAccountID, err))

// unknown scheme
ctx = testingconfig.CreateAccountContext(t, cfg)
ctx := testingconfig.CreateAccountContext(t, cfg)
s.registry = NewServiceRegistry()
_, err = s.Derive(ctx, payload)
assert.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion testworld/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func setupTransitionRuleForCharlie(t *testing.T) (string, string) {
charlie := doctorFord.getHostTestSuite(t, "Charlie")

// Alice prepares document to share with Bob
docPayload := genericCoreAPICreate([]string{bob.id.String()})
docPayload := genericCoreAPICreate([]string{bob.id.String(), alice.id.String()})
res := createDocumentV2(alice.httpExpect, alice.id.String(), "documents", http.StatusCreated, docPayload)
status := getDocumentStatus(t, res)
assert.Equal(t, status, "pending")
Expand Down
2 changes: 1 addition & 1 deletion testworld/v2_documents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func TestDocument_ComputeFields(t *testing.T) {
alice := doctorFord.getHostTestSuite(t, "Alice")
bob := doctorFord.getHostTestSuite(t, "Bob")

payload := genericCoreAPICreate(nil)
payload := genericCoreAPICreate([]string{alice.id.String()})
res := createDocumentV2(alice.httpExpect, alice.id.String(), "documents", http.StatusCreated, payload)
status := getDocumentStatus(t, res)
assert.Equal(t, status, "pending")
Expand Down

0 comments on commit ad2d178

Please sign in to comment.