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

Slots #1063

Open
wants to merge 118 commits into
base: main
Choose a base branch
from
Open

Slots #1063

Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
24b3649
WIP
tiberiuichim Feb 4, 2021
8aeec3c
Add slot_block_ids index
tiberiuichim Feb 4, 2021
0302833
Improve patch service
tiberiuichim Feb 4, 2021
85b9fa7
WIP on deserializers
tiberiuichim Feb 4, 2021
3bf47f6
WIP on deserializers
tiberiuichim Feb 4, 2021
f17d4d1
WIP
tiberiuichim Feb 5, 2021
98e009d
Add slots engine unittest
tiberiuichim Feb 6, 2021
34bc973
Improve test formatting
tiberiuichim Feb 6, 2021
8401e0c
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Feb 6, 2021
02223e0
More tests on slot engine crutch
tiberiuichim Feb 6, 2021
68d534c
Add VolatileSmartField
tiberiuichim Feb 6, 2021
901e3a0
WIP
tiberiuichim Feb 6, 2021
09630a2
Add another way of treating reordered slot fills
tiberiuichim Feb 7, 2021
48f3865
Add save_data_to_slot to slot engine
tiberiuichim Feb 7, 2021
ef71439
Move SlotsEngine to .slots, tweak names
tiberiuichim Feb 7, 2021
3af5692
Rename ISlotsStorage -> ISlotStorage
tiberiuichim Feb 7, 2021
4a479be
Move zca registrations to slots.zcml; more tests
tiberiuichim Feb 8, 2021
44747ad
More tests
tiberiuichim Feb 8, 2021
3b1540c
Add discovery of slots, add slot storage serializer
tiberiuichim Feb 8, 2021
6fd2006
Add initial test of slot service
tiberiuichim Feb 8, 2021
9b087c5
Fix slot serialization service
tiberiuichim Feb 8, 2021
6ee8e76
Fix slot serializer
tiberiuichim Feb 8, 2021
870881d
Add configlet and control panel for content slots
tiberiuichim Feb 8, 2021
62676e4
Shuffle events code
tiberiuichim Feb 9, 2021
65f02ff
Add get_editable_slots implementation
tiberiuichim Feb 9, 2021
a8a0d98
Pass editable status in @slots endpoints
tiberiuichim Feb 9, 2021
53953af
Fix tests
tiberiuichim Feb 9, 2021
58ccfbc
Fix tests
tiberiuichim Feb 9, 2021
ffa86ba
Add security tests
tiberiuichim Feb 9, 2021
84b5779
Add security tests
tiberiuichim Feb 9, 2021
f56b43a
WIP on deserializer
tiberiuichim Feb 10, 2021
6e27022
Rename slot_blocks -> blocks, slot_blocks_layout -> blocks_layout, as…
tiberiuichim Feb 10, 2021
895f5ad
Visual formatting
tiberiuichim Feb 10, 2021
15305b3
Visual formatting
tiberiuichim Feb 10, 2021
cdc54c3
Move interfaces to .slots package
tiberiuichim Feb 10, 2021
b4693a3
Separate deserializer test
tiberiuichim Feb 10, 2021
15809aa
Fix deserializer
tiberiuichim Feb 10, 2021
3505931
Fix deserializer
tiberiuichim Feb 10, 2021
b70875e
Fix deserializer
tiberiuichim Feb 10, 2021
e23c68d
Add another test
tiberiuichim Feb 10, 2021
afae726
Fix indexing, test remove of block from child layout
tiberiuichim Feb 10, 2021
42f007d
Fix indexing, test remove of block from child layout
tiberiuichim Feb 10, 2021
6344b64
WIP on deserializers
tiberiuichim Feb 10, 2021
ee327f3
Fix deserializer + tests
tiberiuichim Feb 11, 2021
fb0e637
Fix tests; don't use an index to keep block sanity, instead resolve i…
tiberiuichim Feb 11, 2021
03c1962
Remove block removed events and associated catalog index, they're not…
tiberiuichim Feb 11, 2021
cd90fba
Run black
tiberiuichim Feb 11, 2021
a28ea4e
Fix slot
tiberiuichim Feb 12, 2021
790d571
Simplify test content creation
tiberiuichim Feb 12, 2021
bea4d76
Add skip csrf protection
tiberiuichim Feb 14, 2021
1922a9d
Use edit status in serializer
tiberiuichim Feb 14, 2021
dd20be7
Use edit status in serializer
tiberiuichim Feb 14, 2021
063f4d3
Fix deserializer, don't trigger ObjectModifiedEvent, as it needs its …
tiberiuichim Feb 15, 2021
24be48d
Fix block transformer for slots
tiberiuichim Feb 16, 2021
14fbd04
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Mar 8, 2021
216f867
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Mar 19, 2021
d420b87
Run black
tiberiuichim Mar 19, 2021
8cfc7e2
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Mar 29, 2021
c3ae3db
Add can_manage_slots info to response
tiberiuichim Mar 29, 2021
923f7ad
Fix a bug in deleting slot fills
tiberiuichim Mar 29, 2021
495380e
Fix another delete
tiberiuichim Mar 30, 2021
08cd548
Merge master
tiberiuichim May 25, 2021
b54a298
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Jun 7, 2021
49fce60
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Jul 2, 2021
2ee8de7
Add transaction doom
tiberiuichim Jul 2, 2021
fc8d000
Add full parameter
tiberiuichim Jul 2, 2021
28cab5d
Fix deserializer
tiberiuichim Jul 2, 2021
e00ed37
Add block parent
tiberiuichim Jul 2, 2021
401a7ea
Fix parameters
tiberiuichim Jul 2, 2021
d6583c0
Improve block_parent implementation
tiberiuichim Jul 2, 2021
e6bd47b
Pass blocks when full is true
tiberiuichim Jul 2, 2021
cfae76c
Add info about attributes
tiberiuichim Jul 5, 2021
f2cdd56
Fix _v_ handling; send a _v_original to the frontend
tiberiuichim Jul 6, 2021
df11630
WIP
tiberiuichim Jul 6, 2021
8ea93d8
Add test for block hiding
tiberiuichim Jul 8, 2021
30c2f99
Fix sameAs handling
tiberiuichim Jul 8, 2021
527c621
Fix some tests
tiberiuichim Jul 8, 2021
00f5159
More tests, enable the _v_original as it's needed in frontend when 'u…
tiberiuichim Jul 8, 2021
4061471
Fix some tests, run black
tiberiuichim Jul 8, 2021
33a0d8f
Fix deserializer test
tiberiuichim Jul 8, 2021
4ac03ea
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Jul 8, 2021
3c6cfa4
Fix serializer test
tiberiuichim Jul 8, 2021
4964317
Fix one test in test_addons
tiberiuichim Jul 8, 2021
f729ae0
Add upgrade handler
tiberiuichim Jul 8, 2021
8fb791d
Remove unused import
tiberiuichim Jul 8, 2021
4ce5fde
Fix _v_ handling
tiberiuichim Jul 10, 2021
8aea2f9
Fix deserializing when showing a hidden parent
tiberiuichim Jul 10, 2021
fa3c80f
Fix parent if None
tiberiuichim Jul 10, 2021
222043b
Run black, localize test urls
tiberiuichim Jul 10, 2021
ecf0788
Add some test descriptions
tiberiuichim Jul 11, 2021
d8eaaae
Add a test for third-hand inherited slots
tiberiuichim Jul 11, 2021
211420e
Make the test more clear
tiberiuichim Jul 11, 2021
1bfe28f
WIP on test
tiberiuichim Jul 11, 2021
79eb618
Fix deep inheritance test
tiberiuichim Jul 12, 2021
9eb4403
Don't include _v_inherit everywhere; don't fail on deleted inherited …
tiberiuichim Jul 12, 2021
66e7687
WIP on new traversal for slots
tiberiuichim Jul 28, 2021
493f345
Add missing file
tiberiuichim Jul 28, 2021
c5723f6
WIP on new traversal for slots
tiberiuichim Jul 28, 2021
59c3644
Adjust tests for new slots serialized ids
tiberiuichim Jul 29, 2021
f77f5a4
Run zpretty
tiberiuichim Jul 29, 2021
b484298
Run black
tiberiuichim Jul 29, 2021
72aa841
Remove print statement
tiberiuichim Jul 29, 2021
1d524f3
Merge pull request #1187 from plone/slots_traversing
tiberiuichim Jul 29, 2021
6eabb69
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Jul 29, 2021
16839b3
Pass expanders in @slots endpoint
tiberiuichim Jul 29, 2021
29a5a63
Run black
tiberiuichim Jul 31, 2021
7800daa
Fix tests
tiberiuichim Jul 31, 2021
e4aa1e3
Merge master
tiberiuichim Oct 17, 2021
378e5a1
Pass readOnly
tiberiuichim Oct 26, 2021
0e34a87
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Nov 3, 2021
7695215
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Nov 11, 2021
850cf31
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Nov 27, 2021
544f614
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Mar 5, 2022
79f72da
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim May 17, 2022
9b93908
Merge branch 'master' into slots
tiberiuichim Jul 23, 2022
3f6cf2a
Merge remote-tracking branch 'origin/master' into slots
tiberiuichim Aug 2, 2022
be413c1
Merge from 'master'
laszlocseh Jul 27, 2023
af48f1f
Merge remote-tracking branch 'origin/main' into slots
tiberiuichim Oct 11, 2023
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
55 changes: 36 additions & 19 deletions src/plone/restapi/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,101 +1,118 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone.restapi">
i18n_domain="plone.restapi"
>

