Creating read-only document?

22 views
Skip to first unread message

MobDev

unread,
Oct 14, 2014, 7:16:37 PM10/14/14
to mobile-c...@googlegroups.com
Hey guys, is it possible to create read only document?

We are pushing "global" documents to all users using channels and roles.

lets say someone accessed the cblite file and changed the global document, how do we reject these changes on app/sync function?

One solution we thought about is setting owner while creating global document, is there another way to handle this?

Does this mean if someone adds fake documents to the cblite database those will sync as well?

Thanks a lot.

Cheers,

ajres

unread,
Oct 15, 2014, 3:05:15 AM10/15/14
to mobile-c...@googlegroups.com
@MobDev

There are a number of features available to you in the sync function that can restrict who can create and modify documents e.g for the following doc format.

{"_id": "ACA9083F",

 "owner": "alice",

 "readers": ["bob",…],

 "category": "riddle",

 "text": "Why is a…"

}


You might use these in your sync function



"Every document must have an owner."

if (!doc.owner)

    throw({forbidden: "Missing owner"});


"The owner property must be immutable."

if (oldDoc && doc.owner != oldDoc.owner)

    throw({forbidden: "Owner changed"});


"The owner is the user who is creating the document."

requireUser(doc.owner);


"Only those with the 'creator' role can create documents."

requireRole("creators");



MobDev

unread,
Oct 15, 2014, 8:42:27 PM10/15/14
to mobile-c...@googlegroups.com
Got it, Thanks a lot.

Cheers,
Reply all
Reply to author
Forward
0 new messages