hgweb: refactor checks for granting and revoking user permissions

Provides an entry point for extensions implementing more complex
authorization schemes.

Original patch proposed by Markus Zapke-Gründemann.