-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4f91f0
commit 90439b1
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from plone.restapi.batching import HypermediaBatch | ||
from plone.restapi.interfaces import ISerializeToJson | ||
from Products.PlonePAS.interfaces.group import IGroupData | ||
from zope.component import adapter | ||
from zope.interface import implementer | ||
from redturtle.volto.interfaces import IRedturtleVoltoLayer | ||
from Products.PluggableAuthService.interfaces.plugins import IRolesPlugin | ||
from plone.restapi.serializer.group import BaseSerializer | ||
from plone import api | ||
|
||
|
||
@implementer(ISerializeToJson) | ||
@adapter(IGroupData, IRedturtleVoltoLayer) | ||
class SerializeGroupToJson(BaseSerializer): | ||
def __call__(self): | ||
data = super().__call__() | ||
group = self.context | ||
if group.id == 'AuthenticatedUsers': | ||
data['roles'] = [] | ||
acl = api.portal.get_tool('acl_users') | ||
rolemakers = acl.plugins.listPlugins(IRolesPlugin) | ||
for rolemaker_id, rolemaker in rolemakers: | ||
roles = rolemaker.getRolesForPrincipal(group) or () | ||
data['roles'].extend(roles) | ||
|
||
members = group.getGroupMemberIds() | ||
batch = HypermediaBatch(self.request, members) | ||
members_data = { | ||
"@id": batch.canonical_url, | ||
"items_total": batch.items_total, | ||
"items": sorted(batch), | ||
} | ||
if batch.links: | ||
members_data["batching"] = batch.links | ||
|
||
data["members"] = members_data | ||
return data | ||
|
||
|