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
- education plan not activated
Hi I have an edu id 13103046@iubat.edu but when I am trying to claim my plan and trying to logging with github where education student plan active. the appwrite...
- I'm getting an error on the console "j?....
On my self hosted instance version 1.8.1 the console is giving me this error when trying to view the rows for a table I recently created. My application is read...
- 500 simultaneous OAuth logins from the s...
Hi, I'd like to ask about rate limiting around Google OAuth login on Appwrite Cloud. **OVERVIEW** Service type: A PWA (web app) for members of a university clu...