How can I update the permissions of a document using cloud functions, the code below gives me the aforementioned error:
`import { Client, Databases, Permission, Query, Role } from 'node-appwrite';
export default async function ({ req, res }) {
console.log(req);
const client = new Client()
.setEndpoint(process.env.REACT_APP_APPWRITE_BASE_URL)
.setProject(process.env.REACT_APP_APPWRITE_PROJECT_KEY);
const database = new Databases(client);
try{
const team = "xxx";
const response = await database.updateDocument(
process.env.REACT_APP_APPWRITE_DATABASE_ID,
process.env.REACT_APP_APPWRITE_COMPANIES_COLLECTION_ID,
"yyy",
{},
[
Permission.read(Role.team("team:" + team)),
Permission.update(Role.team("team:" + team)),
Permission.delete(Role.team("team:" + team))
]
);
}catch (error) {
console.log(error);
}
};
If these are all going to the same team you can just do
Permissions.Write(Role.Team(team))
Thanks for the tip @Kenny . This was my initial setup and I was still getting the same issue
https://appwrite.io/docs/advanced/platform/permissions#example-1-basic-usage
Looking at the docs, you don't have to do team:team_id
It's just the team_id. So with your current setup it would be.
[
Permission.read(Role.team(team)),
Permission.update(Role.team(team)),
Permission.delete(Role.team(team))
]
Were you doing "team:"+team? I believe it would just be team
Yes, here is the updated code:
`import { Client, Databases, Permission, Query, Role } from 'node-appwrite';
export default async function ({ req, res }) {
console.log(req);
const client = new Client()
.setEndpoint(process.env.REACT_APP_APPWRITE_BASE_URL)
.setProject(process.env.REACT_APP_APPWRITE_PROJECT_KEY);
const database = new Databases(client);
try{
const team = "xx";
console.log("The Team is", team);
const response = await database.updateDocument(
process.env.REACT_APP_APPWRITE_DATABASE_ID,
process.env.REACT_APP_APPWRITE_COMPANIES_COLLECTION_ID,
"yy",
{},
[
Permission.read(Role.team(team)),
Permission.update(Role.team(team)),
Permission.delete(Role.team(team))
]
);
console.log("Permissions Update", response);
}catch (error) {
console.log(error);
throw error;
}
return res.json({ ok: true, message: 'Vote cast.'}); }; `
Recommended threads
- How to Display File in Web?
I'm trying to use Appwrite's Storage to store images and display them in my app, however when I use the `getFileView`, `getFileDownload` or `getFilePreview` met...
- Selfhosted Github App installation
I've followed this guide: https://appwrite.io/docs/advanced/self-hosting/configuration/version-control to connect GitHub to my self-hosted Appwrite instance (1....
- Project Paused Despite Daily Active Usag...
I noticed that my project was automatically **paused**, even though it is actively being used. The project is an **attendance application** that is used daily b...