<i18n:registerTranslations directory="locales" />

<include package="plone.behavior" file="meta.zcml"/>
<include package="plone.rest" file="meta.zcml"/>
<include
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiberiuichim do you have a special formatter in your IDE? We shouldn't mix code cleanups and complex PRs together. This makes it a lot harder to do a proper review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tisto I use collective zpretty, which has a special mode for zcml. I guess we could integrate zpretty in a separate PR and run it on all zcml files?

zpretty [-h] [--encoding ENCODING] [-i] [-x] [-z] [file ...]

positional arguments:
  file                 The list of files to prettify (defaults to stdin)

optional arguments:
  -h, --help           show this help message and exit
  --encoding ENCODING  The file encoding (defaults to utf8)
  -i, --inplace        Format files in place (overwrite existing file)
  -x, --xml            Threat the input file(s) as XML
  -z, --zcml           Threat the input file(s) as XML. Follow the ZCML
                       styleguide

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiberiuichim yeah. please create a separate PR for this. Is zpretty adopted in Plone core @ale-rt? Can it run as a pre-commit hook as part of p.r.codeanalysis and in a CI mode to check for violation? If we adopt a tool we should either go all in or not use it at all IMHO. Adopting it a bit won't really help much.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @tisto I missed the comment before.

zpretty is not adopted in Plone core.

