Skip to content

Commit 534bc3c

Browse files
authored
Compatibility with core#2835 (display Shipments in navbar) (#39)
* Compatibility with core#2835 * Changelog
1 parent b661e75 commit 534bc3c

7 files changed

Lines changed: 156 additions & 25 deletions

File tree

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
2.0.0 (Unreleased)
55
------------------
66

7+
- #39 Compatibility with core#2835 (display Shipments in navbar)
78
- #38 Fix referred samples do not transition to "received at reference"
89
- #37 Allow to set the default sorting order for samples in outbound shipments
910
- #36 Enable configuration for notifying about retested and hidden analyses

src/senaite/referral/profiles/default/metadata.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
dependencies before installing this add-on own profile.
77
-->
88
<metadata>
9-
<version>2009</version>
9+
<version>2010</version>
1010

1111
<!-- Be sure to install the following dependencies if not yet installed -->
1212
<dependencies>

src/senaite/referral/setuphandlers.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
from collections import OrderedDict
2222

23+
from bika.lims import api
2324
from bika.lims.api import UID_CATALOG
24-
from plone.registry.interfaces import IRegistry
2525
from senaite.core.api.workflow import update_workflow
2626
from senaite.core.registry import get_registry_record
2727
from senaite.core.registry import set_registry_record
@@ -37,7 +37,6 @@
3737
from senaite.referral.config import PRODUCT_NAME
3838
from senaite.referral.config import PROFILE_ID
3939
from senaite.referral.config import UNINSTALL_ID
40-
from zope.component import getUtility
4140

4241
CATALOGS = (
4342
InboundSampleCatalog,
@@ -60,11 +59,6 @@
6059
("shipments", "Shipments", "ShipmentFolder"),
6160
]
6261

