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

Commit

Permalink
Enable to set prinrole and roleperm
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramon Navarro Bosch committed Jan 27, 2017
1 parent d76afaf commit 84bdb5b
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/plone.server/plone/server/api/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from zope.securitypolicy.interfaces import IPrincipalPermissionMap
from zope.securitypolicy.interfaces import IPrincipalRoleManager
from zope.securitypolicy.interfaces import IRolePermissionManager
from zope.securitypolicy.interfaces import IPrincipalRoleMap
from zope.securitypolicy.interfaces import IRolePermissionMap

Expand Down Expand Up @@ -200,12 +201,20 @@ async def sharing_get(context, request):
name='@sharing')
async def sharing_post(context, request):
data = await request.json()
roleperm = IRolePermissionManager(context)
prinrole = IPrincipalRoleManager(context)
if 'prinrole' not in data:
raise HTTPNotFound('prinrole missing')
for user, roles in data['prinrole'].items():
for role in roles:
prinrole.assignRoleToPrincipal(role, user)
if 'prinrole' not in data and 'roleperm' not in data:
raise AttributeError('prinrole or roleperm missing')

if 'prinrole' in data:
for user, roles in data['prinrole'].items():
for role in roles:
prinrole.assignRoleToPrincipal(role, user)

if 'roleperm' in data:
for role, perms in data['roleperm'].items():
for perm in perms:
roleperm.grantPermissionToRole(perm, role)
await notify(ObjectPermissionsModifiedEvent(context))


Expand Down

0 comments on commit 84bdb5b

Please sign in to comment.