feat(privacy): keep venue phone numbers out of every public response
A doctor's office number sat next to the address on the public profile and in the anonymous API payload, so harvesting the phone number of every practice in the country was one unauthenticated request away. Street address and map coordinates stay public — a patient needs those to find the place — but the phone is now opt-in per caller: DoctorAddress::toArray() and the clinic serializers only emit it when told to, and the public doctor/clinic endpoints tell them to only when the caller may edit that profile (the same can_edit they already compute). Owner-facing address CRUD keeps returning it unchanged. The patient still gets the number where it is actually useful — their own appointment. That payload also stops guessing: it used to serialise the doctor's *first* address, so a booking made at the clinic or at a second office showed the wrong street entirely. It now resolves the address recorded on the appointment itself, which works the same for a personal office and a clinic branch, and falls back to the clinic's own number when the address has none. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,10 @@ use App\Tests\ApiTestCase;
|
||||
* A clinic whose address record said Karaj then rendered a Yazd street on the
|
||||
* public site. Contact fields must all resolve from the address record, and only
|
||||
* fall back to the legacy columns when that record has nothing to offer.
|
||||
*
|
||||
* The phone is a separate matter: it is not public data, so the anonymous
|
||||
* response must never carry it. The resolution order is still asserted, just
|
||||
* through the owner's view of the same endpoint.
|
||||
*/
|
||||
class ClinicContactSourceTest extends ApiTestCase
|
||||
{
|
||||
@@ -26,10 +30,23 @@ class ClinicContactSourceTest extends ApiTestCase
|
||||
$data = $this->fetchClinic($clinic);
|
||||
|
||||
$this->assertSame('کرج، بلوار طالقانی', $data['location']);
|
||||
$this->assertSame('02634567890', $data['phone']);
|
||||
$this->assertSame('02634567890', $data['phone_number']);
|
||||
$this->assertSame('کرج', $data['city'][0]['name'] ?? null);
|
||||
$this->assertSame('البرز', $data['state'][0]['name'] ?? null);
|
||||
|
||||
$owner = $this->fetchClinicAsOwner($clinic);
|
||||
$this->assertSame('02634567890', $owner['phone']);
|
||||
$this->assertSame('02634567890', $owner['phone_number']);
|
||||
}
|
||||
|
||||
public function testThePublicResponseCarriesNoPhoneNumber(): void
|
||||
{
|
||||
$clinic = $this->createClinic('یزد، خیابان قدیمی', '03531234567');
|
||||
$this->createAddressFor($clinic, 'کرج، بلوار طالقانی', '02634567890');
|
||||
|
||||
$data = $this->fetchClinic($clinic);
|
||||
|
||||
$this->assertNull($data['phone'], 'شمارهٔ کلینیک نباید در پاسخ عمومی بیاید');
|
||||
$this->assertNull($data['phone_number']);
|
||||
}
|
||||
|
||||
public function testLegacyColumnsAreUsedWhenTheClinicHasNoAddressRecord(): void
|
||||
@@ -39,8 +56,8 @@ class ClinicContactSourceTest extends ApiTestCase
|
||||
$data = $this->fetchClinic($clinic);
|
||||
|
||||
$this->assertSame('یزد، خیابان قدیمی', $data['location']);
|
||||
$this->assertSame('03531234567', $data['phone']);
|
||||
$this->assertSame([], $data['city']);
|
||||
$this->assertSame('03531234567', $this->fetchClinicAsOwner($clinic)['phone']);
|
||||
}
|
||||
|
||||
public function testBlankAddressFieldsFallBackInsteadOfBlankingTheContactBlock(): void
|
||||
@@ -51,8 +68,8 @@ class ClinicContactSourceTest extends ApiTestCase
|
||||
$data = $this->fetchClinic($clinic);
|
||||
|
||||
$this->assertSame('یزد، خیابان قدیمی', $data['location']);
|
||||
$this->assertSame('03531234567', $data['phone']);
|
||||
$this->assertSame('کرج', $data['city'][0]['name'] ?? null);
|
||||
$this->assertSame('03531234567', $this->fetchClinicAsOwner($clinic)['phone']);
|
||||
}
|
||||
|
||||
private function createClinic(?string $legacyAddress, ?string $legacyPhone): Clinic
|
||||
@@ -92,4 +109,13 @@ class ClinicContactSourceTest extends ApiTestCase
|
||||
|
||||
return json_decode($this->client->getResponse()->getContent(), true)['data']['data'];
|
||||
}
|
||||
|
||||
/** همان اندپوینت، اینبار با توکنِ صاحب کلینیک — جایی که شماره دیده میشود. */
|
||||
private function fetchClinicAsOwner(Clinic $clinic): array
|
||||
{
|
||||
$body = $this->authJson('GET', '/api/v1/clinic/' . $clinic->getUuid(), $clinic->getUser());
|
||||
$this->assertSame(200, $this->responseCode());
|
||||
|
||||
return $body['data']['data'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user