Is was thinking about plugging it with https://pre-commit.com/ which is what I use recently.

Note that I recently worked quite a lot on the zcml part, especially in collective/zpretty#32.
I will probably do a release nowish.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are interested zpretty 2.1.0 is out.
The nice thing about that is IMO That the attribute order is in sync with the function signature, see this example for the CORSPolicy directive
https://github.com/collective/zpretty/blob/e1ef596cfd1edea4113423ce5ef4467c0506c650/zpretty/zcml.py#L47-L57

package="plone.behavior"
file="meta.zcml"
/>
<include
package="plone.rest"
file="meta.zcml"
/>

<include package="plone.behavior" />
<include package="plone.rest" />
<include package="plone.schema" />
<include file="indexers.zcml" />

<five:registerPackage package="." initialize=".initialize" />
<five:registerPackage
package="."
initialize=".initialize"
/>

<include file="permissions.zcml" />

<genericsetup:registerProfile
name="default"
title="plone.restapi"
directory="profiles/default"
description="RESTful hypermedia API for Plone."
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/default"
/>

<genericsetup:registerProfile
name="testing"
title="plone.restapi testing"
directory="profiles/testing"
description="Adds sample content types for testing"
provides="Products.GenericSetup.interfaces.EXTENSION"
for="Products.CMFPlone.interfaces.ITestCasePloneSiteRoot"
directory="profiles/testing"
/>

<genericsetup:registerProfile
name="performance"
title="plone.restapi performance testing"
directory="profiles/performance"
description="Adds sample content for performance testing"
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/performance"
/>

<genericsetup:registerProfile
name="blocks"
title="Volto Blocks"
directory="profiles/blocks"
description="Enables blocks on the Document content type"
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/blocks"
/>

<!-- Register "various" import step -->
<genericsetup:importStep
name="plone.restapi"
title="plone.restapi special import handlers"
description=""
handler="plone.restapi.setuphandlers.import_various"
/>
name="plone.restapi"
title="plone.restapi special import handlers"
description=""
handler="plone.restapi.setuphandlers.import_various"
/>

<genericsetup:registerProfile
name="uninstall"
title="plone.restapi"
directory="profiles/uninstall"
description="RESTful hypermedia API for Plone - Uninstall"
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/uninstall"
/>

<include package="plone.rest" file="configure.zcml" />
<include
package="plone.rest"
file="configure.zcml"
/>
<include package=".services" />
<include package=".serializer" />
<include package=".deserializer" />
<include package=".types" />
<include package=".search" />
<include package=".slots" />

<include package=".upgrades" />

<configure zcml:condition="installed plone.app.dexterity">

<include package="plone.behavior" file="meta.zcml"/>
<include
package="plone.behavior"
file="meta.zcml"
/>

