Skip to content

Commit

Permalink
Merge branch 'main' into openpyxl3
Browse files Browse the repository at this point in the history
  • Loading branch information
reinhardt committed Jan 13, 2025
2 parents 51c4f44 + 7ab8dff commit 0b9e6f9
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 57 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ jobs:
strategy:
matrix:
config:
- ["Py3.8-Plone5.2", "3.8", "5.2"]
- ["Py3.8-Plone6.0", "3.8", "6.0"]
- ["Py3.8-Plone6.0", "3.8"]
runs-on: ubuntu-latest
name: ${{ matrix.config[0] }}
steps:
Expand All @@ -42,17 +41,13 @@ jobs:
run: |
sudo locale-gen en_US.UTF-8 nl_NL@euro
python -m venv .
ln -s requirements-${{ matrix.config[2] }}.txt requirements.txt
bin/pip install -r requirements.txt
ln -s versions-${{ matrix.config[2] }}.cfg versions.cfg
bin/buildout -c .github.cfg
- name: Pre commit
uses: pre-commit/[email protected]
if: ${{ matrix.config[2] == '5.2' }}
- name: Code Analysis
run: |
bin/code-analysis
if: ${{ matrix.config[2] == '5.2' }}
- name: Test
run: |
bin/coverage run bin/test -s osha.oira
Expand Down
4 changes: 3 additions & 1 deletion docs/changes.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
Changelog
=========

10.0.6 (unreleased)
10.1.0 (unreleased)
-------------------

- Support openpyxl 3.x
[reinhardt]
- Remove support and testing infrastructure for Plone 5.2.
[thet]


10.0.5 (2024-12-09)
Expand Down
1 change: 0 additions & 1 deletion requirements-5.2.txt

This file was deleted.

File renamed without changes.
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os


version = "10.0.6.dev0"
version = "10.1.0.dev0"

setup(
name="osha.oira",
Expand All @@ -18,7 +18,6 @@
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Plone",
"Framework :: Plone :: 5.2",
"Framework :: Plone :: 6.0",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Programming Language :: Python :: 3",
Expand Down
15 changes: 13 additions & 2 deletions src/osha/oira/client/browser/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ def validate_ticket(self):
if ticket != expected:
raise Unauthorized("Invalid ticket")

@property
def page(self):
return int(self.request.get("page", "1"))

@property
def page_limit(self):
return int(self.request.get("page_limit", "10"))

def __call__(self):
"""Returns a json meant to be consumed by pat-autosuggest.
Expand Down Expand Up @@ -178,7 +186,8 @@ def results(self):
user = api.user.get_current()

if (
not q or q in all_users["id"] or q in all_users["text"].lower()
self.page == 1
and (not q or q in all_users["id"] or q in all_users["text"].lower())
) and api.user.has_permission("Manage portal"):
results.append(all_users)

Expand All @@ -198,7 +207,9 @@ def results(self):
else:
query["path"] = "/".join((query["path"], q))

brains = self.filter_permission(catalog(**query), query, user)
b_start = (self.page - 1) * self.page_limit
brains = catalog(**query, b_start=b_start, b_size=self.page_limit)
brains = self.filter_permission(brains, query, user)

for brain in brains:
results.extend(self._get_mailing_lists_for(brain))
Expand Down
58 changes: 58 additions & 0 deletions src/osha/oira/client/tests/test_mailing_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,64 @@ def test_mailing_lists(self):
results,
)

def test_mailing_lists_batching(self):
request = self.request.clone()
request.form = {"user_id": "admin", "page_limit": "2"}
with mock.patch.object(
MailingListsJson,
"addresses_view",
return_value=GroupToAddresses(context=self.portal.client, request=request),
):
view = MailingListsJson(context=self.portal.client, request=request)
results = view.results

# Result = 3, because the "general" mailing list is always added
# on page one for admin users.
self.assertEqual(len(results), 3)
self.assertEqual(
results[0],
{"id": "general|QWxsIHVzZXJz", "text": "All users [0 subscribers]"},
)
self.assertEqual(
results[1],
{
"id": "nl/test/second-survey|U2Vjb25kIFN1cnZleQ==",
"text": "Second Survey (nl/test/second-survey) [0 subscribers]",
},
)
self.assertEqual(
results[2],
{
"id": "nl/ict/software-development|U29mdHdhcmUgZGV2ZWxvcG1lbnQ=",
"text": "Software development (nl/ict/software-development) [0 subscribers]", # noqa: E501
},
)

request.form = {"user_id": "admin", "page_limit": "2", "page": "2"}
with mock.patch.object(
MailingListsJson,
"addresses_view",
return_value=GroupToAddresses(context=self.portal.client, request=request),
):
view = MailingListsJson(context=self.portal.client, request=request)
results = view.results

self.assertEqual(len(results), 2)
self.assertEqual(
results[0],
{
"id": "nl-nl|VGhlIE5ldGhlcmxhbmRzIChubCk=",
"text": "The Netherlands (nl) [0 subscribers]",
},
)
self.assertEqual(
results[1],
{
"id": "nl-fr|VGhlIE5ldGhlcmxhbmRzIChmcik=",
"text": "The Netherlands (fr) [0 subscribers]",
},
)

def test_group_to_addresses(self):
user = Account(loginname="[email protected]", password="secret")
Session.add(user)
Expand Down
45 changes: 0 additions & 45 deletions versions-5.2.cfg

This file was deleted.

File renamed without changes.

0 comments on commit 0b9e6f9

Please sign in to comment.