Hi I read about two ways for implementing per-document read access for couchapps:
I have some questions about this:
Are there more possibillities to acieve read access on document level?
How do i create a users private database in a couchapp? i do need admin rights for that but a user who fills out the signUp form of my application clearly can't have admin rights. do i need a middle-layer (php etc...) for the signup process so that i can create the database needed?
When i finally have this database i need to start continous replication using a filter. somewhere i read that such replications are not resumed when the server is rebooted. do i need a chronjob that recreates these replications ever x hours for the case that the server crashes??
isn't that a huge waste of disk space? most of the data gets duplicated for every user that registers for my application or am i wrong? (especially if there is only little information that must not be read by others)
The emit(key, value) function creates an entry in our view result . One more thing: the emit() function can be called multiple times in the map function to create multiple entries in the view results from a single document, but we are not doing that yet.
To solve this problem, but still keep sensitive and private information secured, there is a special configuration option public_fields . In this option you may define a comma-separated list of users document fields that will be publicly available.
I know of no other way that is immediately workable, besides for example modifying the CouchDB source code. One possibility is to use the trunk (or v1.1 when it is released) which may have an externals API. Externals are web servers CouchDB will forward some connections to.
You need a third layer, but not necessarily a middle layer. Your external software will connect to CouchDB as an admin and perform tasks that are pending. For example, when a user needs a new database, they create a document in a public DB, then the external software will create the database, assign the user as the admin, etc. It is very easy to do this by querying /_changes?feed=continuous
because you get a real-time feed of updates from users. I prefer this instead of a middle layer because the software is simpler (no extra web development, just CouchDB GET and PUT) and it can crash, restart, be upgraded, etc. without much impact to the users.
A cron job is not a bad idea anyway. Hey, it could be part of your external processor from step 2 above! However, beginning with CouchDB 1.1, replications will restart after a couch restart.
It should not waste much space. Depending on your application, you want to get all shared data in a shared database, and all private data in a private database per user. But even if you have duplicates of the data, I would not call it a waste. Disk space is a very small expense compared to developer effort or the intangible cost of security issues.
Depending on your application, you have huge opportunities in the future for mobile or offline features. When you release an iPhone, desktop, or offline webapp, users can work on a local replica of their database, then sync with the "official" database on your server once they are back online. For some apps, that is becoming a must-have features as people expect to use applications in any situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With