Files
wekan/server/models/translation.js
T
Lauri Ojansivu 828fc2d718 Revert Legacy HTML4 browser interface and parity changes
Remove the progressive HTML4/Legacy Omi middleware, cookieless sessions, page controllers, assets, parity refactors, design documents and associated tests. Restore the standard Meteor interface and operations from before the HTML4 work began.

Preserve intervening translations, backup screenshots, session upgrades, cryptographic test identifiers, local image storage, document previews and lazy browser loading. Extract the GIF utilities still required by image features into imageGif.

Validate the Node suites and add standard-interface and GIF regressions. Two existing failures remain in docsLinksResolve and ruleDetailsLocalization; browser regressions are registered but require a running server.

Thanks to xet7 !
2026-09-07 17:03:59 +03:00

70 lines
2.3 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import Translation from '/models/translation';
import { safeSelector } from '/server/lib/selectorGuard';
import { ensureIndex } from '/server/lib/mongoStartup';
const getReactiveCache = () => require('/imports/reactiveCache').ReactiveCache;
Meteor.methods({
async setCreateTranslation(language, text, translationText) {
check(language, String);
check(text, String);
check(translationText, String);
if (!(await getReactiveCache().getCurrentUser())?.isAdmin) {
throw new Meteor.Error('not-authorized');
}
const nTexts = (await getReactiveCache().getTranslations({ language, text })).length;
if (nTexts > 0) {
throw new Meteor.Error('text-already-taken');
}
await Translation.insertAsync({
language,
text,
translationText,
});
},
async setTranslationText(translation, translationText) {
check(translation, Object);
check(translationText, String);
if (!(await getReactiveCache().getCurrentUser())?.isAdmin) {
throw new Meteor.Error('not-authorized');
}
await Translation.updateAsync(translation, {
$set: { translationText },
});
},
async deleteTranslation(translationId) {
check(translationId, String);
if (!(await getReactiveCache().getCurrentUser())?.isAdmin) {
throw new Meteor.Error('not-authorized');
}
await Translation.removeAsync(translationId);
},
// The total behind the "page X / N" counter of the Translation table page
// (docs/Features/Page/Table.md). It counts the whole result set - the page itself
// only ever holds 25 rows - so it is a separate call, made when the pane opens
// and when the search changes, never on a prev/next click.
async getTranslationsCollectionCount(query = {}) {
check(query, Match.OneOf(Object, null, undefined));
if (!(await getReactiveCache().getCurrentUser())?.isAdmin) {
throw new Meteor.Error('not-authorized');
}
const cursor = await getReactiveCache().getTranslations(safeSelector(query || {}, 'getTranslationsCollectionCount'), {}, true);
return typeof cursor.countAsync === 'function' ? await cursor.countAsync() : cursor.count();
},
});
Meteor.startup(async () => {
await ensureIndex(Translation, { modifiedAt: -1 });
});