Fix query def perm check

Fix bug when checking permissions on query definition.