Fix a bug in pagination (no items) and fix permission check on attachments