Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

How to set database permission correctly

Hello,

I have checked Appery doc and tutorials but haven't yet found some sort of straightforward explanation how to set permissions to database collections.
In my scenario I have one collection to which all users must be given "read" permission and only one user who will be given both "read" and "write" permissions.

As far as I was able to learn it looks like that:

1) By default all collections except 'users' collection have their permissions set to "read" and "write" to all users.
2) Each collection has 'acl' field in which you can put permissions in JSON format like this:

{"*":{"read":true},"userID":{"read":true,"write":true}}

By doing so you will effectively limit the users' permissions.

So it is developer's job to:

1) define which user will be granted which permission.
2) update the 'acl' column of all object which permissions must be limited.

In my scenario, where I have quite small collection about 800 objects, I need to update 'acl' field of each object. Right?

If I am right then what is the best way to do it? Doing it manually is of course no option. I have considered the following approaches:

1) import the collection with 'acl' already preset in CSV file. This seemed the easiest way (copy the row it in Excel) but unfortunately it fell through because JSON permission string contains commas, which of course will break the structure of imported data.

2) run update query via Appery admin panel - this failed to, because there is only one update method available (single object update). You can not set "multi' flag like in this example:

db.collection.update( { "_id" : { $exists : true } }, objNew, upsert, true);

see here http://stackoverflow.com/questions/41...

3) run update from application editor - this is the approach suggested by Appery support in one of posts:

a) first run query service with 'where' criteria or just list service returning all objects.
b) then iterate through all results via data variable and Javascript, and set the value for each object.

So please tell me if I am right as to setting permissions?
I do not want all users to have write permissions to some of my db collections, for obvious reasons.

And is there any other approach to update 'acl' column, preferably faster and simpler than the ones outlined by me above?

I will be thankful for you guidance and any hints helping me and future Appery users to do it in the right way.

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

How to set database permission correctly

Hello,

The simplest way is to export your collection to .csv file. Find and replace fields values using some editor and import collection back.

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

How to set database permission correctly

Hello Igor,
Thanks, but what about commas? JSON acl will contain commas and the column number in CSV header will not match data structure, and the Appery will fail to load such CSV.

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

How to set database permission correctly

Anybody?
Tried, CSV, TSV, JSON, with no success. The problem is that you can not import this string:

{"*":{"read":true},"5?????????????8e114":{"read":true,"write":true}}

into ACL column because it contains quotes and commas.

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

How to set database permission correctly

Hello,

Could you send to a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a your exported .csv file and description what do you want to replace in this file. I'll check it.

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

How to set database permission correctly

Thanks Igor,

I have sent sample CSV file to a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a for further check, but it looks like I have found the solution FINALLY.

You can not paste (as I did) the JSON acl string taken from USERS collection. It looks like this:

{"*":{"read":true},"???USER_ID_HERE???":{"read":true,"write":true}}

and it WILL NOT BE imported into collection.

You have to put extra spaces before and after commas and brackets. So it should look like that:

{ "*" : { "read" : true} , "???USER_ID_HERE???" : { "read" : true , "write" : true}}

I have figured it out after analyzing the output of Appery CSV export.

So you can paste it into Excel cell and copy to as many rows as you want, then save as CSV and finally import the whole database into your collection.

Hope this helps.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

How to set database permission correctly

Hi Adam,

Thank you for sharing this!

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

How to set database permission correctly

You welcome.
Cheers.
Adam

Return to “Issues”