<plone:behavior
name="volto.blocks"
title="Blocks"
description="Enables Volto Blocks support"
provides=".behaviors.IBlocks"
/>
/>

</configure>

<utility
factory=".setuphandlers.HiddenProfiles"
name="plone.restapi"
provides="Products.CMFPlone.interfaces.INonInstallable"
name="plone.restapi"
/>

</configure>
7 changes: 4 additions & 3 deletions src/plone/restapi/controlpanels/registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from zope.component import adapter
from zope.interface import Interface
from plone.restapi.controlpanels import RegistryConfigletPanel
from Products.CMFPlone.interfaces.controlpanel import IDateAndTimeSchema
from Products.CMFPlone.interfaces.controlpanel import IEditingSchema
from Products.CMFPlone.interfaces.controlpanel import IImagingSchema
Expand All @@ -11,7 +10,9 @@
from Products.CMFPlone.interfaces.controlpanel import ISecuritySchema
from Products.CMFPlone.interfaces.controlpanel import ISiteSchema
from Products.CMFPlone.interfaces.controlpanel import ISocialMediaSchema
from plone.restapi.controlpanels import RegistryConfigletPanel
from zope.component import adapter
from zope.interface import Interface


try:
from plone.i18n.interfaces import ILanguageSchema
Expand Down
20 changes: 20 additions & 0 deletions src/plone/restapi/deserializer/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,26 @@ def __call__(self, block):
return block


@adapter(IBlocks, IBrowserRequest)
@implementer(IBlockFieldDeserializationTransformer)
class VolatileSmartField(object):
"""When deserializing block values, delete all block fields that start with `_v_`"""

order = float("inf")
block_type = None

def __init__(self, context, request):
self.context = context
self.request = request

def __call__(self, block):
for k, v in block.items():
if k.startswith("_v_"):
del block[k]

return block


@adapter(IBlocks, IBrowserRequest)
@implementer(IBlockFieldDeserializationTransformer)
class ResolveUIDDeserializer(ResolveUIDDeserializerBase):
Expand Down
73 changes: 52 additions & 21 deletions src/plone/restapi/deserializer/configure.zcml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone.restapi">
i18n_domain="plone.restapi"
>

<adapter factory=".site.DeserializeSiteRootFromJson" />
<adapter factory=".dxcontent.DeserializeFromJson" />
Expand All @@ -19,25 +20,55 @@
<adapter factory=".dxfields.RichTextFieldDeserializer" />
<adapter factory=".blocks.BlocksJSONFieldDeserializer" />

<subscriber factory=".blocks.TextBlockDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>
<subscriber factory=".blocks.HTMLBlockDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>
<subscriber factory=".blocks.ImageBlockDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>
<subscriber factory=".blocks.ResolveUIDDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>
<subscriber factory=".blocks.TextBlockDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>
<subscriber factory=".blocks.HTMLBlockDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>
<subscriber factory=".blocks.ImageBlockDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>
<subscriber factory=".blocks.ResolveUIDDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"/>

<adapter factory=".local_roles.DeserializeFromJson"
name="local_roles"/>
<adapter factory=".slots.SlotDeserializer" />
<adapter factory=".slots.SlotDeserializerRoot" />
<adapter factory=".slots.SlotsDeserializer" />
<adapter
factory=".slots.SlotsDeserializerRoot"
provides="plone.restapi.interfaces.IDeserializeFromJson"
/>

<subscriber
factory=".blocks.TextBlockDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.HTMLBlockDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.ImageBlockDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.ResolveUIDDeserializer"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.TextBlockDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.HTMLBlockDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.ImageBlockDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.ResolveUIDDeserializerRoot"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>
<subscriber
factory=".blocks.VolatileSmartField"
provides="plone.restapi.interfaces.IBlockFieldDeserializationTransformer"
/>

<adapter
factory=".local_roles.DeserializeFromJson"
name="local_roles"
/>

<configure zcml:condition="installed z3c.relationfield">
<adapter factory=".relationfield.RelationChoiceFieldDeserializer" />
Expand All @@ -51,7 +82,7 @@
<configure zcml:condition="installed Products.Archetypes.atapi">
<adapter factory=".atcontent.DeserializeFromJson" />
<configure zcml:condition="installed plone.app.blob">
<adapter factory=".atfields.BlobFieldDeserializer" />
<adapter factory=".atfields.BlobFieldDeserializer" />
</configure>
<adapter factory=".atfields.DefaultFieldDeserializer" />
<adapter factory=".atfields.FileFieldDeserializer" />
Expand Down
Loading