I have a File database table with the following columns:
Id (PK), Filename
And a Document database table with the following columns:
Id (PK), Name, Description, FileId (FK)
Uploads the file they have selected. This will create a File record in the database, and the client will receive its Id in response.
Saves the Document with the given data (Name, FileId, etc.). This will create/update a Document record in the database.
I have a service set up that allows a user to download a file, provided they specify its Id. However, there is some security logic in the service that checks whether a user has permission to download the file, by checking whether there is at least one database "entity" associated with it that the user has access to. For example, a Document would be one such entity. So if a user can access a particular Document (determined by some business rules - but let's just say multiple users can access the same Document), they can download its file.
What are some ways I can solve this problem?