Skip to content

Commit

Permalink
Merge pull request #7992 from 4teamwork/amo/TI-669/extract_workspace_…
Browse files Browse the repository at this point in the history
…group_participants_excel_export

Include group users in Teamraum participant Excel export
  • Loading branch information
Abdu-moustafa authored Jul 12, 2024
2 parents 2425ba2 + dcfc212 commit 5c9fdc5
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 2 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]
10 changes: 8 additions & 2 deletions opengever/globalindex/browser/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def check_permissions(self):
if not is_administrator():
raise Unauthorized

def __call__(self):
self.check_permissions()
def extract_user_ids_from_request(self):
user_ids = self.request.form.get("user_ids")

if not user_ids:
Expand All @@ -105,10 +104,17 @@ def __call__(self):
else:
return self.request.RESPONSE.redirect(
self.context.absolute_url())
return user_ids

def fetch_users(self):
user_ids = self.extract_user_ids_from_request()
users = [ogds_service().fetch_user(user_id) for user_id in user_ids]
users = [user for user in users if user]
return users

def __call__(self):
self.check_permissions()
users = self.fetch_users()
reporter = XLSReporter(
self.context.REQUEST,
self.columns(),
Expand Down
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 5c9fdc5

Please sign in to comment.