Skip to content

Commit a8044bb

Browse files
committed
reset cache on delete
1 parent fdef3b1 commit a8044bb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

adminforth/documentation/docs/tutorial/05-Plugins/10-i18n.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Sometimes you might want to have HTML in translations. You can use `v-html` dire
275275
v-html='$t("<span class=\"text-transparent bg-clip-text bg-gradient-to-r to-emerald-600 from-sky-400\">Apartments</span> Statistics.")'></h1>
276276
```
277277
278-
> 🪪 Please keep in mind that roles who have access to translations resource can make HTML injections, though anyway if you are using [Audit Log](/docs/tutorial/Plugins/AuditLog/) plugin you can track all changes in translations and understand who made them.
278+
> 🪪 Security alert. Please keep in mind that if you are using `v-html="$t(`, the roles who have access to translations resource can make HTML/XSS injections, though anyway if you are using [Audit Log](/docs/tutorial/Plugins/AuditLog/) plugin you can track all changes in translations and understand who made them.
279279

280280
### Pluralization
281281

adminforth/plugins/i18n/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@ export default class I18N extends AdminForthPlugin {
234234
return { ok: true };
235235
});
236236

237+
// add hook on delete of any translation to reset cache
238+
resourceConfig.hooks.delete.afterSave.push(async ({ record }: { record: any }): Promise<{ ok: boolean, error?: string }> => {
239+
for (const lang of this.options.supportedLanguages) {
240+
this.cache.clear(`${this.resourceConfig.resourceId}:frontend:${lang}`);
241+
this.cache.clear(`${this.resourceConfig.resourceId}:${record[this.options.categoryFieldName]}:${lang}:${record[this.enFieldName]}`);
242+
}
243+
this.updateUntranslatedMenuBadge();
244+
return { ok: true };
245+
});
246+
237247
if (this.options.completedFieldName) {
238248
// on show and list add a list hook which will add incomplete field to record if translation is missing for at least one language
239249
const addIncompleteField = (record: any) => {

0 commit comments

Comments
 (0)