
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
- 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
- Appwrite OAuth2 says Key and Secret not ...
Hello Appwriter, i'm creating an OAuth Login with Apple, i have configure everything on my Apple Developer Account and in my Appwrite Console, **When i Login ...
- [SOLVED] Running into error 400 when lin...
I cant find the create collection under database, all I see is create tables and this is affecting my react app
