Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore transitive membership of groups #240

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Changelog
- Add principals to groups that already exist during import (#228)
[pbauer]

- In export_members ignore transitive membership of groups (#240)
[pbauer]


1.10 (2023-10-11)
-----------------

Expand Down
10 changes: 8 additions & 2 deletions src/collective/exportimport/export_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,14 @@ def _getUserPassword(self, userId):

def _getUserData(self, userId):
member = self.pms.getMemberById(userId)
groups = member.getGroups()
groups = [i for i in groups if i not in self.AUTO_GROUPS]
groups = []
group_ids = [i for i in member.getGroups() if i not in self.AUTO_GROUPS]
# Drop groups in which the user is a transitive member
for group_id in group_ids:
group = api.group.get(group_id)
plone_group = group.getGroup()
if userId in plone_group.getMemberIds():
groups.append(group_id)
group_roles = []
for gid in groups:
group_roles.extend(self.group_roles.get(gid, []))
Expand Down
25 changes: 25 additions & 0 deletions src/collective/exportimport/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,31 @@ def test_export_members(self):
if member["username"] == TEST_USER_ID:
self.assertTrue(member["roles"], ["Member"])

def test_export_indirect_members(self):
direct = api.group.create("Direct")
indirect = api.group.create("Indirect")
api.group.add_user(group=direct, username=TEST_USER_ID)
# Make user a indirect member of the group indirect
api.group.add_user(group=direct, user=indirect)

transaction.commit()
browser = self.open_page("@@export_members")
browser.getForm(action="@@export_members").submit(name="form.submitted")
contents = browser.contents
if not browser.contents:
contents = DATA[-1]
data = json.loads(contents)
self.assertIn("groups", data.keys())
self.assertIn("members", data.keys())
members = data["members"]
membernames = [member["username"] for member in members]
self.assertIn(TEST_USER_ID, membernames)
for member in members:
if member["username"] == TEST_USER_ID:
self.assertEqual(member["username"], TEST_USER_ID)
# Only direct membership is exported
self.assertEqual(member["groups"], ["Direct"])

def test_export_defaultpages_empty(self):
browser = self.open_page("@@export_defaultpages")
browser.getForm(action="@@export_defaultpages").submit(name="form.submitted")
Expand Down
Loading