How to write to relations that use the subject rel...
# spicedb
d
Hi team, How to add existing relation to a relation. In the following schema, relation issue_creator: role#member, how to add role#member using API. I first added user as member and then tried adding the same user to project, didn't work.
Copy code
definition user {}

definition project {
    relation issue_creator: role#member
    relation issue_assigner: role#member
    relation any_issue_resolver: role#member
    relation assigned_issue_resolver: role#member
    relation comment_creator: role#member
    relation comment_deleter: role#member
    relation role_manager: role#member

    permission create_issue = issue_creator
    permission create_role = role_manager
}

definition role {
    relation project: project
    relation member: user
    relation built_in_role: project

    permission delete = project->role_manager - built_in_role->role_manager
    permission add_user = project->role_manager
    permission add_permission = project->role_manager - built_in_role->role_manager
    permission remove_permission = project->role_manager - built_in_role->role_manager
}

definition issue {
    relation project: project
    relation assigned: user

    permission assign = project->issue_assigner
    permission resolve = (project->assigned_issue_resolver & assigned) + project->any_issue_resolver
    permission create_comment = project->comment_creator

    // synthetic relation
    permission project_comment_deleter = project->comment_deleter
}

definition comment {
    relation issue: issue
    permission delete = issue->project_comment_deleter
}
@vroldanbet
v
Can you reformulate the question? I don't think I understand "how to add a relation to a relation". Do you mean "how to write a relationship to a relation"?
can you perhaps share here the relationships you are writting in tuple form like
resource-type:resource-id#relation@subject-type:subject-id#relation
form?
d
Sorry for the delayed response. Yes, my question was in the above example, a relationship was added to a relation instead of adding definition to a relation. I couldn't find any example on how to achieve the same with API.
@vroldanbet
v
@DharsanB what client library are you using? If you want to write relationships, you want to use the
WriteRelationships
API. An example with
zed
would look like this (which under the hood does
WriteRelationships
):
zed relationship create project:my_project_id issue_creator role:my_role_id member
The key here is that for the subject you must specify the relation
member
d
We're using the go library
I'll get back to you with the code since I'm unable to write relationships for the above schema
v
have you checked the docs? it has Go examples: https://authzed.com/docs/guides/first-app
2 Views