How to restrict some users not to write some directories in a branch?

I need to implement the policies described below
https://git-scm.com/book/en/v2/Customizing-Git-An-Example-Git-Enforced-Policy

Usually this is done by edit the server-side update hook.
But I cannot get the specific user who do the push operation. Maybe it because GitLab ask users to share the same git account to do git server access.
How can I control some users not to push any change to some directories in a branch by using GitLab?

I solved this issue.

Under each GitLab repository directory, a custom_hooks directory can be placed there.
Use the git lab shell lib to get the user name.

Can you maybe share the hook that did the trick? That might help others.