Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API rule join syntax for "sharing" records with other users? #4475

Closed
j6k4m8 opened this issue Mar 2, 2024 · 0 comments
Closed

API rule join syntax for "sharing" records with other users? #4475

j6k4m8 opened this issue Mar 2, 2024 · 0 comments

Comments

@j6k4m8
Copy link

j6k4m8 commented Mar 2, 2024

Hi team, wondering how you'd approach this query that (I believe) needs an aliased join. Very hard to debug these rules (requires an edit and then running a few queries as a test suite) so hoping you might have some insight!

Here's a super simple MVP schema to illustrate; Users write Storys and collect them in Books.

Story
    text:    string
    author:  →User
    book:    →Book

User
    id
    username

Book
    owner:   →User

Here, a user is allowed to edit any Story for which they are an author. Fine, easy:

-- Story permission:
@request.auth.id = author.id

Now they want to invite some collaborators. The best way I can think of doing this (for arbitrary, large number of collaborators) is a separate collection that stores the permission. (i.e., I'd rather avoid a list of relations, since I think that's an anti-pattern here?)

EditPermission:
    book_owner: →User
    book:       →Book
    grantee:    →User

In this toy example I want any user who has been granted permission to a book to be able to edit the constituent stories.

-- Story permission:
-- I am the original creator,
(@request.auth.id = creator.id) 
||
-- Or I have been granted permission to a book:
???

It seems that this is a new feature with the @collection and aliasing capabilities, but I absolutely cannot decode the documentation here nor the answer here for this use-case. Hopefully some help here will aid other users in a similar situation :)

@j6k4m8 j6k4m8 changed the title API rule for "shared" records API rule join syntax for "sharing" records with other users? Mar 2, 2024
@pocketbase pocketbase locked and limited conversation to collaborators Mar 2, 2024
@ganigeorgiev ganigeorgiev converted this issue into discussion #4476 Mar 2, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant