Merge branch 'misc' into 'main'

Improvements

See merge request PronounsPage/PronounsPage!405
This commit is contained in:
Andrea Vos 2024-01-10 21:26:45 +00:00
commit 8725637b38
4 changed files with 42 additions and 5 deletions

View File

@ -5,7 +5,7 @@ SECRET=changeMeOnProd!
STATS_FILE=%projectdir%/stats.json STATS_FILE=%projectdir%/stats.json
MAILER_TRANSPORT=smtps://username:password@smtp.example.com/?pool=true MAILER_TRANSPORT=
MAILER_FROM=test@example.com MAILER_FROM=test@example.com
TWITTER_KEY= TWITTER_KEY=

View File

@ -39,7 +39,10 @@
<button class="btn btn-sm btn-outline-success" @click="acceptTranslationProposal(tp.id)">Accept</button> <button class="btn btn-sm btn-outline-success" @click="acceptTranslationProposal(tp.id)">Accept</button>
<button class="btn btn-sm btn-outline-danger" @click="rejectTranslationProposal(tp.id)">Reject</button> <button class="btn btn-sm btn-outline-danger" @click="rejectTranslationProposal(tp.id)">Reject</button>
</template> </template>
<span v-else class="badge bg-success text-white">Approved</span> <template v-else>
<span class="badge bg-success text-white">Approved</span>
<button class="btn btm-sm btn-outline-danger" @click="unapproveTranslationProposal(tp.id)">Unapprove</button>
</template>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -147,6 +150,14 @@ export default {
await this.$post(`/translations/reject-proposal`, {id}) await this.$post(`/translations/reject-proposal`, {id})
this.translationProposals = this.translationProposals.filter(tp => tp.id !== id); this.translationProposals = this.translationProposals.filter(tp => tp.id !== id);
}, },
async unapproveTranslationProposal(id) {
await this.$confirm('Do you want to unmark this translation proposal as approved?', 'danger');
await this.$post(`/translations/unapprove-proposal`, {id});
this.translationProposals = this.translationProposals.map(tp => {
if (tp.id === id) { tp.status = 0; }
return tp;
});
},
async markTranslationProposalsDone() { async markTranslationProposalsDone() {
await this.$confirm(`This will mark all approved translations as done and they'll disappear from here await this.$confirm(`This will mark all approved translations as done and they'll disappear from here
but they'll only actually show up on production if they are added to the <code>translations.suml</code> file but they'll only actually show up on production if they are added to the <code>translations.suml</code> file

View File

@ -25,7 +25,7 @@ router.post('/translations/propose', handleErrorAsync(async (req, res) => {
await req.db.get(SQL`INSERT INTO translations (id, locale, tKey, tValue, status, author_id) VALUES ( await req.db.get(SQL`INSERT INTO translations (id, locale, tKey, tValue, status, author_id) VALUES (
${ulid()}, ${global.config.locale}, ${ulid()}, ${global.config.locale},
${tKey}, ${JSON.stringify(req.body.changes[tKey])}, ${tKey}, ${JSON.stringify(req.body.changes[tKey])},
${req.isGranted('translations') ? TRANSLATION_STATUS.APPROVED : TRANSLATION_STATUS.AWAITING}, ${req.user.id} ${TRANSLATION_STATUS.AWAITING}, ${req.user.id}
)`); )`);
} }
@ -102,6 +102,21 @@ router.post('/translations/accept-proposal', handleErrorAsync(async (req, res) =
return res.json('OK'); return res.json('OK');
})); }));
router.post('/translations/unapprove-proposal', handleErrorAsync(async (req, res) => {
if (!req.isGranted('translations')) {
return res.status(401).json({error: 'Unauthorised'});
}
await req.db.get(SQL`UPDATE translations SET status = ${TRANSLATION_STATUS.AWAITING} WHERE id = ${req.body.id}`)
await auditLog(req, 'translations/unapproved', {
locale: global.config.locale,
id: req.body.id,
});
return res.json('OK');
}));
router.post('/translations/proposals-done', handleErrorAsync(async (req, res) => { router.post('/translations/proposals-done', handleErrorAsync(async (req, res) => {
if (!req.isGranted('translations')) { if (!req.isGranted('translations')) {

View File

@ -12,7 +12,11 @@ const loadSuml = name => new Suml().parse(fs.readFileSync(`${__dirname}/../${nam
const translations = loadSuml('data/translations'); const translations = loadSuml('data/translations');
const fallbackTranslations = loadSuml('locale/_base/translations'); const fallbackTranslations = loadSuml('locale/_base/translations');
const transporter = nodemailer.createTransport(process.env.MAILER_TRANSPORT, {from: process.env.MAILER_FROM}); let transport = process.env.MAILER_TRANSPORT;
if (!transport && process.env.NODE_ENV === 'development') {
transport = {streamTransport: true};
}
const transporter = nodemailer.createTransport(transport, {from: process.env.MAILER_FROM});
const sendEmail = (to, subject, text = undefined, html = undefined) => { const sendEmail = (to, subject, text = undefined, html = undefined) => {
transporter.sendMail({ transporter.sendMail({
@ -20,7 +24,14 @@ const sendEmail = (to, subject, text = undefined, html = undefined) => {
subject, subject,
text, text,
html, html,
}, function(err) { if (err) { console.error(err); } }) }, function(err, info) {
if (process.env.NODE_ENV === 'development' && info.message) {
info.message.pipe(process.stdout);
}
if (err) {
console.error(err);
}
})
}; };
const findTranslation = (key) => { const findTranslation = (key) => {