ICTatRTI / coconut-mobile-plugin-zanzibar

Plugins added to Coconut Mobile for project specific features
Other
0 stars 0 forks source link

Transferring cases not working #34

Open mikeymckay opened 5 years ago

mikeymckay commented 5 years ago

This has revealed a major problem. If we encrypt the database using crypto-pouch, then we are unable to replicate a document to the ecnrypted database, edit it, and then replicate back. Despite returning success messages, it fails. This is a known bug. Notes below:

Unable to replicate updated documents back to source when the source is a couchdb.

https://github.com/pouchdb-community/transform-pouch/issues/42

We use crypto-pouch which uses transform-pouch. Seems like the issues is in transform-pouch. It is crazy that this is a long term bug, since it seems to completely break a very normal use case.

Options:

1) Fix the bug in transform-pouch

2) Find a workaround. Some kind of manual 'replication-like' approach. Track the changes feed of the encrypted pouchdb instance. When a replication needs to be done, just do an upsert of the changed document on the couchdb. This will introduce a conflict when replicating from the couchdb back to the pouchdb, but the data itself (apart from the revision #) will be the same.

3) Remove encryption on the database. Can still encrypt a database for each user with that user's password. Inside each user's database could stores the login details for the server. This would ensure that a valid login would need to occur in order to sync data (we could block the application from working, but that could be hacked around). Ideally this would be the chance to switch to using actual couchdb users as the same users for Coconut.

cloudDB = new PouchDB('http://admin:password@localhost:5984/test')
pouchNotEncrypted = new PouchDB('pouchNotEncrypted')
pouchEncrypted = new PouchDB('pouchEncrypted')
pouchEncrypted.crypto("password")

cloudDB.replicate.to(pouchNotEncrypted)
.then (replicationResult) ->
  console.log replicationResult
  pouchNotEncrypted.get("doc")
.then (doc) ->
  console.log "pouchNotEncrypted before update:"
  console.log doc
  doc.a = "b"
  pouchNotEncrypted.put(doc)
.then  ->
  console.log "pouchNotEncrypted after update:"
  console.log doc
  pouchNotEncrypted.replicate.to(cloudDB)
.then (replicationResult) ->
  console.log replicationResult
  cloudDB.get("doc")
.then (doc) ->
  console.log "Cloud doc after replication:"
  console.log doc
  cloudDB.replicate.to(pouchEncrypted)
.then (replicationResult) ->
  console.log replicationResult
  pouchEncrypted.get("doc")
.then (doc) ->
  console.log "pouchEncrypted before update:"
  console.log doc
  doc.c = "d"
  pouchEncrypted.put(doc)
.then (doc) ->
  console.log "pouchEncrypted after update:"
  console.log doc
  pouchEncrypted.replicate.to(cloudDB)
.then (replicationResult) ->
  console.log replicationResult
  cloudDB.get("doc")
.then (doc) ->
  console.log "Cloud doc after replication:"
  console.log doc