-
Notifications
You must be signed in to change notification settings - Fork 55
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
Conversation
a9d3a0f
to
1116c00
Compare
There was a problem hiding this 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.
src/collective/cover/content.py
Outdated
annotation_tiles = { | ||
k.split('.')[-1]: k | ||
for k in annotations.keys() | ||
if k.startswith(u'plone.tiles.data') or |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice tip! thanks
src/collective/cover/content.py
Outdated
for tile_id, annotation_key in annotation_tiles.iteritems(): | ||
if tile_id in layout_tiles: | ||
continue | ||
annotations.pop(annotation_key, None) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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.
@hvelarde done |
src/collective/cover/content.py
Outdated
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') |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
src/collective/cover/content.py
Outdated
""" | ||
prefixes = ('plone.tiles.data', 'plone.tiles.configuration', 'plone.tiles.permission') | ||
layout_tiles = self.list_tiles() | ||
annotations = IAnnotations(self) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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..
@idgserpro @claytonc I need more eyes here, please. |
src/collective/cover/config.py
Outdated
@@ -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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these constants are defined somewhere else:
- https://github.com/collective/collective.cover/blob/1.6b4/src/collective/cover/tiles/configuration.py#L17
- https://github.com/collective/collective.cover/blob/1.6b4/src/collective/cover/tiles/permissions.py#L9
- https://github.com/plone/plone.tiles/blob/2.0.0b3/plone/tiles/data.py#L37
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
src/collective/cover/content.py
Outdated
""" | ||
prefixes = ('plone.tiles.data', 'plone.tiles.configuration', 'plone.tiles.permission') | ||
layout_tiles = self.list_tiles() | ||
annotations = IAnnotations(self) |
There was a problem hiding this comment.
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.
src/collective/cover/tiles/base.py
Outdated
""" | ||
logger.debug('Deleting tile {0}'.format(self.id)) | ||
|
||
data_mgr = ITileDataManager(self) |
There was a problem hiding this comment.
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.
2833949
to
7e277a3
Compare
${compose_url} = Execute Javascript | ||
... return (function() { | ||
... return location.href; | ||
... })(); |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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'); | ||
... })(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get Element Attribute:
http://robotframework.org/Selenium2Library/Selenium2Library.html#Get%20Element%20Attribute
self._do_upgrade_step(step) | ||
|
||
with self.assertRaises(KeyError): | ||
annotations[key] |
There was a problem hiding this comment.
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())
There was a problem hiding this comment.
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.
src/collective/cover/content.py
Outdated
|
||
To delete tile we just need the ID, the type can be anything. | ||
""" | ||
tile = self.restrictedTraverse('foo/' + tile_id) |
There was a problem hiding this comment.
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?
e162665
to
ee28d94
Compare
db42a9b
to
facb577
Compare
I'm going to merge this after Travis; if somebody else has something to say, it's now. |
from collective.cover.config import PERMISSIONS_PREFIX | ||
from zope.annotation import IAnnotations | ||
from zope.component import eventtesting | ||
from zope.lifecycleevent import IObjectModifiedEvent |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Fix #765