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

Commit

Permalink
Moved utils.current_service(request) to reified request method (ref
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Feb 3, 2016
1 parent 3189f68 commit a6b3e90
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ This document describes changes between each past release.
- Resource events are not emitted if the transaction is rolledback (e.g. a batch
subrequest fails) (#634)

**Internal changes**

- Moved ``utils.current_service(request)`` to reified request method (ref #631)

2.15.0 (2016-01-27)
-------------------
Expand Down
4 changes: 3 additions & 1 deletion cliquet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from cliquet.initialization import ( # NOQA
initialize, initialize_cliquet, install_middlewares,
load_default_settings)
from cliquet.utils import follow_subrequest, current_resource_name
from cliquet.utils import (
follow_subrequest, current_service, current_resource_name)
from cliquet.logs import logger


Expand Down Expand Up @@ -157,6 +158,7 @@ def add_api_capability(config, identifier, description="", url="", **kw):
config.add_request_method(lambda request: {'id': request.prefixed_userid},
name='get_user_info')
config.add_request_method(current_resource_name, reify=True)
config.add_request_method(current_service, reify=True)
config.commit()

# Include cliquet plugins after init, unlike pyramid includes.
Expand Down
2 changes: 1 addition & 1 deletion cliquet/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def get_permission_object_id(self, request, record_id=None):
# With the current request on a collection, the record URI must
# be found out by inspecting the collection service and its sibling
# record service.
service = utils.current_service(request)
service = request.current_service
# XXX: Why not use service.path.format(id=) ?
record_service = service.name.replace('-collection', '-record')
matchdict = request.matchdict.copy()
Expand Down
5 changes: 2 additions & 3 deletions cliquet/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from cliquet.storage import exceptions as storage_exceptions, Filter, Sort
from cliquet.utils import (
COMPARISON, classname, native_value, decode64, encode64, json,
current_service, encode_header, decode_header, DeprecatedMeta,
dict_subset
encode_header, decode_header, DeprecatedMeta, dict_subset
)

from .model import Model, ShareableModel
Expand Down Expand Up @@ -1006,7 +1005,7 @@ def _next_page_url(self, sorting, limit, last_record, offset):
params['_limit'] = limit
params['_token'] = token

service = current_service(self.request)
service = self.request.current_service
next_page_url = self.request.route_url(service.name, _query=params,
**self.request.matchdict)
return next_page_url
Expand Down
2 changes: 1 addition & 1 deletion cliquet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def reapply_cors(request, response):
recreating the response from scratch.
"""
service = current_service(request)
service = request.current_service
if service:
request.info['cors_checked'] = False
cors.apply_cors_post_request(service, request, response)
Expand Down
3 changes: 1 addition & 2 deletions cliquet_docs/reference/permission.rst
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,11 @@ For example, a simplistic example with the previous resource viewset:
.. code-block:: python
from pyramid.security import IAuthorizationPolicy
from cliquet import utils
class MyRootFactory(object):
def __init__(self, request):
self.current_resource = None
service = utils.current_service(request)
service = request.current_service
if service and hasattr(service, 'resource'):
self.current_resource = service.resource
Expand Down

0 comments on commit a6b3e90

Please sign in to comment.