Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purge data when delete tile #768

Merged
merged 11 commits into from
Nov 21, 2017
Merged

Purge data when delete tile #768

merged 11 commits into from
Nov 21, 2017

Conversation

rodfersou
Copy link
Member

@rodfersou rodfersou commented Nov 17, 2017

Fix #765

@rodfersou rodfersou force-pushed the issue_765 branch 2 times, most recently from a9d3a0f to 1116c00 Compare November 17, 2017 18:41
Copy link
Member

@hvelarde hvelarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is looking good; we need an upgrade step and a clear changelog entry.

annotation_tiles = {
k.split('.')[-1]: k
for k in annotations.keys()
if k.startswith(u'plone.tiles.data') or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be written differently:

prefixes = ('plone.tiles.data', 'plone.tiles.configuration', 'plone.tiles.permission')
...
    for k in annotations.keys() if k.startswith(prefixes)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice tip! thanks

for tile_id, annotation_key in annotation_tiles.iteritems():
if tile_id in layout_tiles:
continue
annotations.pop(annotation_key, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the variable to key and remove the annotation like this:

del annotations[key]

@@ -177,6 +177,17 @@ Test Basic Tile

# go back to compose view and edit the tile
Compose Cover

${compose_url} = Execute Javascript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move this test out of here to make it easier to understand.

@@ -186,6 +197,16 @@ Test Basic Tile
# check for successful AJAX refresh
Wait Until Page Contains ${title_sample}

Go to ${edit_url}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment to document why you are doing this and what are you trying to demonstrate.

@rodfersou
Copy link
Member Author

@hvelarde done

This method purge all tile annotation data for tiles where there are
no reference in layout.
"""
prefixes = ('plone.tiles.data', 'plone.tiles.configuration', 'plone.tiles.permission')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these prefixes are defined as constants we should import and use the constants instead of hard-coding them.

@@ -290,41 +290,10 @@
'top': '0',
'width': '15px'
});
elements = elements !== undefined ? elements : le.find('.' + column_class + ', .' + tile_class + ', .' + row_class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is not in the JS registry, we don't need to cook the registry in the upgrade step; anyway, I think is a good idea to add it in the registry to guarantee it will be always updated in production sites.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think about it when we rewrite code to use webpack; I'll remove the upgrade step to cook javascript now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put ?v=xxxx in the file call to avoid problems with caching.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I saw you registered js.

@@ -66,24 +65,3 @@ def test_default_configuration(self):

def test_accepted_content_types(self):
self.assertEqual(self.tile.accepted_ct(), ALL_CONTENT_TYPES)

def test_delete_tile_persistent_data(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to keep this test to guarantee all persistent data, conffiguration an permissions are removed at low level and the ObjectModifiedEvent is being fired.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses the tile.delete() method that was suggested to be removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to think on how to test the feature on low level.

"""
prefixes = ('plone.tiles.data', 'plone.tiles.configuration', 'plone.tiles.permission')
layout_tiles = self.list_tiles()
annotations = IAnnotations(self)
Copy link
Member

@hvelarde hvelarde Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has to be divided in a two-step process: on plone.tiles persistent tiles data can be stored on a storage different of annotations, that means it's safer to use the data manager API to remove the data from the tile; our annotations (configuration and permission) can be removed directly, but we will need to test them at least on the base tile at low level to guarantee it's working.

it's probably better to keep the API also on configuration and permission, so we could call a delete() method to do the work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean.. storage variable is an alias to annotation property

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean you have to delete the annotation using the tile manager.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't work, tile collection test breaks because I don't know the type of the deleted tile to instantiate the correct type..

@hvelarde
Copy link
Member

hvelarde commented Nov 20, 2017

@idgserpro @claytonc I need more eyes here, please.

@@ -37,3 +37,5 @@
# In case that no value was set to that field
# we need to detect it and use it
DEFAULT_SEQUENCEWIDGET_VALUE = '--NOVALUE--'

ANNOTATION_PREFIXES = ('plone.tiles.data', 'plone.tiles.configuration', 'plone.tiles.permission')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@hvelarde hvelarde Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodfersou did you saw this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I saw, need to review this

@@ -66,24 +65,3 @@ def test_default_configuration(self):

def test_accepted_content_types(self):
self.assertEqual(self.tile.accepted_ct(), ALL_CONTENT_TYPES)

def test_delete_tile_persistent_data(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have to think on how to test the feature on low level.

"""
prefixes = ('plone.tiles.data', 'plone.tiles.configuration', 'plone.tiles.permission')
layout_tiles = self.list_tiles()
annotations = IAnnotations(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean you have to delete the annotation using the tile manager.

"""
logger.debug('Deleting tile {0}'.format(self.id))

data_mgr = ITileDataManager(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is what you need to do in the new purge_deleted_tiles() method.

@rodfersou rodfersou force-pushed the issue_765 branch 7 times, most recently from 2833949 to 7e277a3 Compare November 20, 2017 20:01
${compose_url} = Execute Javascript
... return (function() {
... return location.href;
... })();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${compose_url} = Get Location

# confirm that data is still there
Go to ${edit_url}
${value} = Get value ${title_field_id}
Should be equal ${title_sample} ${value}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it even necessary to test this? You just clicked Save.

# confirm that data is gone
Go to ${edit_url}
${value} = Get value ${title_field_id}
Should Not be equal ${title_sample} ${value}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, it needs to be empty. They are different things.

... return (function() {
... var $link = jQuery('${edit_link_selector}');
... return $link.attr('href');
... })();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self._do_upgrade_step(step)

with self.assertRaises(KeyError):
annotations[key]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If annotations have the keys method:

self.assertNotIn(key, annotations.keys())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Python 3 there is no keys() method; we must use self.assertNotIn(key, annotations) instead.


To delete tile we just need the ID, the type can be anything.
"""
tile = self.restrictedTraverse('foo/' + tile_id)
Copy link
Member Author

@rodfersou rodfersou Nov 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@datakurre when I try to instantiate a deleted tile (to delete it's data) I get this exception:

ipdb> self.restrictedTraverse(u'foo/' + tile_id)
*** NotFound: f
ipdb> self.restrictedTraverse(u'collective.cover.base/' + tile_id)
*** NotFound: c
ipdb> self.restrictedTraverse(u'collective.cover.basic/' + tile_id)
*** NotFound: c

Can you help me please understand why this code don't work, while it is almost the same code from get_tile method?

@rodfersou rodfersou force-pushed the issue_765 branch 6 times, most recently from e162665 to ee28d94 Compare November 20, 2017 23:56
@rodfersou rodfersou force-pushed the issue_765 branch 3 times, most recently from db42a9b to facb577 Compare November 21, 2017 00:02
@hvelarde
Copy link
Member

I'm going to merge this after Travis; if somebody else has something to say, it's now.

@hvelarde hvelarde merged commit ba54a2a into master Nov 21, 2017
@hvelarde hvelarde deleted the issue_765 branch November 21, 2017 19:16
from collective.cover.config import PERMISSIONS_PREFIX
from zope.annotation import IAnnotations
from zope.component import eventtesting
from zope.lifecycleevent import IObjectModifiedEvent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hvelarde why in tests do you import inside the methods?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because is easier to maintain later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants