24
Transforming Safe HTML PRAKHAR JOSHI (GSOC’15)

Transforming safe html

Embed Size (px)

Citation preview

Page 1: Transforming safe html

Transforming Safe HTMLPRAKHAR JOSHI (GSOC’15)

Page 2: Transforming safe html

How I started Contributed to Plone

Plone is one of the most frequent organization that is part of Google Summer of Code.

The IRC people really helped a lot during the initial phase. Awesome Documentation. Came across the ticket https://dev.plone.org/ticket/14929

 proposed by Tom when I was looking for some project and he has also tried to do the changes accordingly but there were lot of constraint of test cases that made it less possible to work on it.

Page 3: Transforming safe html

Cont..

Plone.transform was a try for the same during GSOC’07. Finally decided to create a separate project for creating safe html

transform using lxml and not of CMF Default. We also thought about using intelligent text from html transform. Finally created a new add-on experimental.safe_html_transform. It uses lxml to filter html.

Page 4: Transforming safe html

Difficulties working with Plone

Plone is not a piece of cake for anyone new. The Plone code base is too vast. Things were alien for 1-2 months. It was difficult for me to figure out from where to start. The safe_html of portal_transform is quite old. It was difficult to understand the code of old html filter which was

using CMF Default, SGML Parser.

Page 5: Transforming safe html

Fun With Plone

Learnt how to work in team. Learnt a lot of new things related to plone and how awesome

plone is. How to write efficient code and how to document the work that

have been done. Test Driven Development. One of the best part of plone. Got to interact with cool people. Got to know about the unique and new beers of Europe.

Page 6: Transforming safe html

The main aim of the project

This is to be done with CMF Default in Plone and in this project also :-

Page 7: Transforming safe html

The new safe_Html Filter

Lot of things required to setup the add-on. Generic setup of the transform. Register safe_html for the browser. Add control panel for filter to the browser. Create interface for filter under browser. Setup profile for the transform by registering browser layer and control

panel under the profile module. Deregister Profile as to replace the existing one with a transform of the

same name, since TinyMCE and p.a.controlpanel address safe_html by it’s Transform name, rather than asking for one MIME to another MIME. (safe_html = getattr(getToolByName(self, 'portal_transforms'), 'safe_html'))

Page 8: Transforming safe html

Automatic register and deregister for safe_html

Functions for register and deregister of the product. Register safe_html on the installation of the add on. Deregistration of the old safe_html from the portal_transform. when any developer just install safe_html, the old safe_html will

deregister and the new safe_html will get registered. People who are just using plone site will use safe_html by adding

an add-on in their “@@overview-controlpanel” and add experimental.safe_html_trasform.

The old safe_html from portal_transform will be deregistered and  the new safe_html that add-on one will get registered.

Page 9: Transforming safe html

Cont..

Codes :- <genericsetup:registerProfile

        name="default"        title="experimental.safe_html_transform"        directory="profiles/default"        description="Installs the experimental.safe_html_transform add- on."        provides="Products.GenericSetup.interfaces.EXTENSION"        />

 <genericsetup:registerProfile      name="uninstall"      title="experimental.safe_html_transform uninstall"      directory="profiles/uninstall"      description="Uninstalls the experimental.safe_html_transform package"      provides="Products.GenericSetup.interfaces.EXTENSION"      />

Page 10: Transforming safe html

New Releases at plone , releases my sweat.

This was the time when CMF Plone 5.0.dev was released. Not able to detect the issue as where CMF Plone was used as I

have already pinned the CMF Plone. Plone.app.widget was not pinned and that is using CMF Plone so

it was creating an error and it took me a lot of time to solve This was one of the scariest experience of my GSOC project.

Page 11: Transforming safe html
Page 12: Transforming safe html
Page 13: Transforming safe html

Getting Control Panel for add-on

 Two ways to create Control Panel Either to overwrite the old cntrol panel of PortalTransform

safe_html. Create a separate control panel for our new safe_html add-on. I choose the 2nd way to create a control panel and created a

separate control panel for the add-on.

Page 14: Transforming safe html

Cont..

Register the control panel. <!-- Filter Control Panel --><browser:page name="safe_html_transform-settings"

for="Products.CMFPlone.interfaces.IPloneSiteRoot"

layer="..interfaces.IExperimentalSafeHtmlTransformLayer"class=".controlpanel.FilterControlPanel"

permission="experimental.safe_html.controlpanel.Filtering“/>

Page 15: Transforming safe html

Cont..

Adding Permissions for control panel<configure

xmlns="http://namespaces.zope.org/zope"> <permission id="experimental.safe_html.controlpanel.Filtering" title="Plone Site Setup: Filtering"> <role name="Manager"/> <role name="Site Administrator"/> </permission>

</configure>

Page 16: Transforming safe html

The Transform Finally…

This is the script for filtering safe_html using lxml. Converting the whole document into the tree form and then

parsing each node of the tree anf filtering accordingly. Used the Cleaner class of lxml for creating Html Filter. On add-on installation this transform have to filter the HTML

instaed of the safe_html transform of Portal_transform.

Page 17: Transforming safe html

Why we need to port the transform to lxml ? 

To remove the CMF Default dependencies. To make the filtering faster. To make the filtering accurate and more optimized.

Page 18: Transforming safe html

Testing the transform

Used Unit test to test the transform. Using sample HTML to test the transform. Using Automated Robot test and integration tests for testing the

whole add-on.

Page 19: Transforming safe html
Page 20: Transforming safe html

How to make tinyMCE uses our new transform in place of old transform? It uses getToolByName in portal_transform to get the required

transform. Rename our new transform to safe_html instead of some other

name.  we changed the name of our transform same as old one so that

tinyMCE sense it like a normal thing and no change. :P

Page 21: Transforming safe html
Page 22: Transforming safe html

Things I learnt during the project

How to work with test driven Development (TDD). How work in collaboration with people on a project. How to work on big projects. How to catch errors from the error logs. How to keep logs for the huge projects. (Blogging, task managers

etc)

Page 23: Transforming safe html

Plans ahead

Looking forward to learn more about plone As of right now a lot more to learn, a lot more to develop and a

lot more to code.

Page 24: Transforming safe html

Thank You!!