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

Compatibility with core#2471 and core#2567 #61

Merged
merged 6 commits into from
Jun 16, 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
98 changes: 1 addition & 97 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,99 +1,3 @@
[buildout]
index = https://pypi.org/simple/
extends = https://dist.plone.org/release/5.2-latest/versions.cfg
find-links =
https://dist.plone.org/release/5.2-latest/
https://dist.plone.org/thirdparty/

parts =
instance
test
omelette
i18ndude
zopepy
update_sources
write_code_headers

eggs =
senaite.core
senaite.app.listing
senaite.app.spotlight
senaite.app.supermodel
senaite.impress
senaite.jsonapi
senaite.lims
plone.reload

extensions = mr.developer

extends = https://raw.githubusercontent.com/senaite/senaite.core/2.x/buildout.base.cfg
package-name = senaite.jsonapi

versions = versions
show-picked-versions = true

plone-user = admin:admin

develop = .
sources = sources
auto-checkout = *

[sources]
senaite.core = git https://github.com/senaite/senaite.core.git [email protected]:senaite/senaite.core.git branch=2.x
senaite.app.listing = git https://github.com/senaite/senaite.app.listing.git [email protected]:senaite/senaite.app.listing.git branch=2.x
senaite.app.supermodel = git https://github.com/senaite/senaite.app.supermodel.git [email protected]:senaite/senaite.app.supermodel.git branch=2.x
senaite.app.spotlight = git https://github.com/senaite/senaite.app.spotlight.git [email protected]:senaite/senaite.app.spotlight.git branch=2.x
senaite.impress = git https://github.com/senaite/senaite.impress.git [email protected]:senaite/senaite.impress.git branch=2.x
senaite.lims = git https://github.com/senaite/senaite.lims.git [email protected]:senaite/senaite.lims.git branch=2.x

[instance]
recipe = plone.recipe.zope2instance
http-address = 127.0.0.1:8080
user = ${buildout:plone-user}
wsgi = on
eggs =
Plone
${buildout:package-name}
${buildout:eggs}
deprecation-warnings = on
environment-vars =
zope_i18n_compile_mo_files true
zcml =

[i18ndude]
unzip = true
recipe = zc.recipe.egg
eggs = i18ndude

[write_code_headers]
recipe = collective.recipe.template
output = ${buildout:directory}/bin/write_code_headers
input = ${buildout:directory}/templates/write_code_headers.py.in
mode = 755

[update_sources]
recipe = collective.recipe.template
output = ${buildout:directory}/bin/update_sources
input = ${buildout:directory}/templates/update_sources.in
mode = 755

[test]
recipe = zc.recipe.testrunner
defaults = ['--auto-color', '--auto-progress']
eggs =
senaite.jsonapi [test]

[omelette]
recipe = collective.recipe.omelette
eggs = ${buildout:eggs}

[zopepy]
recipe = zc.recipe.egg
eggs = ${instance:eggs}
interpreter = zopepy
scripts = zopepy

[versions]
# versions need to match the versions in requirements.txt
# https://github.com/collective/buildout.plonetest/#testing-in-travis-ci-with-multiple-versions-of-plone-and-python
setuptools = 44.1.1
zc.buildout = 2.13.3
3 changes: 2 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Changelog
2.6.0 (unreleased)
------------------

- no changes yet
- #61 Compatibility with senaite.core#2567 (AnalysisCategory to DX)
- #61 Compatibility with senaite.core#2471 (Department to DX)


2.5.0 (2024-01-03)
Expand Down
8 changes: 8 additions & 0 deletions src/senaite/jsonapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,10 @@ def is_creation_allowed(portal_type, container):
if container == api.get_setup():
return False

# Do not allow the update of objects that belong to senaite_setup folder
if container == api.get_senaite_setup():
return False

# Check if the portal_type is allowed in the container
container_info = container.getTypeInfo()
if container_info.filter_content_types:
Expand Down Expand Up @@ -1122,6 +1126,10 @@ def is_update_allowed(obj):
if parent == api.get_setup():
return False

# Do not allow the update of objects that belong to senaite_setup folder
if parent == api.get_senaite_setup():
return False

# Look for an update-specific adapter for this object
adapter = queryAdapter(obj, IUpdate)
if adapter:
Expand Down
6 changes: 6 additions & 0 deletions src/senaite/jsonapi/datamanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ def set(self, name, value, **kw):
if not self.can_write():
raise Unauthorized("You are not allowed to modify this content")

# prioritize setters over fields
setter = "set{}".format(name.capitalize())
setter = getattr(self.context, setter, None)
if setter:
return setter(value)

# fetch the field by name
field = api.get_field(self.context, name)

Expand Down
16 changes: 8 additions & 8 deletions src/senaite/jsonapi/tests/doctests/create.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,31 @@ Create a Department
~~~~~~~~~~~~~~~~~~~

>>> data = {"portal_type": "Department",
... "DepartmentID": "MB",
... "parent_path": api.get_path(setup.bika_departments),
... "DepartmentID": "MB",
... "parent_path": api.get_path(portal.setup.departments),
... "title": "Microbiology",
... "Manager": api.get_uid(lab_contact)}
>>> department = create(data)
>>> department.Title()
'Microbiology'
>>> api.get_parent(department)
<Departments at /plone/bika_setup/bika_departments>
<Departments at /plone/setup/departments>


Create an Analysis Category
~~~~~~~~~~~~~~~~~~~~~~~~~~~

>>> data = {"portal_type": "AnalysisCategory",
... "parent_path": api.get_path(setup.bika_analysiscategories),
... "parent_path": api.get_path(portal.setup.analysiscategories),
... "title": "Microbiology identification",
... "Department": api.get_uid(department)}
>>> category = create(data)
>>> category.Title()
'Microbiology identification'
>>> api.get_parent(category)
<AnalysisCategories at /plone/bika_setup/bika_analysiscategories>
<AnalysisCategories at /plone/setup/analysiscategories>
>>> category.getDepartment()
<Department at /plone/bika_setup/bika_departments/department-1>
<Department at /plone/setup/departments/department-1>


Create an Analysis Service
Expand All @@ -257,7 +257,7 @@ Create an Analysis Service
>>> sal.getAccredited()
True
>>> sal.getCategory()
<AnalysisCategory at /plone/bika_setup/bika_analysiscategories/analysiscategory-1>
<AnalysisCategory at /plone/setup/analysiscategories/analysiscategory-1>

>>> data = {"portal_type": "AnalysisService",
... "parent_path": api.get_path(setup.bika_analysisservices),
Expand All @@ -276,7 +276,7 @@ Create an Analysis Service
>>> ecoli.getPrice()
'15.00'
>>> ecoli.getCategory()
<AnalysisCategory at /plone/bika_setup/bika_analysiscategories/analysiscategory-1>
<AnalysisCategory at /plone/setup/analysiscategories/analysiscategory-1>

Creating a Sample
~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion src/senaite/jsonapi/tests/doctests/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ We get a 401 error if we try to update an object from inside portal root:

We get a 401 error if we try to update an object from inside setup folder:

>>> cats_uid = api.get_uid(api.get_setup().bika_analysiscategories)
>>> cats_uid = api.get_uid(portal.setup.analysiscategories)
>>> data = {"title": "My Analysis Categories folder",
... "uid": cats_uid,}
>>> post("update", data)
Expand Down
4 changes: 2 additions & 2 deletions src/senaite/jsonapi/tests/doctests/users.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ And for each user, the roles and groups are displayed:
As well as other properties:

>>> sorted(analyst.keys())
[u'api_url', u'authenticated', u'description', u'email', ...]
[u'api_url', u'authenticated', u'email', ...]

Get current user
~~~~~~~~~~~~~~~~
Expand All @@ -74,7 +74,7 @@ Current user can also be retrieved easily:
and includes all properties too:

>>> sorted(current.keys())
[u'api_url', u'authenticated', u'description', u'email',...u'groups',...u'roles'...]
[u'api_url', u'authenticated', u'email',...u'groups',...u'roles'...]

Get a single user
~~~~~~~~~~~~~~~~~
Expand Down
Loading