Skip to content
This repository has been archived by the owner on Feb 9, 2019. It is now read-only.

Commit

Permalink
Use a UserResource rather than a ShareableResource
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed Dec 13, 2015
1 parent be70254 commit 860bc21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
30 changes: 5 additions & 25 deletions kinto_webpush/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
import copy
import requests

from cliquet.events import ResourceChanged
from kinto import authorization
from pyramid.security import IAuthorizationPolicy
from zope.interface import implementer

INHERITANCE_TREE = copy.deepcopy(authorization.PERMISSIONS_INHERITANCE_TREE)
INHERITANCE_TREE['collection:webpush:create'] = {
'webpush': ['read', 'write']
}

for key in INHERITANCE_TREE.keys():
if key.startswith(('collection:', 'records:')):
INHERITANCE_TREE[key]['webpush'] = ['write']


@implementer(IAuthorizationPolicy)
class AuthorizationPolicy(authorization.AuthorizationPolicy):
def get_bound_permissions(self, *args, **kwargs):

return authorization.build_permissions_set(
inheritance_tree=INHERITANCE_TREE,
*args, **kwargs)


def includeme(config):
Expand All @@ -42,11 +23,10 @@ def on_resource_changed(event):
# XXX Need to find a way to expire the URLs after some point,
# otherwise they will just pile up and being pinged even if
# useless.
recipients = event.request.storage.get_all(
collection_id=parent_id + "/webpush",
parent_id=parent_id)

from pdb import set_trace; set_trace()
recipients, _ = event.request.registry.storage.get_all(
collection_id="webpush", parent_id=parent_id)
for recipient in recipients:
requests.post(recipient['url'])

config.add_subscriber(on_resource_changed, ResourceChanged)
config.scan('kinto_webpush.views')
Expand Down
12 changes: 11 additions & 1 deletion kinto_webpush/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,15 @@ class WebPushSchema(resource.ResourceSchema):

@resource.register(collection_path=_parent_path + '/webpush',
record_path=_parent_path + '/webpush/{{id}}')
class WebPush(resource.ShareableResource):
class WebPush(resource.UserResource):
mapping = WebPushSchema()

def get_parent_id(self, request):
bucket_id = request.matchdict['bucket_id']
if bucket_id == 'default':
bucket_id = request.default_bucket_id
collection_id = request.matchdict['collection_id']
return '/buckets/%s/collections/%s' % (bucket_id,
collection_id)


4 changes: 0 additions & 4 deletions webpush.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ kinto.userid_hmac_secret = aujourd'hui il fait froid en bretagne.
multiauth.policies = basicauth
kinto.includes = kinto_webpush
kinto_updater.bucket = gofaster
kinto_updater.collection = onecrl
kinto.remote_url = http://localhost:7777
multiauth.authorization_policy = kinto_webpush.AuthorizationPolicy
[loggers]
keys = root, cliquet
Expand Down

0 comments on commit 860bc21

Please sign in to comment.