Skip to content

Commit

Permalink
Merge pull request Kinto#730 from Kinto/prepare-3.3.2
Browse files Browse the repository at this point in the history
Prepare 3.3.2
  • Loading branch information
leplatrem authored Jul 21, 2016
2 parents 8d44754 + a54fbc0 commit ab8db08
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Changelog

This document describes changes between each past release.

3.3.2 (2016-07-21)
==================

**Bug fixes**

- Fix Redis get_accessible_object implementation (#725)
- Fix bug where the resource events of a request targetting two groups/collection
from different buckets would be grouped together.


3.3.1 (2016-07-19)
==================

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
# The short X.Y version.
version = '3.3'
# The full version, including alpha/beta/rc tags.
release = '3.3.0'
release = '3.3.2'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
11 changes: 9 additions & 2 deletions kinto/core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def __init__(self, payload, request):
self.payload = payload
self.request = request

def __repr__(self):
return "<{klass} action={action} uri={uri}>".format(
klass=self.__class__.__name__,
**self.payload)


class ResourceRead(_ResourceEvent):
"""Triggered when a resource is being read.
Expand Down Expand Up @@ -118,7 +123,8 @@ def get_resource_events(request, after_commit=False):
return events


def notify_resource_event(request, timestamp, data, action, old=None):
def notify_resource_event(request, parent_id, timestamp, data, action,
old=None):
"""
Request helper to stack a resource event.
Expand All @@ -141,10 +147,11 @@ def notify_resource_event(request, timestamp, data, action, old=None):

# Get previously triggered events.
events = request.bound_data.setdefault("resource_events", OrderedDict())

resource_name = request.current_resource_name

# Group events by resource and action.
group_by = resource_name + action.value
group_by = resource_name + parent_id + action.value

if group_by in events:
# Add to impacted records of existing event.
Expand Down
4 changes: 2 additions & 2 deletions kinto/core/permission/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def get_accessible_objects(self, principals, bound_permissions=None):
for key in matched:
authorized = self._decode_set(self._client.smembers(key))
if len(authorized & principals) > 0:
_, object_id, permission = key.decode('utf-8').split(':')
perms_by_id.setdefault(object_id, set()).add(permission)
_, obj_id, permission = key.decode('utf-8').split(':', 2)
perms_by_id.setdefault(obj_id, set()).add(permission)

return perms_by_id

Expand Down
4 changes: 3 additions & 1 deletion kinto/core/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,9 @@ def postprocess(self, result, action=ACTIONS.READ, old=None):
'data': result
}

self.request.notify_resource_event(timestamp=self.timestamp,
parent_id = self.get_parent_id(self.request)
self.request.notify_resource_event(parent_id=parent_id,
timestamp=self.timestamp,
data=result,
action=action,
old=old)
Expand Down
26 changes: 26 additions & 0 deletions kinto/tests/core/resource/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ class ResourceChangedTest(BaseEventTest, unittest.TestCase):

subscribed = (ResourceChanged,)

def test_events_have_custom_representation(self):
self.app.post_json(self.collection_url, self.body,
headers=self.headers, status=201)
self.assertEqual(repr(self.events[0]),
"<ResourceChanged action=create "
"uri=%s>" % self.collection_url)

def test_post_sends_create_action(self):
self.app.post_json(self.collection_url, self.body,
headers=self.headers, status=201)
Expand Down Expand Up @@ -352,6 +359,25 @@ def test_one_event_is_sent_per_resource(self):
self.app.post_json("/batch", body, headers=self.headers)
self.assertEqual(len(self.events), 2)

def test_one_event_is_sent_per_parent_id(self):
# /mushrooms is a UserResource (see testapp.views), which means
# that parent_id depends on the authenticated user.
body = {
"defaults": {
"path": '/mushrooms',
"method": "POST",
"body": self.body
},
"requests": [
{"headers": {"Authorization": "Basic bWF0OjE="}},
{"headers": {"Authorization": "Basic dG90bzp0dXR1"}},
{"headers": {"Authorization": "Basic bWF0OjE="}},
]
}
self.app.post_json("/batch", body, headers=self.headers)
# Two different auth headers, thus two different parent_id:
self.assertEqual(len(self.events), 2)

def test_one_event_is_sent_per_action(self):
body = {
"defaults": {
Expand Down
5 changes: 3 additions & 2 deletions kinto/tests/core/test_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,15 @@ def test_get_authorized_principals_handles_empty_set(self):

def test_accessible_objects(self):
self.permission.add_principal_to_ace('id1', 'write', 'user1')
self.permission.add_principal_to_ace('id1', 'read', 'group')
self.permission.add_principal_to_ace('id1', 'record:create', 'group')
self.permission.add_principal_to_ace('id2', 'read', 'user1')
self.permission.add_principal_to_ace('id2', 'read', 'user2')
self.permission.add_principal_to_ace('id3', 'write', 'user2')
per_object_ids = self.permission.get_accessible_objects(
['user1', 'group'])
self.assertEquals(sorted(per_object_ids.keys()), ['id1', 'id2'])
self.assertEquals(per_object_ids['id1'], set(['read', 'write']))
self.assertEquals(per_object_ids['id1'],
set(['write', 'record:create']))
self.assertEquals(per_object_ids['id2'], set(['read']))

def test_accessible_objects_from_permission(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def read_file(filename):


setup(name='kinto',
version='3.3.1',
version='3.3.2',
description='Kinto Web Service - Store, Sync, Share, and Self-Host.',
long_description=README + "\n\n" + CHANGELOG + "\n\n" + CONTRIBUTORS,
license='Apache License (2.0)',
Expand Down

0 comments on commit ab8db08

Please sign in to comment.