-
Notifications
You must be signed in to change notification settings - Fork 427
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add actions to group membership APIs
- Loading branch information
Showing
4 changed files
with
61 additions
and
16 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,12 +1,49 @@ | ||
from h.models import GroupMembershipRoles | ||
from h.security import Permission | ||
from h.traversal.group_membership import ( | ||
EditGroupMembershipContext, | ||
GroupMembershipContext, | ||
) | ||
|
||
|
||
class GroupMembershipJSONPresenter: | ||
def __init__(self, membership): | ||
def __init__(self, request, membership, authenticated_roles=None): | ||
self.request = request | ||
self.membership = membership | ||
self.authenticated_roles = authenticated_roles | ||
|
||
def asdict(self): | ||
return { | ||
membership_dict = { | ||
"authority": self.membership.group.authority, | ||
"userid": self.membership.user.userid, | ||
"username": self.membership.user.username, | ||
"display_name": self.membership.user.display_name, | ||
"roles": self.membership.roles, | ||
"actions": [], | ||
} | ||
|
||
if self.request.has_permission( | ||
Permission.Group.MEMBER_REMOVE, | ||
GroupMembershipContext( | ||
self.membership.group, | ||
self.membership.user, | ||
self.membership, | ||
self.authenticated_roles, | ||
), | ||
): | ||
membership_dict["actions"].append("delete") | ||
|
||
for role in GroupMembershipRoles: | ||
if self.request.has_permission( | ||
Permission.Group.MEMBER_EDIT, | ||
EditGroupMembershipContext( | ||
self.membership.group, | ||
self.membership.user, | ||
self.membership, | ||
role, | ||
self.authenticated_roles, | ||
), | ||
): | ||
membership_dict["actions"].append(f"updates.roles.{role}") | ||
|
||
return membership_dict |
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
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