63-
NAVTYPES = [
64-
"ExternalLaboratoryFolder",
65-
"ShipmentFolder",
66-
]
67-
6862
WORKFLOWS_TO_UPDATE = {
6963
SAMPLE_WORKFLOW: {
7064
"states": {
@@ -215,9 +209,6 @@ def setup_handler(context):
215209
# Portal folders
216210
add_portal_folders(portal)
217211

218-
# Configure visible navigation items
219-
setup_navigation_types(portal)
220-
221212
# Setup worlflows
222213
setup_workflows(portal)
223214

@@ -278,21 +269,40 @@ def add_portal_folders(portal):
278269
logger.info("Adding portal folders ...")
279270
for folder_id, folder_name, portal_type in PORTAL_FOLDERS:
280271
if portal.get(folder_id) is None:
281-
portal.invokeFactory(portal_type, folder_id, title=folder_name)
272+
logger.info("Adding folder: {}".format(folder_id))
273+
params = dict(id=folder_id, title=folder_name)
274+
api.create(portal, portal_type, **params)
275+
276+
# make folders visible in the navigation bar
277+
for folder_id, folder_name, portal_type in PORTAL_FOLDERS:
278+
obj = portal.get(folder_id)
279+
if obj is not None:
280+
display_in_nav(obj)
282281

283282
logger.info("Adding portal folders [DONE]")
284283

285284

286-
def setup_navigation_types(portal):
287-
"""Add additional types for navigation
285+
def display_in_nav(obj):
286+
"""Makes an object to be displayed in the navigation bar
288287
"""
289-
registry = getUtility(IRegistry)
290-
key = "plone.displayed_types"
291-
display_types = registry.get(key, ())
292-
293-
new_display_types = set(display_types)
294-
new_display_types.update(NAVTYPES)
295-
registry[key] = tuple(new_display_types)
288+
portal_type = api.get_portal_type(obj)
289+
290+
# remove from senaite setup's sidebar_skip_types
291+
setup = api.get_senaite_setup()
292+
skip = setup.getSidebarSkipTypes()
293+
if skip and portal_type in skip:
294+
skip = tuple(pt for pt in skip if pt != portal_type)
295+
setup.setSidebarSkipTypes(skip)
296+
297+
# if a root folder, add to senaite setup's sidebar_folders
298+
setup = api.get_senaite_setup()
299+
portal = api.get_portal()
300+
if api.get_parent(obj) == portal:
301+
obj_id = api.get_id(obj)
302+
folders = setup.getSidebarFolders()
303+
if obj_id not in folders:
304+
folders += (obj_id, )
305+
setup.setSidebarFolders(folders)
296306

297307

298308
def setup_workflows(portal):

src/senaite/referral/subscribers/upgrade.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from senaite.referral import PRODUCT_NAME
2424
from senaite.referral.setuphandlers import setup_catalogs
2525
from senaite.referral.setuphandlers import setup_workflows
26-
from senaite.referral.setuphandlers import setup_navigation_types
2726

2827

2928
def afterUpgradeStepHandler(event): # noqa CamelCase
@@ -45,7 +44,4 @@ def afterUpgradeStepHandler(event): # noqa CamelCase
4544
# Setup workflows
4645
setup_workflows(portal)
4746

48-
# Setup navigation tpyes
49-
setup_navigation_types(portal)
50-
5147
logger.info("Run {}.afterUpgradeStepHandler [DONE]".format(PRODUCT_NAME))
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Referral Navigation Bar Visibility
2+
===================================
3+
4+
This test ensures that the Shipments and External Labs folders are visible in
5+
the navigation bar after installation, in accordance with the new sidebar
6+
navigation system introduced in senaite.core.
7+
8+
Running this test from the buildout directory:
9+
10+
bin/test -m senaite.referral -t ReferralNavigation
11+
12+
13+
Test Setup
14+
..........
15+
16+
Needed Imports:
17+
18+
>>> from bika.lims import api
19+
>>> from plone.app.testing import setRoles
20+
>>> from plone.app.testing import TEST_USER_ID
21+
22+
Variables:
23+
24+
>>> portal = self.portal
25+
>>> request = self.request
26+
>>> setup = api.get_senaite_setup()
27+
28+
Assign default roles for the user to test with:
29+
30+
>>> setRoles(portal, TEST_USER_ID, ['LabManager',])
31+
32+
33+
Shipments Folder Navigation Visibility
34+
---------------------------------------
35+
36+
After installation, the Shipments folder should be visible in the navigation
37+
bar. This is configured through two mechanisms:
38+
39+
1. The portal type "ShipmentFolder" should NOT be in SENAITE Setup's
40+
sidebar_skip_types (types in this list are excluded from the sidebar):
41+
42+
>>> sidebar_skip_types = setup.getSidebarSkipTypes()
43+
>>> sidebar_skip_types is not None
44+
True
45+
>>> "ShipmentFolder" not in sidebar_skip_types
46+
True
47+
48+
2. Since the shipments folder is a root folder (direct child of portal), its
49+
ID should be in SENAITE Setup's sidebar_folders:
50+
51+
>>> sidebar_folders = setup.getSidebarFolders()
52+
>>> sidebar_folders is not None
53+
True
54+
>>> "shipments" in sidebar_folders
55+
True
56+
57+
Verify the shipments folder exists and is properly configured:
58+
59+
>>> shipments = portal.shipments
60+
>>> shipments is not None
61+
True
62+
63+
>>> api.get_portal_type(shipments)
64+
'ShipmentFolder'
65+
66+
>>> api.get_parent(shipments) == portal
67+
True
68+
69+
70+
External Labs Folder Navigation Visibility
71+
--------------------------------------------
72+
73+
After installation, the External Labs folder should be visible in the
74+
navigation bar:
75+
76+
1. The portal type "ExternalLaboratoryFolder" should NOT be in SENAITE Setup's
77+
sidebar_skip_types:
78+
79+
>>> "ExternalLaboratoryFolder" not in sidebar_skip_types
80+
True
81+
82+
2. Since the external_labs folder is a root folder, its ID should be in
83+
SENAITE Setup's sidebar_folders:
84+
85+
>>> "external_labs" in sidebar_folders
86+
True
87+
88+
Verify the external_labs folder exists and is properly configured:
89+
90+
>>> external_labs = portal.external_labs
91+
>>> external_labs is not None
92+
True
93+
94+
>>> api.get_portal_type(external_labs)
95+
'ExternalLaboratoryFolder'
96+
97+
>>> api.get_parent(external_labs) == portal
98+
True

src/senaite/referral/upgrade/v02_00_000.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from senaite.referral.catalog import INBOUND_SAMPLE_CATALOG
3030
from senaite.referral.catalog import SHIPMENT_CATALOG
3131
from senaite.referral.config import PRODUCT_NAME as product
32+
from senaite.referral.setuphandlers import display_in_nav
33+
from senaite.referral.setuphandlers import PORTAL_FOLDERS
3234
from senaite.referral.setuphandlers import setup_ajax_transitions
3335
from senaite.referral.setuphandlers import setup_workflows
3436
from senaite.referral.utils import get_notify_unrequested
@@ -205,3 +207,15 @@ def setup_outbound_samples_order(tool):
205207
setup = portal.portal_setup
206208
setup.runImportStepFromProfile(profile, "plone.app.registry")
207209
logger.info("Setup order of outbound samples [DONE]")
210+
211+
212+
def display_folders_navbar(tool):
213+
"""Displays Shipments and External Labs folders in the navigation bar
214+
"""
215+
logger.info("Display folders in navigation bar ...")
216+
portal = api.get_portal()
217+
folders = [portal.get(folder[0]) for folder in PORTAL_FOLDERS]
218+
for folder in folders:
219+
if folder is not None:
220+
display_in_nav(folder)
221+
logger.info("Display folders in navigation bar [DONE]")

src/senaite/referral/upgrade/v02_00_000.zcml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
xmlns="http://namespaces.zope.org/zope"
33
xmlns:genericsetup="http://namespaces.zope.org/genericsetup">
44

5+
<genericsetup:upgradeStep
6+
title="Display Shipments and External Labs in the navbar"
7+
description="
8+
This upgrade step makes the product compatible with senaite.core#2835
9+
by adding Shipments and External Labs folders to the setup field
10+
'Sidebar displayed portal types', thereby displaying them in the
11+
left-hand navigation bar."
12+
source="2009"
13+
destination="2010"
14+
handler=".v02_00_000.display_folders_navbar"
15+
profile="senaite.referral:default"/>
16+
517
<genericsetup:upgradeStep
618
title="SENAITE.REFERRAL 2.0.0: Setup outbound samples sorting config"
719
description="Setup outbound samples sorting config"

0 commit comments

Comments
 (0)