I'm trying to model my Parse database for ACL access with Roles. Roles will contain many users so that users can have groups with whom they share data. I am also locking all CLPs 100%. Only User will have public find() & write() access for login and creation.
I have not yet seen an exact situation where this was explained at all. I have seen many examples of relations, pointers and ACL Role access but none for shared, secured database. So far I cannot understand or extrapolate how I can have locked CLPs (no find()) and Role based ACL access. Can pointers or relations enable this somehow?
Current get colors either returns all objects with master key (obviously the opposite of what I want) or access denied.
Parse.Cloud.define("ccGetColors", async (request) => {
let currentUser = request.user;
let query = new Parse.Query("Color");
// query.equalTo("user", currentUser);
let results = await query.find({ useMasterKey: true });
if(results.length === 0) throw new Error('No results found!');
let steralizedResults = [];
for (let i = 0; i < results.length; i++) {
let object = results[i];
let color = object.get("color");
steralizedResults.push(color);
}
return steralizedResults;
});
Adding user to roles
Parse.Cloud.define("ccAddUserToRole", async function(request) {
let user = request.user;
// Get group admin ID
let userQuery = new Parse.Query("AddUser");
let results = await userQuery.find({ useMasterKey: true });
let resultObject = results[0];
let groupAdminObject = resultObject.get("groupAdmin");
let groupAdminID = groupAdminObject.id;
// Concatonate group name
let groupName = "Group_" + groupAdminID;
// Query for group role with group ID
let roleQuery = new Parse.Query(Parse.Role);
roleQuery.contains("name", groupName);
roleQuery.first({ useMasterKey: true }).then(function(role) {
console.log(role);
role.relation("users").add(user);
role.save(null, { useMasterKey: true });
});
});
- Currently role points to users, this is working nicely adding users as per above.
- My color class has Role based ACL access and works fine for a single user.
- All CPLs are currently locked and I want to keep it that way.
Can someone help point me in the right direction? Either pointer or relation me in the right direction ;)