feat(quizzes): публичные ссылки по токену и флаг no_shuffle
- quizzes.public_token (VARCHAR 32, уникальный индекс) вместо числового id в публичных роутах /api/public-quizzes/:token - бэкилл токенов для существующих строк в db/migration.sql + ensureQuizTables - quiz_questions.no_shuffle — вопрос исключён из перемешивания - POST /api/quizzes/:id/public-token/rotate — сброс утёкшей ссылки (автор/админ) - restore: no_shuffle в INSERT quiz_questions, backup.selftest обновлён - документация AGENTS.md + handoff
This commit is contained in:
+27
-3
@@ -124,6 +124,7 @@
|
||||
required: q.required !== false,
|
||||
min_length: Number(q.min_length) || 0,
|
||||
options_inline: q.options_inline === true,
|
||||
no_shuffle: q.no_shuffle === true,
|
||||
text_match: q.text_match === 'contains' ? 'contains' : 'exact',
|
||||
accepted_answers: Array.isArray(q.accepted_answers) ? q.accepted_answers.slice() : [],
|
||||
assets: Array.isArray(q.assets) ? q.assets.slice() : [],
|
||||
@@ -169,6 +170,7 @@
|
||||
required: qq.required,
|
||||
min_length: qq.min_length,
|
||||
options_inline: qq.options_inline,
|
||||
no_shuffle: qq.no_shuffle,
|
||||
text_match: qq.text_match,
|
||||
accepted_answers: qq.accepted_answers,
|
||||
asset_ids: qq.assets.map(a => a.id),
|
||||
@@ -298,6 +300,7 @@
|
||||
${isTest && q.kind === 'multiple' ? `<label class="toggle" style="padding:2px 6px"><input type="checkbox" data-qi="${qi}" data-field="partial_credit"${q.partial_credit ? ' checked' : ''}><span class="toggle-track"><span class="toggle-thumb"></span></span><span class="toggle-text"><small>Частичный зачёт</small></span></label>` : ''}
|
||||
${isOptionKind(q.kind) && q.kind !== 'select' ? `<label class="toggle" style="padding:2px 6px"><input type="checkbox" data-qi="${qi}" data-field="options_inline"${q.options_inline ? ' checked' : ''}><span class="toggle-track"><span class="toggle-thumb"></span></span><span class="toggle-text"><small>Ответы в строку</small></span></label>` : ''}
|
||||
<label class="toggle" style="padding:2px 6px"><input type="checkbox" data-qi="${qi}" data-field="required"${q.required ? ' checked' : ''}><span class="toggle-track"><span class="toggle-thumb"></span></span><span class="toggle-text"><small>Обязательный</small></span></label>
|
||||
<label class="toggle" style="padding:2px 6px" title="Вопрос останется в начале списка и не будет перемешиваться"><input type="checkbox" data-qi="${qi}" data-field="no_shuffle"${q.no_shuffle ? ' checked' : ''}><span class="toggle-track"><span class="toggle-thumb"></span></span><span class="toggle-text"><small>Не перемешивать</small></span></label>
|
||||
${q.required && (q.kind === 'line' || q.kind === 'text') ? `<label class="qe-min-len">Мин. длина <input type="number" class="settings-input" data-qi="${qi}" data-field="min_length" min="0" max="2000" value="${at(q.min_length || 0)}"></label>` : ''}
|
||||
</div>
|
||||
<div class="qe-assets" data-assets="${owner}">${assetsHtml(q.assets, owner)}</div>
|
||||
@@ -363,7 +366,7 @@
|
||||
? 'По ссылке можно пройти тест без входа в систему. Перед началом ученик может указать имя; если оставить пустым, результат будет анонимным.'
|
||||
: 'По ссылке можно пройти опрос без входа в систему. Ответы сохраняются без имени.';
|
||||
}
|
||||
const ready = state.quiz.allow_anonymous && state.quiz.is_published;
|
||||
const ready = state.quiz.allow_anonymous && state.quiz.is_published && !!state.quiz.public_token;
|
||||
const visible = ready && !dirty;
|
||||
link.hidden = !visible;
|
||||
let text = '';
|
||||
@@ -372,12 +375,28 @@
|
||||
hint.hidden = !text;
|
||||
hint.textContent = text;
|
||||
if (visible) {
|
||||
const url = location.origin + '/quiz-public.html?id=' + state.quiz.id;
|
||||
const url = location.origin + '/quiz-public.html?t=' + encodeURIComponent(state.quiz.public_token);
|
||||
document.getElementById('qeAnonUrl').value = url;
|
||||
document.getElementById('qeAnonOpen').href = url;
|
||||
}
|
||||
}
|
||||
|
||||
async function rotatePublicLink() {
|
||||
if (!confirm('Обновить ссылку? Старая ссылка перестанет работать.')) return;
|
||||
const res = await fetch(API + '/api/quizzes/' + state.quiz.id + '/public-token/rotate', {
|
||||
method: 'POST',
|
||||
headers: hdr(),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
showToast(data.error || 'Не удалось обновить ссылку', true);
|
||||
return;
|
||||
}
|
||||
state.quiz.public_token = data.public_token;
|
||||
renderAnon();
|
||||
showToast('Ссылка обновлена');
|
||||
}
|
||||
|
||||
function renderGradeSelect() {
|
||||
const sel = document.getElementById('qeGradeScale');
|
||||
if (!sel) return;
|
||||
@@ -660,7 +679,7 @@
|
||||
const q = state.questions[qi];
|
||||
if (field === 'weight') q.weight = el.value === '' ? 0 : Number(el.value);
|
||||
else if (field === 'min_length') q.min_length = el.value === '' ? 0 : Math.max(0, Math.min(2000, Math.round(Number(el.value) || 0)));
|
||||
else if (field === 'partial_credit' || field === 'required' || field === 'options_inline') {
|
||||
else if (field === 'partial_credit' || field === 'required' || field === 'options_inline' || field === 'no_shuffle') {
|
||||
q[field] = el.checked;
|
||||
if (field === 'required' && (q.kind === 'line' || q.kind === 'text')) {
|
||||
markDirty();
|
||||
@@ -798,6 +817,10 @@
|
||||
deleteCover();
|
||||
return;
|
||||
}
|
||||
if (act === 'rotate-anon') {
|
||||
rotatePublicLink();
|
||||
return;
|
||||
}
|
||||
if (act === 'copy-anon') {
|
||||
const input = document.getElementById('qeAnonUrl');
|
||||
input.select();
|
||||
@@ -887,6 +910,7 @@
|
||||
required: true,
|
||||
min_length: 0,
|
||||
options_inline: false,
|
||||
no_shuffle: false,
|
||||
text_match: 'exact',
|
||||
accepted_answers: [],
|
||||
assets: [],
|
||||
|
||||
Reference in New Issue
Block a user