Commit aff30449 authored by Rafael Monnerat's avatar Rafael Monnerat

Fix convetsion and content type when convert to svg

In order to fix content type it was Introduced a small
Monkey-Patch for zope.contenttype in order to detect
image/svg+xml content types. This is broken even in newer
versions and this monkey patch is foward compatible.

Update Document and tests to permit conversions to SVG, this
prevents get Unauthorized when use ?format=svg.
parent 72af82b1
master allow_login_change allow_login_change_differentiate_id_and_login allow_login_change_wip arnau arnau-kns arnau-kns-without-property-mapping arnau-merge arnau-poc authentication_policy_fixes auto_extend_select_list autoflake backup_erp5_workflow bk_erp5ish_actions_tool bk_sqlcatalog boc-interaction-drop bt_owner cache catalog_fulltext catalog_fulltext_old cedric cedriclen cedriclen-eos cherry-pick-4a8e045d cherry-pick-bca64206 cleanJSByJSLint clean_up_upgrader compact_title_no_reference credential_update_action datetimefield douglas_forum dream_distributor drop-legacy-simulation eos-dev erp5-component erp5-data-notebook erp5-forum erp5-preference erp5-release erp5-slapos-upgrade erp5-util-testing erp5-vifib erp5-vifib-cleanup erp5_calendar erp5_free_subscription erp5_workflow fix_system_processes_ownership floatArrayTest for_testrunner_1 for_testrunner_2 formbox gabriel gabriel-fix-rounding-in-accounting-generation gabriel-fix-rounding-in-accounting-generation2 gadget-json-value http_cache_fix import_fixes import_fixes_complete improve_default_caching_policy_manager interaction-drop isDeletable item_tracking_graph_editor ivan jerome-bt-reference-doc jerome-test jerome_events jerome_graph_editor_renderjs jerome_new_style_solve_divergence jerome_promise_in_tests jerome_user_preference_time_zone jio jm/form-action-guard joblib-activity jupyter_egg_tests jupyter_import_dot_fix jupyter_import_dot_quickfix jupyter_kernel_fixes jupyter_reference_warning jupyter_restricted kns lignan lingnan listbox-generator mame-bt5-cleanup mame-erp5_project-cleanup mame-naming-convention mame-naming-convention-list_method mame-test-stock-indexation mame-work master-erp5-test-result-scalability master-erp5-test-result-scalability-rebase master-test-fix-additionalbt5path master_calendar_wip_patches master_calendar_wip_patches_extend_security master_no_guard_on_workflow_transition master_no_guard_on_workflow_transition_plus_calendar_wip_patchs merge_xhtml_jquery mmariani-inventory mrp new-render-presentation nexedi-erp5-jp no_reindex_data_stream officejs pere portal_callables portal_solver_process_security_configuration presentation rebased_mrp reindex_calendar_after_change_calendar_exception removed_portal_skin_redundancy romain-fulltext scalability-master2 scalability-master2-rebase scalability-rebase shop-box shop-box-rebased simulation sms_more_than_140_characters strict_catalog syncml test_page testnode_software_link timezones tristan tristan-merge tristan-performance upgradeSite view-aggregated-amounts vivekpab_erp5webrenderjs_layoutconfig vivekpab_jabberclient vivekpab_renderjs_interfaces wenjie wenjie_branch xiaowu_newui yryr yryr-components-cp yryr-inventory-cache yryr-test yryr-with-components yusei erp5.util-0.4.46 erp5.util-0.4.44 erp5.util-0.4.43 erp5.util-0.4.41 erp5.util-0.4.40 erp5.util-0.4.37
No related merge requests found
......@@ -69,8 +69,8 @@ FIXED_PROPERTY_IDS = ('id', 'uid', 'rid', 'sid')
VALID_TEXT_FORMAT_LIST = ('text', 'txt', 'html', 'base_html',
'stripped-html')
VALID_IMAGE_FORMAT_LIST = ('jpg', 'jpeg', 'png', 'gif', 'pnm', 'ppm', 'tiff')
VALID_TRANSPARENT_IMAGE_FORMAT_LIST = ('png', 'gif', 'tiff')
VALID_IMAGE_FORMAT_LIST = ('jpg', 'jpeg', 'png', 'gif', 'pnm', 'ppm', 'tiff', 'svg')
VALID_TRANSPARENT_IMAGE_FORMAT_LIST = ('png', 'gif', 'tiff', 'svg')
DEFAULT_DISPLAY_ID_LIST = ('nano', 'micro', 'thumbnail',
'xsmall', 'small', 'medium',
......
......@@ -60,7 +60,6 @@ class TestERP5WebWithDms(ERP5TypeTestCase, ZopeTestCase.Functional):
manager_password = 'zope'
website_id = 'test'
def getTitle(self):
return "ERP5WebWithDms"
......@@ -713,6 +712,11 @@ return True
image_reference + '?format=jpg', credential)
self.assertEquals(response.getHeader('content-type'), 'image/jpeg')
# testing Image conversions, svg
response = self.publish(website.absolute_url_path() + '/' +\
image_reference + '?format=svg', credential)
self.assertEquals(response.getHeader('content-type'), 'image/svg+xml')
# testing Image conversions, resizing
response = self.publish(website.absolute_url_path() + '/' +\
image_reference + '?display=large', credential)
......
......@@ -71,6 +71,7 @@ from Products.ERP5Type.patches import OFSHistory
from Products.ERP5Type.patches import OFSItem
from Products.ERP5Type.patches import ExternalMethod
from Products.ERP5Type.patches import User
from Products.ERP5Type.patches import zopecontenttype
# These symbols are required for backward compatibility
from Products.ERP5Type.patches.PropertyManager import ERP5PropertyManager
......
# Monkey Patch the zope.contenttype to be able to detect svg image format.
try:
import zope.contenttype
original_text_type = zope.contenttype.text_type
def svg_fix_text_type(s):
s = s.strip()
if '<html>' not in s and "<svg" in s:
return 'image/svg+xml'
# If it is not an svg, just try original behaviour.
# This preserve the further improvements on zope.contenttype
# and preserve the fix.
return original_text_type(s)
# Overwrite original method with the SVG detection fix.
zope.contenttype.text_type = svg_fix_text_type
except ImportError:
print "Skip to patch zope.contenttype, because it is not present."
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment