fix(Core): fix bug is lock

This commit is contained in:
2026-05-17 00:00:13 +03:30
parent 2796ce7de7
commit c3d798689c
8 changed files with 52 additions and 30 deletions

View File

@@ -26,6 +26,13 @@ class ArtController extends Controller
public function index(GetApiRequest $request)
{
$book = Book::find($request->book_id);
$law = Law::find($book?->law_id);
if ($this->isLockedForCurrentUser($law)) {
return $this->failed([], ['title' => 'Subscription Required', 'message' => 'This content requires an active subscription.'], 403);
}
$arts = Art::with(['chapter', 'part', 'volum', 'law', 'book', 'section', 'gate'])->where('book_id', $request->book_id)->orderBy('number')->get();
$arts = $arts->map(function ($art) {
@@ -84,6 +91,10 @@ class ArtController extends Controller
$law = Law::find($art?->law_id);
if ($this->isLockedForCurrentUser($law)) {
return $this->failed([], ['title' => 'Subscription Required', 'message' => 'This content requires an active subscription.'], 403);
}
$art->is_like = $this->isLiked($art->id);
$art->note = Note::select('id', 'note', 'color_code','created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get();
$art->category = $law?->category?->name;
@@ -152,16 +163,23 @@ class ArtController extends Controller
->exists();
}
private function isLockedForCurrentUser(?Law $law): bool
{
return !auth()->user()->isSubscriber() && (bool) $law?->is_locked;
}
public function likes()
{
$likes = LikeArt::query()->where('user_id', auth()->user()->id)
->with('art')
->with('art.law')
->get()
->map(function ($q) {
$isLocked = $this->isLockedForCurrentUser($q->art?->law);
return [
'id' => $q->art->id,
'title' => $q->art->title,
'text' => $q->art->text
'text' => $isLocked ? null : $q->art->text
];
});
@@ -257,12 +275,13 @@ class ArtController extends Controller
}
$law = Law::find($item->law_id);
$isLocked = $this->isLockedForCurrentUser($law);
return [
'id' => $item->id,
'title' => $item->title,
'text' => $context,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
'text' => $isLocked ? null : $context,
'is_locked' => $isLocked,
'type' => 'art',
'route' => array_values($this->route($modelClass, $item)),
'category' => optional($law->category)->name,
@@ -466,11 +485,13 @@ class ArtController extends Controller
$context = $text;
}
$isLocked = $this->isLockedForCurrentUser($law);
return [
'id' => $q->id,
'title' => $q->title,
'text' => $context,
'is_locked' => auth()->user()->isSubscriber() !== false ? false : $law->is_locked,
'text' => $isLocked ? null : $context,
'is_locked' => $isLocked,
'type' => 'art',
'route' => $route,
'category' => $law?->category?->name,