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

Commit

Permalink
Merge pull request #56 from plone/async-install-functions
Browse files Browse the repository at this point in the history
handle async addon functions
  • Loading branch information
vangheem committed Jan 25, 2017
2 parents 0b93bae + d6f617d commit b9b29a2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/plone.server/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

New features:

- install, uninstall methods for addon class can now be async
[vangheem]

- Be able to define adapters, subscribers, permissions, roles, grant
with decorators, not zcml
[vangheem]
Expand Down
12 changes: 10 additions & 2 deletions src/plone.server/plone/server/api/addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from plone.server.registry import IAddons
from zope.i18nmessageid import MessageFactory

import asyncio


_ = MessageFactory('plone')

Expand All @@ -28,7 +30,10 @@ async def install(context, request):
'Duplicate',
_("Addon already installed"))
handler = app_settings['available_addons'][id_to_install]['handler']
handler.install(request)
if asyncio.iscoroutinefunction(handler.install):
await handler.install(request)
else:
handler.install(request)
config.enabled |= {id_to_install}
return await get_addons(context, request)()

Expand All @@ -52,7 +57,10 @@ async def uninstall(context, request):
_("Addon not installed"))

handler = app_settings['available_addons'][id_to_install]['handler']
handler.uninstall(request)
if asyncio.iscoroutinefunction(handler.install):
await handler.uninstall(request)
else:
handler.uninstall(request)
config.enabled -= {id_to_install}


Expand Down
12 changes: 10 additions & 2 deletions src/plone.server/plone/server/traversal.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,21 @@ async def traverse(request, parent, path):
return await traverse(request, context, path[1:])


def _url(request):
try:
return request.url.human_repr()
except AttributeError:
# older version of aiohttp
return request.path


def generate_unauthorized_response(e, request):
# We may need to check the roles of the users to show the real error
eid = uuid.uuid4().hex
message = _('Not authorized to render operation') + ' ' + eid
user = get_authenticated_user_id(request)
extra = {
'r': request.url.human_repr(),
'r': _url(request),
'u': user
}
logger.error(
Expand All @@ -172,7 +180,7 @@ def generate_error_response(e, request, error, status=400):
message = _('Error on execution of view') + ' ' + eid
user = get_authenticated_user_id(request)
extra = {
'r': request.url.human_repr(),
'r': _url(request),
'u': user
}
logger.error(
Expand Down

0 comments on commit b9b29a2

Please sign in to comment.