Skip to content

Commit c9872d8

Browse files
authored
feat: French translations, prevention of opening SVG directly in browser through canonical url (#1430)
* Fix #1377 * feat: expand images in `<img>` tag to avoid javascript attacks * Embed in img tags svg only * Remove canonical url display from directory listing for svg * Add test * Remove unused Media class * Change function of canonical url button * Remove superflous `} ` * Update NL locale * Fix: Right click "open in new tab" on canonical url now renders svg in img tag * Add zoom functionality for expanded svg images * Fix test and js lint * More js linting fixes * Allow ES6 * Update French translations * Fix css map * Update filer/templates/admin/filer/image/expand.html * Fix zoom cursors when displaying svg * ... second part
1 parent 68c3a5c commit c9872d8

File tree

9 files changed

+94
-115
lines changed

9 files changed

+94
-115
lines changed
1.16 KB
Binary file not shown.

filer/locale/fr/LC_MESSAGES/django.po

Lines changed: 54 additions & 101 deletions
Large diffs are not rendered by default.

filer/private/sass/components/_tooltip.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
box-shadow: 0 0 10px rgba(black,.25);
1818
border-radius: 5px;
1919
z-index: 10;
20+
cursor: default;
2021
&:before {
2122
position: absolute;
2223
top: -3px;

filer/static/filer/css/admin_filer.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

filer/static/filer/css/maps/admin_filer.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

filer/static/filer/js/base.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// #####################################################################################################################
22
// #BASE#
33
// Basic logic django filer
4+
/*jshint esversion: 6 */
45
'use strict';
56

67
var Cl = window.Cl || {};
@@ -265,18 +266,20 @@ Cl.mediator = new Mediator();
265266
});
266267
})();
267268
$('.js-copy-url').on('click', function (e) {
269+
const url = new URL(this.dataset.url, document.location.href);
270+
const msg = this.dataset.msg || 'URL copied to clipboard';
271+
let infobox = document.createElement('template');
268272
e.preventDefault();
269-
for(var el of document.getElementsByClassName('info filer-tooltip')) {
273+
for (let el of document.getElementsByClassName('info filer-tooltip')) {
270274
el.remove();
271275
}
272-
var url = new URL(this.dataset.url, document.location.href);
273-
var msg = this.dataset.msg || 'URL copied to clipboard';
274-
var infobox = document.createElement('template');
275276
navigator.clipboard.writeText(url.href);
276277
infobox.innerHTML = '<div class="info filer-tooltip">' + msg + '</div>';
277278
this.classList.add('filer-tooltip-wrapper');
278279
this.appendChild(infobox.content.firstChild);
279-
setTimeout(() => {this.getElementsByClassName('info')[0].remove(); }, 1200);
280+
setTimeout(() => {
281+
this.getElementsByClassName('info')[0].remove();
282+
}, 1200);
280283
});
281284
});
282285
})(djQuery);

filer/templates/admin/filer/folder/directory_table_list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
</td>
140140
<td class="column-action">
141141
{% if file.canonical_url %}
142-
<a href="{{ file.canonical_url }}"
142+
<a href="{% if 'svg' in file.mime_type %}{% url 'admin:filer_image_expand_view' file.pk %}{% else %}{{ file.canonical_url }}{% endif %}"
143143
data-url="{{ file.canonical_url }}"
144144
data-msg="{% trans 'URL copied to clipboard' %}"
145145
rel="noopener noreferrer"
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
<html>
2+
<head>
3+
<style>
4+
img {
5+
cursor: zoom-out;
6+
}
7+
body.scrolling img {
8+
cursor: zoom-out;
9+
}
10+
body.scrolling img.zoom {
11+
cursor: zoom-in;
12+
}
13+
img.zoom {
14+
width: 100%;
15+
cursor: zoom-out;
16+
}
17+
</style>
18+
</head>
219
<body style="margin: 0;">
3-
<img style="max-width: 100%" src="{{ original_url }}" />
20+
<img id="img" src="{{ original_url }}" onclick="this.classList.toggle('zoom')"/>
21+
<script>
22+
setInterval(function () {
23+
const img = document.getElementById('img')
24+
document.body.classList.toggle('scrolling', img.naturalWidth >= document.body.clientWidth)
25+
}, 200);
26+
</script>
427
</body>
528
</html>

tests/test_admin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,10 @@ def test_image_expand_view(self):
346346

347347
response = self.client.get(url)
348348

349-
self.assertContains(response, f"""<html>
350-
<body style="margin: 0;">
351-
<img style="max-width: 100%" src="{original_url}" />
352-
</body>
353-
</html>""")
349+
self.assertContains(
350+
response,
351+
f"""<img id="img" src="{ original_url }" onclick="this.classList.toggle('zoom')"/>"""
352+
)
354353

355354

356355
class FilerClipboardAdminUrlsTests(TestCase):

0 commit comments

Comments
 (0)