I need to set class level permission to some classes.
I referenced #92, and cheked Schema.js and spec/Schema.spec.js.
Also, set environment PARSE_EXPERIMENTAL_CONFIG_ENABLED=1.
I tried to get config and load schema. But I could not get config.
Parse.Cloud.define('restrict', function(req, res) {
Parse.Cloud.useMasterKey();
Parse.Config.get().then((config) => {
return config.database.loadSchema()
}).then((schema) => {
return schema.setPermissions('Product', {
'find': {}
});
}).then((schema) => {
res.success('OK');
}, (err) => {
res.error(err);
});
});
I got ParseError { code: 105, message: 'config does not exist' } on Parse.Config.get().
How to get config and set CLP?
You can get the right config object with:
var Config = require('parse-server/lib/Config');
var config = new Config('your-app-id', '/parse'); // second param is your mount point.
This config and globalConfig are so confusing :)
@gfosco Thanks for your advice.
I got config correctly, and set permission successfully!
Hi,
How to set a Role permissions in CLP level?
Thank's
It would be extremely useful to have some official documentation/sample code on the recommended way to set CLPs. At the moment I can't get my migrated app to work because it relies heavily on CLPs that I don't know how to migrate.
Do CLP's migrate in general, or no?
After search i found the answer how to implement CLP.
The CLP is implemented and can be set via rest api (with master key).
the relevant file in parse-server is Schema.js
example with Parse Js SDK:
Parse._request(
'PUT',
'schemas/' + className,
{className: className, fields: fields, classLevelPermissions: classLevelPermissions}
)
the value of fields and classLevelPermissions should match the format you get by GET request:
Parse._request(
'GET',
'schemas',
{}
)
example for CLP
"classLevelPermissions": {
"find": {
"FVPW0vrLEB": true
},
"get": {
"FVPW0vrLEB": true
},
"create": {},
"update": {},
"delete": {
"*": true
},
"addField": {
"role:isRulsMDfQ": true
}
}
i hope it's can helpful.
The newest version of the Parse Dashboard also lets you set CLPs, as long as you are also on the latest version of Parse Server.
Hi @gfosco, I try to use the Config class but it don't work :
const config = new Config(PARSE_APP_ID, ${PUBLIC_URL}/parse);
console.log(config); // stdout : Config {}
const schema = await config.database.loadSchema();
I got the error : TypeError: Cannot read property 'loadSchema' of undefined
I don't understand what change and what's wrong...
For CLPs, I use the REST interface. I often use Config, but not for this one.
Is it possible to do something like that with the REST interface ?
if (await schema.hasClass(className)) {
await schema.updateClass(className, fields);
} else {
await schema.addClassIfNotExists(className, fields);
}
Looks very doable.
Look at SchemasRouter, line 144.
I found a solution to access to Schema :
const schema = await Config.get(PARSE_APP_ID).database.loadSchema();
The Config class have probably change since 2016 and the class don't have the constructor but a static method get to factory the Config with all necessary property.
Thanks for you advice I will still check about the SchemasRouter for knowledge purpose (maybe a better solution for my need).
adding to previous comment by @brunoMaurice: see also https://medium.com/@mmazzarolo/parse-server-hidden-features-b4e86a236a7a
Most helpful comment
It would be extremely useful to have some official documentation/sample code on the recommended way to set CLPs. At the moment I can't get my migrated app to work because it relies heavily on CLPs that I don't know how to migrate.