I have a function which I'm trying to have create a document in a collection. The collection in question has row security enabled and permissions set to grant users create access.
The purpose of the function is to clone a bunch of documents for the user, including ones in this particular collection. The function implementation is as follows:
async function cloneAnswerAsync (baseAnswer, userID, createdAnswerFiles)
{
try
{
let clonedAnswerFileID = null;
// If the answer has a file, clone it.
if (baseAnswer["value-file"])
{
clonedAnswerFileID = await cloneAnswerFileAsync (baseAnswer["value-file"], userID);
if (!clonedAnswerFileID)
{
return null;
}
createdAnswerFiles.push (clonedAnswerFileID);
}
// Create the new Answer with cloned data.
const clonedData = { ...baseAnswer };
// Remove system fields.
delete clonedData.$id;
delete clonedData.$createdAt;
delete clonedData.$updatedAt;
delete clonedData.$permissions;
delete clonedData.$collectionId;
delete clonedData.$databaseId;
// Override file reference if cloned.
if (clonedAnswerFileID)
{
clonedData["value-file"] = clonedAnswerFileID;
}
// TODO: Figure out why this results in AppwriteException: The current user is not authorized to perform the requested action.
const result = await databases.createDocument (
databaseID,
collectionAnswers,
ID.unique (),
clonedData,
[`write("user:${userID}")`, `read("user:${userID}")`]
);
return result;
}
catch (exception)
{
error ("Failed to clone answer: ", exception);
return null;
}
}
The function scopes are set to: users.read, rows.read, rows.write, execution.write and executes its API calls via a Client configured with an API key given via env var, configured with the same scopes.
Any ideas what might be going on here?
Recommended threads
- Function deployment failed: Unable to re...
Hi Appwrite team, I have been experiencing persistent errors when i attempt to push my appwrite functions. The logs on the deployment detail page on the console...
- One to many 2 way, console UI not correc...
Hey, seems I'm facing the exactly same issue with this one: https://github.com/appwrite/appwrite/issues/6016 Since this Github issue stay open for so long, let ...
- Server Down
Appwrite services are down. When will they start working again?