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.
You already have //, it should also have an actual comment that explains that this is doing.