Closed
Description
Is there a way to have a User Role by default ?
Imagine you have a class called Activities and you want to let only logged in to Users create objects in that class but only the user himself can delete or update his/her own object that he/she created.
The issue here we have to allow the (Public Create) in the CLP, which makes everybody can add a new entry in the class, but thanks to ACL only the user can delete or update his/her object, which is fine.
Expected Behavior:
- CLP Public Create should not always be allowed in order to let
User
create object
Workaround for now
- Create a new Role
User
and add a relation that add all users from the User class - Disallow CLP Public Create
- Add a new Row in the CLP for User Role and enable Create for it
This is only example, this can apply for any other operation such delete
Here example with delete
operation that doesn't work cause of CLP when Public Delete is not checked
- User create an object in the activity class
- This Activity has ACL set to [Public Read, Write : user_id]
- User try to delete that object by calling
object.destroy()
orobject.delete()
while CLP Public Delete is not allowed - User get Permission Denied
workaround in this case
- in BeforeDelete server need to call
Parse.Cloud.useMasterKey()
<- Bad idea! - Create a cloud function
deleteObject
which take theobjectId
andclassName
of the object
Parse.define('deleteObject', function (req, res) {
var Object = Parse.Object.extend(req.params.className)
var object = Object.createWithoutData(objectId)
// if you want you can call object.fetch() or just do
object.destroy( { useMasterKey : true }).then( // handle responses );
// for more security you can use sessionToken
// object.destory({ sessionToken : req.params.sessionToken }).then( ... ) <- I didn't test this yet
});
- Call that function from the client