Created
June 11, 2023 17:15
-
-
Save jdittrich/3e9c9e7cf9dc00bb57801c0f8d91fce6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- get a collaborator ID and a document id | |
-- it should return nothing when the access is not allowed | |
-- it should return one entry when access is allowed | |
-- e.g. | |
-- get get bob and the object Kotti. Is bob allowed to see it (yes, bob is owner of the project) | |
-- get eve and the object kotti. Is eve allowed to see it (no, eve is neither collaborator nor ownwer) | |
-- SCHEMA is: | |
-- Documents: This is what people request. They might not have access to the document, we wanna check this. Documents belong to projects | |
-- Projects: Collect documents. Each project has an owner | |
-- Users: Can own projects or be collaborators on them | |
-- Collaborators: many-to-many match between users and projects | |
-- here tested with user id 2 and document id 2 but it could be any other id. | |
SELECT | |
documents.id as doc_id, | |
projects.id as proj_id, | |
documents.name as doc_name, | |
projects.name as proj_name, | |
join_users_projects.id_user as collaborator | |
FROM documents | |
JOIN projects on documents.project = projects.id | |
JOIN join_users_projects on join_users_projects.id_project = projects.id | |
WHERE collaborator = 2 | |
AND doc_id = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment