Added permission check on templates directory