Fixed a bug when checking permissions.