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
- Invalid query: Query on attribute has gr...
I cannot view the table within the Console
- Functions not executing after usage rese...
Hi team, Last month my project hit 100% usage and functions stopped working (expected). Now the new month has started and usage has reset, requests are going ...
- Functions never end and always fail (sta...
Hi ! I'm using Appwrite Cloud Pro and function execution from appwrite website is KO. Deploying starter function template, execution is always Failed and the ...