
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
- Teams Invite issue
We are getting this error ```AppwriteException: general_unknown, Server Error (500)``` when trying run the createPhoneToken after receiving a Teams invite email...
- Sam AWS CLI x Appwrite
Hello, I have a problem with my functions from Appwrite. Currently, we use AWS SAM CLI to simulate an API Gateway with Lambdas, where the client is initiated...
- appwrite not deducting any payment from ...
We have been trying to make payment, but none is successful treat this with urgency since our app has been down for almost 5 hours
