From fd02e25719b9de4aeabfe12b3f43e7448b43de94 Mon Sep 17 00:00:00 2001 From: Luka Romih Date: Mon, 23 Feb 2026 15:29:58 +0100 Subject: [PATCH] Another batch of important updates and fixes --- dev/.env | 2 +- express/config/settings.js | 2 +- express/controllers/api/v1/comments.js | 9 +++++ express/controllers/api/v1/consultancy.js | 21 ++++++++--- express/controllers/api/v1/dictionaries.js | 2 +- express/controllers/api/v1/extraction.js | 5 ++- express/controllers/api/v1/users.js | 13 +++++-- express/controllers/helpers/dictionary.js | 10 ++++-- express/controllers/index.js | 32 ++++++++++++----- express/controllers/users.js | 24 ++++++++++--- express/middleware/index.js | 9 +++++ express/middleware/user.js | 9 +++-- express/models/system/misc.js | 10 ++++++ express/models/user.js | 14 ++++++-- express/public/javascripts/comments.js | 35 ++++++++++--------- express/public/javascripts/dictionaries.js | 7 ++-- express/public/javascripts/scripts.js | 10 ++++++ express/public/locales/en/core.json | 1 - express/public/locales/sl/core.json | 1 - .../sass/login-signup/_login-signup.scss | 4 +++ express/routes/api/v1/comments.js | 2 ++ express/routes/api/v1/entries.js | 7 +++- express/scheduled/batch_update_linked.js | 9 +++-- .../components/login-signup/login-signup.pug | 12 +++++++ express/views/email/user-activation_en.pug | 2 +- express/views/email/user-activation_sl.pug | 2 +- express/views/pages/admin/areas.pug | 2 +- .../pages/admin/dictionary-description.pug | 2 +- .../pages/admin/dictionary-structure.pug | 2 +- .../views/pages/admin/dictionary-users.pug | 3 +- .../admin/portal-consultancy-settings.pug | 2 +- express/views/pages/admin/portal.pug | 2 +- .../pages/admin/settings-dictionaries.pug | 2 +- express/views/pages/admin/user-portals.pug | 2 +- .../views/pages/consultancy/admin/edit.pug | 2 +- .../views/pages/dictionaries/description.pug | 2 +- .../views/pages/dictionaries/structure.pug | 2 +- express/views/pages/dictionaries/users.pug | 3 +- .../dictionary-domain-labels-mixin.pug | 2 +- postgres/init/021_honeypot_log.sql | 5 +++ 40 files changed, 216 insertions(+), 71 deletions(-) create mode 100644 express/models/system/misc.js create mode 100644 postgres/init/021_honeypot_log.sql diff --git a/dev/.env b/dev/.env index 9246be4..9aa349a 100644 --- a/dev/.env +++ b/dev/.env @@ -13,7 +13,7 @@ PORTAL_ADMIN_INITIAL_PASSWORD="admin" # The endpoint where you've made Term Candidate Extraction API available. # It is required for the extraction module to work properly. -EXTRACTION_API_ORIGIN="http://rsdo.lhrs.feri.um.si:8080" +EXTRACTION_API_ORIGIN="https://rsdo.lhrs.si" # The main port, which will be exposed on localhost of the of host running the Docker Engine. diff --git a/express/config/settings.js b/express/config/settings.js index a530187..9c030bd 100644 --- a/express/config/settings.js +++ b/express/config/settings.js @@ -25,6 +25,6 @@ exports.TEMP_EXPORT_PATH = `${DATA_FILES_PATH}/export_temp` exports.MAX_EXTRACTIONS_PER_USER = 5 -exports.ACTIVATION_TOKEN_VALID_DAYS = 7 +exports.ACTIVATION_TOKEN_VALID_DAYS = 2 exports.CHANGE_EMAIL_TOKEN_VALID_DAYS = 7 diff --git a/express/controllers/api/v1/comments.js b/express/controllers/api/v1/comments.js index dd80ded..ee9fb94 100644 --- a/express/controllers/api/v1/comments.js +++ b/express/controllers/api/v1/comments.js @@ -12,6 +12,15 @@ exports.listComments = async (req, res) => { } if (filters.ctxType === 'entry_dict_int') { + if (!filters.ctxId) { + const NO_COMMENTS_OBJECT = { + page: 1, + numberOfAllPages: 1, + comments: [], + commentCount: 0 + } + return res.send(NO_COMMENTS_OBJECT) + } const { dictionary_id: dictionaryId } = await Entry.fetch(filters.ctxId) const isEditor = req.user.hasAnyDictionaryRole(dictionaryId) const isPortalAdmin = req.user.hasRole('portal admin') diff --git a/express/controllers/api/v1/consultancy.js b/express/controllers/api/v1/consultancy.js index b481358..5fefd4a 100644 --- a/express/controllers/api/v1/consultancy.js +++ b/express/controllers/api/v1/consultancy.js @@ -123,6 +123,8 @@ consultancy.createQuestion = async (req, res) => { subject: subjectText, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${emails} (subject: ${subjectText})`) res.status(201).send() } @@ -233,11 +235,14 @@ consultancy.assign = async (req, res) => { const emailHtml = await renderAsync('email/consultancy-assigned') // TODO i18n - What language are the email title and content (we already have email translated) + const emailSubject = req.t('Novo terminološko vprašanje') await email.send({ to: emails, - subject: req.t('Novo terminološko vprašanje'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${emails} (subject: ${emailSubject})`) res.send() } @@ -289,11 +294,14 @@ consultancy.sendToReview = async (req, res) => { const emailHtml = await renderAsync('email/consultancy-item-review') // TODO i18n - What language are the email title and content (we already have email translated) + const emailSubject = req.t('Potrditev objave') await email.send({ to: emails, - subject: req.t('Potrditev objave'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${emails} (subject: ${emailSubject})`) res.send() } @@ -318,13 +326,16 @@ consultancy.publish = async (req, res) => { portalName } ) + const emailSubject = i18next.t('Objava terminološkega vprašanja', { + lng: author.language + }) await email.send({ to: author.email, - subject: i18next.t('Objava terminološkega vprašanja', { - lng: author.language - }), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${author.email} (subject: ${emailSubject})`) await ConsultancyEntry.publish(questionId, answerAuthors) await ConsultancyEntry.indexIntoSearchEngine(questionId, true) diff --git a/express/controllers/api/v1/dictionaries.js b/express/controllers/api/v1/dictionaries.js index 3df6a31..1192e62 100644 --- a/express/controllers/api/v1/dictionaries.js +++ b/express/controllers/api/v1/dictionaries.js @@ -55,7 +55,7 @@ dictionary.updateEntry = async (req, res) => { } dictionary.fetchEntries = async (req, res) => { - const dictionaryId = req.query.id + const { dictionaryId } = req.query const hitsQuery = genEditorAllQuery(dictionaryId) const hits = await searchEntryIndex(hitsQuery) diff --git a/express/controllers/api/v1/extraction.js b/express/controllers/api/v1/extraction.js index b705363..3dc9a7b 100644 --- a/express/controllers/api/v1/extraction.js +++ b/express/controllers/api/v1/extraction.js @@ -218,11 +218,14 @@ extraction.begin = async (req, res) => { extractionLink } ) + const emailSubject = i18next.t('Luščenje končano', { lng: authorLanguage }) await email.send({ to: authorEmail, - subject: i18next.t('Luščenje končano', { lng: authorLanguage }), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${authorEmail} (subject: ${emailSubject})`) } catch (error) { // eslint-disable-next-line no-console console.error(error) diff --git a/express/controllers/api/v1/users.js b/express/controllers/api/v1/users.js index 6a26ebe..2f7b638 100644 --- a/express/controllers/api/v1/users.js +++ b/express/controllers/api/v1/users.js @@ -18,7 +18,8 @@ users.listUsers = async (req, res) => { const { pages_total: numberOfAllPages, results } = await User.fetchAll( resultsPerPage, - page + page, + true ) res.send({ page, numberOfAllPages, results }) @@ -63,11 +64,14 @@ users.updateBasicData = async (req, res) => { changeEmailLink } ) + const emailSubject = req.t('Sprememba elektronskega naslova') await email.send({ to: newEmail, - subject: req.t('Sprememba elektronskega naslova'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${newEmail} (subject: ${emailSubject})`) const message = req.t( @@ -103,11 +107,14 @@ users.updatePassword = async (req, res) => { username: req.user.userName } ) + const emailSubject = req.t('Sprememba gesla') await email.send({ to: req.user.email, - subject: req.t('Sprememba gesla'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${req.user.email} (subject: ${emailSubject})`) req.flash('info', 'Geslo je bilo spremenjeno.') res.send() diff --git a/express/controllers/helpers/dictionary.js b/express/controllers/helpers/dictionary.js index fc3c69a..aa9b555 100644 --- a/express/controllers/helpers/dictionary.js +++ b/express/controllers/helpers/dictionary.js @@ -76,11 +76,14 @@ exports.minEntriesRequirementCheckAndAct = { }) // TODO i18n - What language are the email title and content (we already have email translated) + const emailSubject = __('Obvestilo o številu gesel') await email.send({ to: allEmails, - subject: __('Obvestilo o številu gesel'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${allEmails} (subject: ${emailSubject})`) await minEntriesEmailBookmark.set(dictionaryId) }, @@ -207,9 +210,12 @@ async function renderAndSendStatusChangeEmails( }) // TODO i18n - What language are the email title and content (we already have email translated) + const emailSubject = __('Sprememba stanja slovarja') await email.send({ to: targetEmails, - subject: __('Sprememba stanja slovarja'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${targetEmails} (subject: ${emailSubject})`) } diff --git a/express/controllers/index.js b/express/controllers/index.js index c8a4471..b3ed712 100644 --- a/express/controllers/index.js +++ b/express/controllers/index.js @@ -442,18 +442,31 @@ exports.entryDetails = async (req, res) => { } /* entryData.entry.foreign_entries.forEach((val, idx) => { - entry.foreignEntries[idx] = await + entry.foreignEntries[idx] = await }) */ - const langs = await Dictionary.fetchLanguages( + const allowedLangauges = await Dictionary.fetchLanguages( entryData.dictionary_id, req.determinedLanguage ) - entryData.foreign_entries.forEach((val, idx) => { - try { - entry.foreign_entries[idx].name = langs[idx].name - } catch (e) {} - }) + const allowedLanguageIDs = allowedLangauges.reduce((agg, el, index) => { + agg[el.id] = el.name + + return agg + }, {}) + + if (entryData.foreign_entries) { + entryData.foreign_entries = entryData.foreign_entries.filter(item => { + return Object.keys(allowedLanguageIDs).includes(`${item.language_id}`) + }) + + entryData.foreign_entries.forEach((val, idx) => { + try { + entry.foreign_entries[idx].name = + allowedLanguageIDs[entry.foreign_entries[idx].language_id] + } catch (e) {} + }) + } res.render('pages/search/result-detail', { allPrimaryDomains, @@ -515,11 +528,14 @@ exports.changeEmail = async (req, res) => { username: user.username } ) + const emailSubject = req.t('Sprememba elektronskega naslova - uspeh') await email.send({ to: user.email, - subject: req.t('Sprememba elektronskega naslova - uspeh'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${user.email} (subject: ${emailSubject})`) req.flash('info', req.t('Uspešno ste spremenili svoj elektronski naslov.')) if (req.user) return res.redirect(303, '/moj-racun') diff --git a/express/controllers/users.js b/express/controllers/users.js index df9ad8f..7133166 100644 --- a/express/controllers/users.js +++ b/express/controllers/users.js @@ -2,6 +2,7 @@ const { randomBytes } = require('crypto') const { promisify } = require('util') const passport = require('passport') const User = require('../models/user') +const Misc = require('../models/system/misc') const email = require('../models/email') const { logout: logoutUser } = require('../middleware/user') const { origin } = require('../config/keys') @@ -14,6 +15,11 @@ const user = {} user.register = async (req, res) => { // TODO Add validation. + if (req.body.userTag) { + await Misc.logHoneypotCatch(req.body) + return res.send(req.t('Registracija uspešna')) + } + const userId = await User.create( { ...req.body, @@ -32,11 +38,14 @@ user.register = async (req, res) => { username, activationLink }) + const emailSubject = req.t('Aktivacija računa') await email.send({ to: userEmail, - subject: req.t('Aktivacija računa'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${userEmail} (subject: ${emailSubject})`) res.send(req.t('Registracija uspešna')) } @@ -136,11 +145,14 @@ user.generateResetPasswordToken = async (req, res) => { resetPasswordLink } ) + const emailSubject = req.t('Ponastavitev gesla') await email.send({ to: userEmail, - subject: req.t('Ponastavitev gesla'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${userEmail} (subject: ${emailSubject})`) res.send() } @@ -162,11 +174,14 @@ user.changePassword = async (req, res) => { username: user.username } ) + const emailSubject = req.t('Uspešna ponastavitev gesla') await email.send({ to: user.email, - subject: req.t('Uspešna ponastavitev gesla'), + subject: emailSubject, html: emailHtml }) + // eslint-disable-next-line no-console + console.log(`Sent email to ${user.email} (subject: ${emailSubject})`) req.flash('info', req.t('Vaše geslo je bilo uspešno ponastavljeno.')) @@ -186,7 +201,8 @@ user.list = async (req, res) => { const { pages_total: numberOfAllPages, results } = await User.fetchAll( resultsPerPage, - 1 + 1, + true ) res.render('pages/admin/user-list', { title: req.t('Seznam uporabnikov'), diff --git a/express/middleware/index.js b/express/middleware/index.js index 284f348..a35552b 100644 --- a/express/middleware/index.js +++ b/express/middleware/index.js @@ -1,4 +1,5 @@ const { getInstanceSetting } = require('../models/helpers') +const Entry = require('../models/entry') exports.enhanceLocals = async (req, res, next) => { res.locals.portalCode = await getInstanceSetting('portal_code') @@ -12,3 +13,11 @@ exports.adjustHeaders = async (req, res, next) => { next() } + +exports.setDerivedDictionaryIdFromEntryId = async (req, res, next) => { + const { entryId } = req.query + const { dictionary_id: dictionaryId } = await Entry.fetch(entryId) + req.derivedDictionaryId = dictionaryId + + next() +} diff --git a/express/middleware/user.js b/express/middleware/user.js index 19ae856..aab882e 100644 --- a/express/middleware/user.js +++ b/express/middleware/user.js @@ -53,7 +53,8 @@ user.isDictionaryEditor = (req, res, next) => { } user.canAdministrateDictionary = (req, res, next) => { - const dictionaryId = req.params.dictionaryId || req.dictionaryId + const dictionaryId = + req.params.dictionaryId || req.query.dictionaryId || req.dictionaryId const isAdmin = req.user.hasDictionaryRole(dictionaryId, 'administration') const isPortalAdmin = req.user.hasRole('portal admin') const isDictionariesAdmin = req.user.hasRole('dictionaries admin') @@ -73,7 +74,11 @@ user.canAdministrateDictionaries = (req, res, next) => { } user.canContentEdit = (req, res, next) => { - const { dictionaryId } = req.params + const dictionaryId = + req.params.dictionaryId || + req.query.dictionaryId || + req.body.dictionaryId || + req.derivedDictionaryId const isEditor = req.user.hasAnyDictionaryRole(dictionaryId) const isPortalAdmin = req.user.hasRole('portal admin') const isDictionariesAdmin = req.user.hasRole('dictionaries admin') diff --git a/express/models/system/misc.js b/express/models/system/misc.js new file mode 100644 index 0000000..3ebd1dd --- /dev/null +++ b/express/models/system/misc.js @@ -0,0 +1,10 @@ +const db = require('../db') + +const Misc = {} + +// Log a successful honeypot catch. +Misc.logHoneypotCatch = async body => { + await db.query('INSERT INTO honeypot_log (body_content) VALUES ($1)', [body]) +} + +module.exports = Misc diff --git a/express/models/user.js b/express/models/user.js index a7c1ec3..bd23b2c 100644 --- a/express/models/user.js +++ b/express/models/user.js @@ -330,7 +330,15 @@ User.fetchDeserializedDataById = async userId => { } // Fetch all registered users on the portal -User.fetchAll = async (resultsPerPage, page) => { +User.fetchAll = async (resultsPerPage, page, hideInactive) => { + // hideInactive was added to hide bot spammed accounts. Using the 'inactive' status might be more appropriate as a filtering criteria in the future. + + const whereClause = `WHERE status ${ + hideInactive + ? `= 'active' OR (status = 'registered' AND NOW() - time_registered < '${ACTIVATION_TOKEN_VALID_DAYS} days')` + : "<> 'closed'" + }` + const { rows: [{ result }] } = await db.query( @@ -339,7 +347,7 @@ User.fetchAll = async (resultsPerPage, page) => { 'pages_total', ( SELECT CEIL(COUNT(*) / $1::float) FROM "user" - WHERE status <> 'closed' + ${whereClause} ), 'results', ARRAY( SELECT jsonb_build_object( @@ -349,7 +357,7 @@ User.fetchAll = async (resultsPerPage, page) => { 'status', status ) FROM "user" - WHERE status <> 'closed' + ${whereClause} ORDER BY username LIMIT $1 OFFSET $2 diff --git a/express/public/javascripts/comments.js b/express/public/javascripts/comments.js index 8c8c33c..031cd9e 100644 --- a/express/public/javascripts/comments.js +++ b/express/public/javascripts/comments.js @@ -9,8 +9,8 @@ window.addEventListener('load', () => { function initComments() { const ce = {} - ce.updatePager = initPagination('pagination', onPageChange) window.commentElements = ce + ce.updatePager = initPagination('pagination', onPageChange) ce.commentsCountEl = document.getElementById('comments-count') ce.commentsContainerEl = document.getElementById('comments-container') ce.commentForm = document.getElementById('comment-form') @@ -58,16 +58,20 @@ function initComments() { if (/\/slovarji\/\d+\/vsebina/.test(pageURL)) { ce.terminsList = document.getElementById('term-list') if (ce.terminsList) { - ce.terminsList.addEventListener('click', displayComments) + ce.terminsList.addEventListener('click', () => + changeEntryCommentSection() + ) } const ctxBtns = document.getElementsByName('comments-type') if (ctxBtns) { const ctxBtnsArray = Array.from(ctxBtns) - ctxBtnsArray.forEach(el => el.addEventListener('click', displayComments)) + ctxBtnsArray.forEach(el => + el.addEventListener('click', () => changeEntryCommentSection()) + ) } } ce.commentMessageInput && ce.commentReplyInput && clearMessageInput() - displayComments() + changeEntryCommentSection() } function autoGrow({ target: inputToResize }) { @@ -496,24 +500,16 @@ function normalCommentColors(selectedText, btnEyeOffEl) { selectedText.classList.remove('comment-white-text') } -// function getCtxId({ target }) { -// console.log(target) -// const termBtn = target.closest('.terms-label') -// console.log(termBtn) -// if (termBtn) { -// console.log(termBtn) -// displayComments() -// } -// } - const ctxBtns = document.getElementsByName('comments-type') const commentsTab = document.getElementById('content-comments') if (ctxBtns) { const ctxBtnsArray = Array.from(ctxBtns) - ctxBtnsArray.forEach(el => el.addEventListener('click', displayComments)) + ctxBtnsArray.forEach(el => + el.addEventListener('click', () => changeEntryCommentSection()) + ) } if (commentsTab) { - commentsTab.addEventListener('click', displayComments) + commentsTab.addEventListener('click', () => changeEntryCommentSection()) } function getCtxTypeId(type) { @@ -572,10 +568,15 @@ function checkButton(type) { return checked } +async function changeEntryCommentSection() { + await onPageChange() +} + async function onPageChange(newPage) { const { updatePager } = window.commentElements try { - const { page, numberOfAllPages } = await displayComments(newPage) + let { page, numberOfAllPages } = await displayComments(newPage) + numberOfAllPages ||= 1 updatePager(page, numberOfAllPages) } catch (error) { let message = i18next.t('Prišlo je do napake.') diff --git a/express/public/javascripts/dictionaries.js b/express/public/javascripts/dictionaries.js index 7614783..61aecb5 100644 --- a/express/public/javascripts/dictionaries.js +++ b/express/public/javascripts/dictionaries.js @@ -544,6 +544,7 @@ function initDictionaries() { } function handleClick({ target }) { + // TODO Fix leaks and related server request spam. Many click action create a new object or attach a new event listener on every click. const term = target.closest('.terms-label') const versionEl = target.closest('.date-element') const deleteEntryEl = target.closest('#delete-entry') @@ -652,11 +653,11 @@ function initDictionaries() { } = window.dictionaryElements event?.preventDefault() const dictionaryIdElem = document.getElementById('hidden-dictionary-id') - const dictctionaryId = dictionaryIdElem.value + const dictionaryId = dictionaryIdElem.value const deleteEntry = document.getElementById('delete-entry') try { const { data } = await axios.get('/api/v1/entries', { - params: { id: entryId, dictctionaryId: dictctionaryId } + params: { id: entryId, dictionaryId } }) insertTermData(entryId, data) const isPublishedEl = data.entry.is_published @@ -947,7 +948,7 @@ function initDictionaries() { const dictionaryId = hiddenEl.value try { const { data } = await axios.get('/api/v1/entries/fetch-terms', { - params: { id: dictionaryId } + params: { dictionaryId } }) renderTerms(data, entryId) } catch (error) { diff --git a/express/public/javascripts/scripts.js b/express/public/javascripts/scripts.js index 06b3e53..41e467d 100644 --- a/express/public/javascripts/scripts.js +++ b/express/public/javascripts/scripts.js @@ -677,11 +677,21 @@ function initPagination(paginationRootElIds, onPageChange, currentPage = 1) { function initControls(paginationRootElId) { const rootEl = document.getElementById(paginationRootElId) + + if (!rootEl) { + return + } + const btnFirstPage = rootEl.querySelector('.first-page') const btnPreviousPage = rootEl.querySelector('.previous-page') const btnNextPage = rootEl.querySelector('.next-page') const btnLastPage = rootEl.querySelector('.last-page') const formEl = rootEl.querySelector('form') + + if (!formEl) { + return + } + const pageInputEl = formEl.querySelector('input') const pagesCountDisplayEl = formEl.querySelector('.pages-total') diff --git a/express/public/locales/en/core.json b/express/public/locales/en/core.json index 1457a78..f1b2671 100644 --- a/express/public/locales/en/core.json +++ b/express/public/locales/en/core.json @@ -118,7 +118,6 @@ "ID Slovarja": "Dictionary ID", "ID: Ni idja": "ID: No ID", "IDEKSIRAJ": "INDEX", - "Imate neshranjene spremebe. Ali jih želite shraniti?": "Your changes have not been saved. Do you want to save them?", "Imate neshranjene spremembe. Ali jih želite shraniti?": "Your changes have not been saved. Do you want to save them?", "Ime": "First name", "IME": "FIRST NAME", diff --git a/express/public/locales/sl/core.json b/express/public/locales/sl/core.json index 878e8fc..7cb3ad1 100644 --- a/express/public/locales/sl/core.json +++ b/express/public/locales/sl/core.json @@ -118,7 +118,6 @@ "ID Slovarja": "ID Slovarja", "ID: Ni idja": "ID: Ni idja", "IDEKSIRAJ": "IDEKSIRAJ", - "Imate neshranjene spremebe. Ali jih želite shraniti?": "Imate neshranjene spremebe. Ali jih želite shraniti?", "Imate neshranjene spremembe. Ali jih želite shraniti?": "Imate neshranjene spremembe. Ali jih želite shraniti?", "Ime": "Ime", "IME": "IME", diff --git a/express/public/sass/login-signup/_login-signup.scss b/express/public/sass/login-signup/_login-signup.scss index 714829f..f44c297 100644 --- a/express/public/sass/login-signup/_login-signup.scss +++ b/express/public/sass/login-signup/_login-signup.scss @@ -158,6 +158,10 @@ form#register-form { input { border: none; } + + &.pt-6 { + display: none; + } } } diff --git a/express/routes/api/v1/comments.js b/express/routes/api/v1/comments.js index 8fe7134..39fe413 100644 --- a/express/routes/api/v1/comments.js +++ b/express/routes/api/v1/comments.js @@ -6,6 +6,8 @@ const { updateStatus } = require('../../../controllers/api/v1/comments') +// TODO Add correct authorization for different contexts. + // List comments (one page). router.get('/', listComments) diff --git a/express/routes/api/v1/entries.js b/express/routes/api/v1/entries.js index 3be2612..7fd1b4e 100644 --- a/express/routes/api/v1/entries.js +++ b/express/routes/api/v1/entries.js @@ -1,6 +1,9 @@ // This page refers to dictionary entries, not consultancy or other entries const router = require('express-promise-router')() const user = require('../../../middleware/user') +const { + setDerivedDictionaryIdFromEntryId +} = require('../../../middleware/index') const { getEntry, @@ -12,7 +15,9 @@ const { } = require('../../../controllers/api/v1/dictionaries') // All further routes are only available to authenticated users with dictionary content editing rights. -router.use(user.isAuthenticated, user.canContentEdit) +router.use(user.isAuthenticated) +router.use('/delete-entry', setDerivedDictionaryIdFromEntryId) +router.use(user.canContentEdit) // Render entry data for the selected entry router.get('/', getEntry) diff --git a/express/scheduled/batch_update_linked.js b/express/scheduled/batch_update_linked.js index 4a1c871..1179c96 100644 --- a/express/scheduled/batch_update_linked.js +++ b/express/scheduled/batch_update_linked.js @@ -196,7 +196,12 @@ function updateDictionaries(done) { ) }, function (cbwd) { - fetchUpdates(ldict, errd => { + fetchUpdates(ldict, (errd, body) => { + if (body && body.error) + console.error( + 'skipping dictionary update due to ', + body.error + ) cbwd(errd) }) }, @@ -304,7 +309,7 @@ function fetchUpdates(ldict, done) { if (error) return done(error) if (body.error) { // server side error message - return done(body) + return done(null, body) } // the body will contain decoded JSON array of dictionary items to update if (Array.isArray(body)) { diff --git a/express/views/components/login-signup/login-signup.pug b/express/views/components/login-signup/login-signup.pug index 2c41894..d73bdc0 100644 --- a/express/views/components/login-signup/login-signup.pug +++ b/express/views/components/login-signup/login-signup.pug @@ -182,6 +182,18 @@ .row.pt-1 .col.pe-0 p#error-password-repeat.mb-0.repeat.error-text.text-end= t('Geslo se ne ujema') + //- Honeypot. Hidden by css selector form#register-form .row.pt-6. + .row.pt-6 + .col-2.d-flex.align-items-center.justify-content-center.pe-4 + img(src="/images/user.svg" alt="") + .col-8.input-floor.ps-0 + label.loginregisterlabel(for="register-user-tag") OZNAKA + input#register-user-tag.w-100.input-lr(name="userTag") + .col-2.input-floor.d-flex.justify-content-end.pe-0 + img.error-icon.error-user-tag.align-self-end.d-flex( + src="/images/x_red.svg" + alt="X" + ) .row.mt-1.pt-0 .col-2.d-flex.align-items-center.justify-content-center.pe-4 .col-8.ps-0 diff --git a/express/views/email/user-activation_en.pug b/express/views/email/user-activation_en.pug index 804b396..3c7e74a 100644 --- a/express/views/email/user-activation_en.pug +++ b/express/views/email/user-activation_en.pug @@ -1,4 +1,4 @@ p Dear #{ username }, p You have received this massage because a new user account has been created on the Slovenian Terminology Portal using this e-mail address. -p To activate your account, you must confirm that this is the correct e-mail address. The link will be active for 7 days. +p To activate your account, you must confirm that this is the correct e-mail address. The link will be active for 2 days. a(href=activationLink) I confirm my e-mail address. diff --git a/express/views/email/user-activation_sl.pug b/express/views/email/user-activation_sl.pug index 4bd37dc..f7d281c 100644 --- a/express/views/email/user-activation_sl.pug +++ b/express/views/email/user-activation_sl.pug @@ -1,4 +1,4 @@ p Pozdravljeni #{ username }, p to sporočilo ste prejeli, ker ste na Slovenskem terminološkem portalu registrirali nov uporabniški račun s tem elektronskim naslovom. -p Za uporabo računa potrebujete le še potrditi, da je to res vaš elektronski naslov. Povezava je veljavna 7 dni. +p Za uporabo računa potrebujete le še potrditi, da je to res vaš elektronski naslov. Povezava je veljavna 2 dni. a(href=activationLink) Potrjujem svoj naslov diff --git a/express/views/pages/admin/areas.pug b/express/views/pages/admin/areas.pug index 9a947df..9e9f829 100644 --- a/express/views/pages/admin/areas.pug +++ b/express/views/pages/admin/areas.pug @@ -82,4 +82,4 @@ block body include /utilities/modal-alert include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/admin/dictionary-description.pug b/express/views/pages/admin/dictionary-description.pug index a433b6a..4e2f4ca 100644 --- a/express/views/pages/admin/dictionary-description.pug +++ b/express/views/pages/admin/dictionary-description.pug @@ -18,4 +18,4 @@ block body +dictionary-description(dictionary.id) include /utilities/modal-alert include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/admin/dictionary-structure.pug b/express/views/pages/admin/dictionary-structure.pug index cde2c40..f4fdd36 100644 --- a/express/views/pages/admin/dictionary-structure.pug +++ b/express/views/pages/admin/dictionary-structure.pug @@ -20,4 +20,4 @@ block body include /utilities/dictionary-structure-input include /common/footer include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/admin/dictionary-users.pug b/express/views/pages/admin/dictionary-users.pug index 95bab20..dc26079 100644 --- a/express/views/pages/admin/dictionary-users.pug +++ b/express/views/pages/admin/dictionary-users.pug @@ -210,6 +210,7 @@ block body span.new-user-info= t('NOV UPORABNIK') .row.d-flex.justify-content-lg-start.align-items-center.mt-2.ms-0.ps-0 .col-lg-6.ms-0.ps-0.me-2 + input(type="hidden" name="dictionaryId" value=dictionary.id) input.name-input.d-inline.form-control.ms-0.ps-0( type="text" name="userNameEmail" @@ -279,4 +280,4 @@ block body include /utilities/modal-response +responseModal include /utilities/modal-alert-mixin - +alertModal('unsaved-data', 'Shrani', 'Ne', 'modal-save-btn', 'modal-dont-save-btn', 'Imate neshranjene spremebe. Ali jih želite shraniti?') + +alertModal('unsaved-data', 'Shrani', 'Ne', 'modal-save-btn', 'modal-dont-save-btn', 'Imate neshranjene spremembe. Ali jih želite shraniti?') diff --git a/express/views/pages/admin/portal-consultancy-settings.pug b/express/views/pages/admin/portal-consultancy-settings.pug index 624090a..495618d 100644 --- a/express/views/pages/admin/portal-consultancy-settings.pug +++ b/express/views/pages/admin/portal-consultancy-settings.pug @@ -78,4 +78,4 @@ block body span.d-md-inline.d-block.smaller-gray-info.ms-xxl-3.ms-md-3= t('Vnesite naslov spletnega mesta, kjer so zbrani vsi odgovori terminološke svetovalnice.') include /common/footer include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/admin/portal.pug b/express/views/pages/admin/portal.pug index 73b5d1c..be24b0c 100644 --- a/express/views/pages/admin/portal.pug +++ b/express/views/pages/admin/portal.pug @@ -137,4 +137,4 @@ block body span.d-md-inline.d-block.smaller-gray-info= t('Modul za svetovanje pri terminoloških zagatah.') include /common/footer include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/admin/settings-dictionaries.pug b/express/views/pages/admin/settings-dictionaries.pug index ccae398..9f43295 100644 --- a/express/views/pages/admin/settings-dictionaries.pug +++ b/express/views/pages/admin/settings-dictionaries.pug @@ -107,4 +107,4 @@ block body span.d-md-inline.d-block.smaller-gray-info.ms-md-2= t('Poleg objave slovarskega sestavka v fazi "Urejeno" je omogočena tudi objava v fazi "V urejanju".') include /common/footer include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/admin/user-portals.pug b/express/views/pages/admin/user-portals.pug index 163485e..607edf9 100644 --- a/express/views/pages/admin/user-portals.pug +++ b/express/views/pages/admin/user-portals.pug @@ -111,4 +111,4 @@ block body include /utilities/modal-response +responseModal include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/consultancy/admin/edit.pug b/express/views/pages/consultancy/admin/edit.pug index 8845e87..95397ca 100644 --- a/express/views/pages/consultancy/admin/edit.pug +++ b/express/views/pages/consultancy/admin/edit.pug @@ -146,4 +146,4 @@ block body #offset-main.ps-2.pe-2 p #{ t('Nimate ustreznih pravic') } include /utilities/modal-alert-mixin - +alertModal('unsaved-data', 'Shrani', 'Ne', 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', 'Shrani', 'Ne', 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/dictionaries/description.pug b/express/views/pages/dictionaries/description.pug index 3f390dc..8f82357 100644 --- a/express/views/pages/dictionaries/description.pug +++ b/express/views/pages/dictionaries/description.pug @@ -18,4 +18,4 @@ block body +dictionary-description include /utilities/modal-alert include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/dictionaries/structure.pug b/express/views/pages/dictionaries/structure.pug index a4fa2ed..ff6ff13 100644 --- a/express/views/pages/dictionaries/structure.pug +++ b/express/views/pages/dictionaries/structure.pug @@ -20,4 +20,4 @@ block body include /utilities/dictionary-structure-input include /common/footer include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/pages/dictionaries/users.pug b/express/views/pages/dictionaries/users.pug index b20bca1..e8657fd 100644 --- a/express/views/pages/dictionaries/users.pug +++ b/express/views/pages/dictionaries/users.pug @@ -210,6 +210,7 @@ block body span.new-user-info= t('NOV UPORABNIK') .row.d-flex.justify-content-lg-start.align-items-center.mt-2.ms-0.ps-0 .col-lg-6.ms-0.ps-0.me-2 + input(type="hidden" name="dictionaryId" value=dictionary.id) input.name-input.d-inline.form-control.ms-0.ps-0( type="text" name="userNameEmail" @@ -279,4 +280,4 @@ block body include /utilities/modal-response +responseModal include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/express/views/utilities/dictionary-domain-labels-mixin.pug b/express/views/utilities/dictionary-domain-labels-mixin.pug index afd9928..8d17a6c 100644 --- a/express/views/utilities/dictionary-domain-labels-mixin.pug +++ b/express/views/utilities/dictionary-domain-labels-mixin.pug @@ -89,4 +89,4 @@ mixin dictionary-domain-labels include /common/footer include /utilities/modal-alert include /utilities/modal-alert-mixin - +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremebe. Ali jih želite shraniti?')) + +alertModal('unsaved-data', t('Shrani'), t('Ne'), 'modal-save-btn', 'modal-dont-save-btn', t('Imate neshranjene spremembe. Ali jih želite shraniti?')) diff --git a/postgres/init/021_honeypot_log.sql b/postgres/init/021_honeypot_log.sql new file mode 100644 index 0000000..51c35a9 --- /dev/null +++ b/postgres/init/021_honeypot_log.sql @@ -0,0 +1,5 @@ +CREATE TABLE honeypot_log ( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + time_created TIMESTAMPTZ NOT NULL DEFAULT NOW(), + body_content JSONB +);