I am using Parse Server (on Node.js) and have to expand my application to give my users a new function.
I have a class class called 'Programme'. Previously I locked this programme down to user only ACL using a before save function:
Parse.Cloud.beforeSave("Programme", function(req, res) {
user = req.object.get("user");
var acl = new Parse.ACL();
acl.setReadAccess(req.user, true);
acl.setWriteAccess(req.user, true);
req.object.setACL(acl);
res.success();
});
However I now wish to give the users a button to toggle the public view of a Program.
I have coded the button to request the cloud code and have got the beginning of a working function.
However, I have issues with checking if the queried programme has already got public view ACL set, or if it needs setting.
Questions:
How can I toggle the
setPublicReadAccess
of an item in theProgramme
class.How can I deconflict this with my
beforeSave
function, because I expect my function is going to change it and then thebeforeSave
function will change it straight back.
My function so far:
Parse.Cloud.define('toggleSharedProgramme', function(req, res) {
var user = req.object;
var programmeId = req.params.programmeId;
var query = new Parse.Query("Programme");
query.equalTo("objectId", programmeId);
query.first({ sessionToken: req.user.getSessionToken()}).then(function(results) {
var acl = new Parse.ACL();
// acl.setReadAccess(req.user, true);
// acl.setWriteAccess(req.user, true);
acl.setPublicReadAccess(true);
results.setACL(acl);
results.save();
res.success('Working - code needs to be added to set the programme's ACL');
})
});
Aucun commentaire:
Enregistrer un commentaire