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:
@@ -725,7 +725,7 @@ class AppointmentController extends BaseController
|
||||
return $this->error(ErrorCodes::ERR_ACCESS_DENIED, 'دسترسی ممنوع', 403);
|
||||
}
|
||||
|
||||
$payload = $appointment->toArray();
|
||||
$payload = $this->appointmentWithVenue($appointment);
|
||||
|
||||
/**
|
||||
* نوبتِ سرویسیِ کلینیک `service_section_id` را روی خودِ نوبت نمینویسد؛ فقط
|
||||
@@ -893,13 +893,49 @@ class AppointmentController extends BaseController
|
||||
// `toArray()` هم داخل محدوده است: proxyهای پزشک و کلینیک آنجا باز میشوند و
|
||||
// با فیلترِ برگشته، Doctrine `EntityNotFoundException` میدهد.
|
||||
$rows = $this->tenantScope->withoutFilter(fn () => array_map(
|
||||
fn(Appointment $a) => $a->toArray(),
|
||||
fn(Appointment $a) => $this->appointmentWithVenue($a),
|
||||
$this->appointmentRepo->findByUser($user, $status),
|
||||
));
|
||||
|
||||
return $this->success(['data' => $rows]);
|
||||
}
|
||||
|
||||
/**
|
||||
* نوبت بههمراه نشانیِ واقعیِ همان نوبت — با شمارهٔ تماس.
|
||||
*
|
||||
* `Appointment::toArray()` نشانی را از «اولین آدرسِ پزشک» برمیداشت، پس بیماری که
|
||||
* نوبتش در کلینیک یا در شعبهٔ دوم بود، نشانیِ مطبِ شخصیِ پزشک را میدید. آدرسِ درست
|
||||
* روی خودِ نوبت ثبت شده (`address_id`) و همانجا برای مطب و کلینیک یکسان کار میکند.
|
||||
*
|
||||
* شماره هم اینجا برمیگردد و نه در پاسخهای عمومی: مخاطبِ این متد یا صاحب نوبت است
|
||||
* یا کسی که `canView()` تأییدش کرده. اگر خودِ آدرس شماره نداشته باشد، شمارهٔ کلینیکِ
|
||||
* همان نوبت جایش مینشیند تا بیمار بیراهارتباطی نماند.
|
||||
*/
|
||||
private function appointmentWithVenue(Appointment $appointment): array
|
||||
{
|
||||
$payload = $appointment->toArray();
|
||||
|
||||
$addressId = $appointment->getAddressId();
|
||||
$address = $addressId !== null ? $this->addressRepo->find($addressId) : null;
|
||||
|
||||
if ($address !== null) {
|
||||
$payload['address'] = $address->toArray(null, true);
|
||||
} elseif ($payload['address'] !== null) {
|
||||
// نوبتهای قدیمی `address_id` ندارند؛ همان آدرسِ حدسیِ toArray() میماند،
|
||||
// ولی دستکم بدون شمارهٔ اشتباه نمایش داده نمیشود.
|
||||
$payload['address']['telephone'] = null;
|
||||
}
|
||||
|
||||
if (($payload['address']['telephone'] ?? null) === null && $payload['address'] !== null) {
|
||||
$clinic = $appointment->getClinic();
|
||||
if ($clinic !== null) {
|
||||
$payload['address']['telephone'] = $clinic->getTelephone();
|
||||
}
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
private function canView(Appointment $a, User $user): bool
|
||||
{
|
||||
return $this->accessChecker->canView($a, $user);
|
||||
|
||||
Reference in New Issue
Block a user