Are there plans to support Class Level Permissions (CLP) after the migration?
I have seen no mention of the feature in the migration guide or any related discussion. I'm also not aware of any directly comparable behavior in vanilla Mongo. It appears that the Parse Server code is responsible for enforcing this behavior, presumably via the _SCHEMA collection that is not visible when I export all my data from Parse. I don't see a way to define this behavior for my migrated instance.
Yes. The eventual dashboard release will have a method for changing CLPs. Right now, CLPs are supported from migration, and there _is_ a method for setting them, but the format is not well documented. See Schema.js Schema.setPermissions. CLPs are stored in a metadata tag under the _SCHEMA collection rows.
@gfosco Are CLPs encoded entirely in the _SCHEMA records, or is some of the information stored elsewhere? That is, could I copy CLPs (including pointer permissions) from one instance of my app to another just by dumping the source instance's _SCHEMA and using it to replace the destination instance's _SCHEMA (assuming that the only difference between the two instances was in their CLPs)?
I want to be able to do this to get CLPs from dev to test, thence to prod, etc.
Thanks!
@christianpbrink did you find a way to do it?
I'm interested in this too, @gfosco @flovilmart do you have any suggestion on this?
Is there a way to programmatically set CLPs?
It would be nice to set the default CLPs from a config file.
I solved it this way:
export const createAdminUser = async () => {
const adminUser = await new User({
username: 'adminUser',
password: 'password',
email: '[email protected]'
}).save(null, { useMasterKey: true })
await addUserToAdminRole(adminUser)
console.log('createAdminUser -> done')
return adminUser
}
export const createAdminRole = async () => {
const acl = new Parse.ACL()
acl.setPublicReadAccess(true)
acl.setPublicWriteAccess(false)
const adminRole = new Role()
adminRole.set('name', 'admin')
adminRole.setACL(acl)
await adminRole.save({}, { useMasterKey: true })
console.log('createAdminRole -> done')
}
export const getAdminUser = async () => {
const admin = await Parse.User.logIn('adminUser', 'password')
return admin
}
export const addUserToAdminRole = async (user) => {
const adminRole = await new Parse.Query(Role)
.equalTo('name', 'admin')
.first()
const users = adminRole.relation('users')
users.add(user)
await adminRole.save({}, { useMasterKey: true })
console.log('addUserToAdminRole -> done')
}
export const createClasses = async () => {
const config = new Config('TEST_APP_ID', '/api')
const schema = await config.database.loadSchema()
await schema.addClassIfNotExists('Service', {
listText: { type: 'String' },
formText: { type: 'String' },
hasDateTime: { type: 'Boolean' },
hasLocation: { type: 'Boolean' }
})
console.log('createClasses -> done')
}
export const setCLPs = async () => {
const config = new Config('TEST_APP_ID', '/api')
const schema = await config.database.loadSchema()
await schema.setPermissions('Service', {
get: { 'role:admin': true, '*': true },
find: { 'role:admin': true, '*': true },
create: { 'role:admin': true },
update: { 'role:admin': true },
delete: { 'role:admin': true },
addField: {}
})
console.log('setCLPs -> done')
}
I can also use it to make test much more useful now.
That's unfortunate that features like this are not documented (except for the .spec), because Parse-Server under the hood is really flexible and you can be creative in a lot of ways (e.g.: tweak the setCLPs function above and feed with a JSON file with all the CLPs settings).
Whops, addClassIfNotExists throw an error if the class exists 馃摣 :
try {
await schema.addClassIfNotExists('Service', {
listText: { type: 'String' },
formText: { type: 'String' },
hasDateTime: { type: 'Boolean' },
hasLocation: { type: 'Boolean' }
})
} catch (err) {
if (err.code === 103) {
console.log(err.message)
} else {
throw err
}
}
@flovilmart @gfosco @christianpbrink
https://medium.com/@mmazzarolo/parse-server-hidden-features-b4e86a236a7a#.ulc9jozhs
I wrote a post about this, just putting it here because it might help in my opinion (feel free to remove it if it is considered spamming)
@mmazzarolo that's real neat :) You know what would be even better? Exposing cleanly those tricks through a nice API (instead of loading the modules from the paths that may change :))
Yep, I agree.
Thanks anyway, you're doing an awesome job with parse!
@mmazzarolo if you want to tackle, parse-server as API, go ahead :) that would be a real nice thing to have it in a programmable way.
I'll probably give it a try as soon as I have some free time then.
I'll keep you informed ;)
Most helpful comment
I solved it this way:
I can also use it to make test much more useful now.
That's unfortunate that features like this are not documented (except for the .spec), because Parse-Server under the hood is really flexible and you can be creative in a lot of ways (e.g.: tweak the
setCLPsfunction above and feed with a JSON file with all the CLPs settings).