Function checkPermission