[misc] Small refactoring to improve the code.
XWIKI-11449: The link to a document that you don't have the right to view is broken
* Bulletproofing the code in case the user doesn't have the right to view the document.