Added permission check for flag link.

This commit checks whether a user has permission or not to see the flag/unflag link. Additionally we added some tests.
Same here, add a comment to explain your test.