diff --git a/js/api.js b/js/api.js index fc37a0d..dcd4534 100644 --- a/js/api.js +++ b/js/api.js @@ -885,6 +885,23 @@ async function hideDisabledFeatures() { } } + // Exam-prep track links (/exam-prep/): показываем только включённые + // (exam_tracks.enabled) и доступные пользователю треки. /api/exam-prep/tracks + // уже отдаёт enabled-треки, отфильтрованные по правам доступа. + const examLinks = document.querySelectorAll('[href^="/exam-prep/"]'); + if (examLinks.length) { + try { + const data = await apiFetch('/api/exam-prep/tracks'); + const allowed = new Set((data.tracks || []).map(t => t.exam_key)); + examLinks.forEach(el => { + const m = (el.getAttribute('href') || '').match(/^\/exam-prep\/([^/?#]+)/); + if (m && !allowed.has(m[1])) el.style.display = 'none'; + }); + const cur = window.location.pathname.match(/^\/exam-prep\/([^/?#]+)/); + if (cur && !allowed.has(cur[1])) window.location.href = '/dashboard.html'; + } catch { /* сеть/доступ недоступны — ссылки оставляем как есть */ } + } + // Student with no class — restrict to dashboard, homework, library, theory if (feats._no_class) { const classOnlyHrefs = [