Skip to content

Commit

Permalink
Include group users in Teamraum participant Excel export
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdu-moustafa committed Jul 12, 2024
1 parent c4b7ef9 commit dcfc212
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions changes/TI-669.other
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include group users in workspace participant Excel export and ensure unique user listing. [amo]
16 changes: 16 additions & 0 deletions opengever/workspace/report.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from opengever.globalindex.browser.report import UserReport
from opengever.ogds.models.service import ogds_service
from zope.i18n import translate
from zope.i18nmessageid import MessageFactory

Expand All @@ -20,3 +21,18 @@ def filename(self):

def check_permissions(self):
pass

def fetch_users(self):
user_ids = self.extract_user_ids_from_request()
users = set()

for user_id in user_ids:
group_members = ogds_service().fetch_group(user_id)
if group_members:
users.update(group_members.users)
else:
user = ogds_service().fetch_user(user_id)
if user:
users.add(user)

return list(users)
109 changes: 109 additions & 0 deletions opengever/workspace/tests/test_workspace_participation_reporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
from ftw.builder.builder import Builder
from ftw.builder.builder import create
from ftw.testbrowser import browsing
from opengever.ogds.models.service import ogds_service
from opengever.testing import IntegrationTestCase
from openpyxl import load_workbook
from tempfile import NamedTemporaryFile


class TestWorkspaceParticipationReporter(IntegrationTestCase):

@browsing
def test_empty_users_report(self, browser):
self.login(self.administrator, browser=browser)
browser.open(view='workspace_participants_report', data={'user_ids': []})

self.assertEquals('Error You have not selected any items.',
browser.css('.portalMessage.error').text[0])

@browsing
def test_download_users_xlsx(self, browser):
"""Test downloading a user report in XLSX format.
This test verifies that the user report correctly generates an XLSX file
including individual users and users within a group.
"""
self.login(self.administrator, browser=browser)

# Create a group and add regular_user to the group
group_users = ogds_service().find_user(self.regular_user.id)
group = create(Builder('ogds_group')
.having(groupid='group1',
title='Group 1', users=[group_users, ]))

user_ids = {
'user_ids': [
self.regular_user.id,
self.administrator.id,
group.groupid
]
}

browser.open(view='workspace_participants_report', data=user_ids)
self.assertEqual(browser.status_code, 200)
with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmpfile:
tmpfile.write(browser.contents)
tmpfile.flush()
workbook = load_workbook(tmpfile.name)

task_cells = list(workbook.active.rows)

# if ror_num != 0 will remove the table header
cell_values = [[cell.value for cell in row] for row_num, row in enumerate(task_cells) if row_num != 0]
expected_values = [
[
u'kathi.barfuss',
True,
u'K\xe4thi',
u'B\xe4rfuss',
u'B\xe4rfuss K\xe4thi',
u'Staatsarchiv',
u'Arch',
u'Staatskanzlei',
u'SK',
None,
u'[email protected]',
u'[email protected]',
u'http://www.example.com',
u'012 34 56 78',
u'012 34 56 77',
u'012 34 56 76',
u'Frau',
u'Gesch\xe4ftsf\xfchrerin',
u'nix',
u'Kappelenweg 13',
u'Postfach 1234',
u'1234',
u'Vorkappelen',
u'Schweiz',
None
],
[
u'nicole.kohler',
True,
u'Nicole',
u'Kohler',
u'Kohler Nicole',
None,
None,
None,
None,
None,
u'[email protected]',
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None
]
]
self.assertSequenceEqual(expected_values, cell_values)

0 comments on commit dcfc212

Please sign in to comment.