I have a custom permissions set of a database with
“Who can delete content from this collection?” set to “Site Member Author”.
In one login session, I add a record, update it successfully using widData api., but when I attempt to delete it (using wixData.remove() )… it encountered this error.
“The current user does not have permissions to remove on the MyDatabase collection.”
I then even started from fresh, emptied all record using database editor, and started fresh. But still got the same error.
Even though, I think, it has nothing to do with dataset’s permissions, as a side note the corresponding dataset is configured for “Read & Write”.
Today without any change in permissions, the update also started failing with …
"The current user does not have permissions to update on the MyDatabase collection.
I realized that i am able to delete and update the newly added record.
But
Add->update->remove is consistently failing. (i.e. deleting an updated record is failing).
And Add->update->update (i.e. updating an updated record is failing.)
Found out that:
While i am updating/deleting record from the table (using a set of input fields and buttons next to the table), The record I am passing to the wixData.save() does not have Owner field in it (and so are Date created, Last Updated fields). This save operation wipes out the owner information, and hence the subsequent save() and delete() fails. Experimentally also found that all the columns not passed to the save() operation will be wiped out as well.
Workaround 1 (uses wixData API):
sRec = $w("#dataset).currentItem(); // saved record to reflect what is in collection
Now to do update the collection with partial record (pRec) synthesized from UI.
The reason I am not keeping or relying on previously saved _id in the pRec._id
// Because without it the merge (new with old) operation using Object.assign() creates a new id
// If specified, then the owner information does not get copied, so subsequent update/remove fails.
So work around is: not to keep _id in the pRec. And then …
pRec._id = sRec._id;
pRec._owner = sRec._owner;
Object.assign(sRec, pRec); // Now ends up keeping the same Id and owner.
wixData.save(collectionName, sRec);
Workaround 2 (uses wix-dataset API: better, cleaner):
Instead of using wixData APIs, I now used wid-dataset APIs for update.
$w(“#datasetName”).setFieldValues(pRec); // where pRec contains only the fields that are edited by user.
$w(“#datasetName”).save();