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
- general_route_not_found - Auth Guide
If you’ve just added a subdomain to your project, verified your DNS records, and confirmed your SSL certificate is working, but you're still hitting a `general_...
- Can't resume paused project
I have logged in in incognito, done the email verification and still get the invalid fingerprint error. What's the issue.
- Download appwrite Docs
Is there is a way to download appwrite Docs ? Because appwrite skill isn't enough to give the agent full understanding about how appwrite works (I noticed this ...