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
- Clean install of 1.9.0 shows errors in a...
I just run a full clean install of Appwrite on my server following the Manual installation guide in the docs page. The console seems to work, visually there d...
- Setup custom domain on selfhosted behind...
Hello everyone, can anyone help me to setup a custom domain on a selfhosted appwrite instance thats running behind cloudflare tunnels? Current setup: Appwrite r...
- Why does this happen?
`AppwriteException: general_argument_invalid, Invalid `secret` param: Value must be a valid string and at least 1 chars and no longer than 256 chars (400)` the...