-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove can_assign key from roles endpoint
- Loading branch information
Showing
3 changed files
with
0 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,19 @@ | ||
from AccessControl import getSecurityManager | ||
from Acquisition import aq_inner | ||
from plone.restapi.services import Service | ||
from Products.CMFCore.permissions import ManagePortal | ||
from Products.CMFCore.utils import getToolByName | ||
from zope.i18n import translate | ||
|
||
|
||
class RolesGet(Service): | ||
@property | ||
def is_zope_manager(self): | ||
return getSecurityManager().checkPermission(ManagePortal, self.context) | ||
|
||
def can_assign(self, is_zope_manager, _id): | ||
if is_zope_manager: | ||
return True | ||
return _id != "Manager" | ||
|
||
def reply(self): | ||
pmemb = getToolByName(aq_inner(self.context), "portal_membership") | ||
roles = [r for r in pmemb.getPortalRoles() if r != "Owner"] | ||
is_zope_manager = self.is_zope_manager | ||
return [ | ||
{ | ||
"@type": "role", | ||
"@id": f"{self.context.absolute_url()}/@roles/{r}", | ||
"id": r, | ||
"title": translate(r, context=self.request, domain="plone"), | ||
"can_assign": self.can_assign(is_zope_manager, r), | ||
} | ||
for r in roles | ||
] |
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