I would move this logic into the query rather than the view. Pass in the user_id as a parameter and return only the records that the user is allowed to view. It looks like your schema allows you to grant permission to a document based on your userID, or by a user's association with a group (which seems to be missing from the table structure, but you mentioned it in your description)
select documents.*
from documents
inner join doc_users on documents.number= doc_users.doc
where doc_users.user = ?
Union
select documents.*
from documents
inner join doc_groups on documents.number= doc_group.doc
inner join user_groups on user_groups.group = doc_groups.group
where user_groups.user = ?
i'm sure this query could be done without a union, but this is pretty clear to read and understand.