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.