feat(sidebar): скрывать ссылки exam-prep при выключенном/недоступном треке

This commit is contained in:
Maxim Dolgolyov
2026-06-15 14:19:38 +03:00
parent 6fed18f819
commit 56fc15418e
+17
View File
@@ -885,6 +885,23 @@ async function hideDisabledFeatures() {
}
}
// Exam-prep track links (/exam-prep/<key>): показываем только включённые
// (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 = [