[ticket/340] Correctly check if permission_setting template row exists

Fixes #340