| 171 | return {"invites": [InviteSerializerFull(invite).data for invite in instance]} |
| 172 | |
| 173 | def validate(self, attrs): # type: ignore[no-untyped-def] |
| 174 | for email in attrs.get("emails", []): |
| 175 | if Invite.objects.filter( # type: ignore[misc] |
| 176 | email=email, organisation__id=self.context.get("organisation") |
| 177 | ).exists(): |
| 178 | raise serializers.ValidationError( |
| 179 | {"emails": "Invite for email %s already exists" % email} |
| 180 | ) |
| 181 | return super(MultiInvitesSerializer, self).validate(attrs) |
| 182 | |
| 183 | def _get_invited_by(self): # type: ignore[no-untyped-def] |
| 184 | return self.context.get("request").user if self.context.get("request") else None # type: ignore[union-attr] |