feat(subscription): return plan features for users without subscription permission
This commit is contained in:
@@ -53,23 +53,43 @@ class SubscriptionController extends BaseController
|
||||
|
||||
// ── Authenticated ────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* اشتراکِ محیط جاری — و برای کاربرِ بدونِ مجوزِ اشتراک، فقط **قابلیتهای** پلن.
|
||||
*
|
||||
* پنل بدون دانستنِ قابلیتهای پلن نمیتواند منو را درست بسازد: هر آیتمِ
|
||||
* feature-دار (پروندهٔ بیماران، بیمه) وقتی این فهرست نیاید «قفل» میشود و کاربر
|
||||
* را به صفحهٔ اشتراک میفرستد — حتی وقتی خودِ API آن قابلیت را به او میدهد.
|
||||
* پس ۴۰۳ اینجا به یک قفلِ دروغین در UI ترجمه میشد.
|
||||
*
|
||||
* افشای تازهای هم ندارد: `GET /subscription/plans` عمومی است و همین قابلیتها
|
||||
* (بهعلاوهٔ قیمتها) را برای همهٔ پلنها میدهد. چیزی که خصوصی میماند وضعیت و
|
||||
* تاریخِ اشتراکِ همین محیط و سابقهٔ دورهٔ آزمایشی است.
|
||||
*/
|
||||
#[Route('/api/v1/subscription/my', methods: ['GET'])]
|
||||
#[IsGranted('IS_AUTHENTICATED_FULLY')]
|
||||
public function my(#[CurrentUser] User $user): JsonResponse
|
||||
{
|
||||
$this->secretaryAccess->denyUnlessGranted($user, 'subscription', 'view');
|
||||
[$entityType, $entityId] = $this->resolveEntity($user);
|
||||
if ($entityId === null) {
|
||||
return $this->error(ErrorCodes::ERR_FORBIDDEN_001, 'پروفایل یافت نشد', 403);
|
||||
}
|
||||
|
||||
$subscription = $this->subscriptionService->getActiveSubscription($entityType, $entityId);
|
||||
$usedTrial = $this->subscriptionService->hasUsedTrial($entityType, $entityId);
|
||||
$effectivePlan = $this->subscriptionService->getEffectivePlan($entityType, $entityId);
|
||||
|
||||
if (!$this->secretaryAccess->canOrNonSecretary($user, 'subscription', 'view')) {
|
||||
return $this->success([
|
||||
'subscription' => null,
|
||||
'used_trial' => false,
|
||||
'effective_plan' => $effectivePlan === null ? null : [
|
||||
'features' => $effectivePlan->getFeatures(),
|
||||
'max_secretaries' => $effectivePlan->getMaxSecretaries(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'subscription' => $subscription?->toArray(),
|
||||
'used_trial' => $usedTrial,
|
||||
'subscription' => $this->subscriptionService->getActiveSubscription($entityType, $entityId)?->toArray(),
|
||||
'used_trial' => $this->subscriptionService->hasUsedTrial($entityType, $entityId),
|
||||
'effective_plan' => $effectivePlan?->toArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user