防止删除 Plone 中的文件夹(类型),除非删除父文件夹

发布于 2024-12-10 05:57:12 字数 462 浏览 0 评论 0原文

我想防止删除 Plone 中文件夹类型的实例,除非删除父文件夹。我有预感,事件处理程序可以防止删除(在绑定到标记接口的 IObjectRemovedEvent 处理程序中引发异常),但实现此规则的异常似乎更难确定:我想允许删除项目的父文件夹时删除该项目。

我最初的预感是我可以遍历 __parent__ 指针并检查是否在要删除的父级(或某些远程间接容器)上设置了属性,但我不确定如何设置它在尝试删除所包含的子项之前删除父项的属性(否则不允许删除)。所以现在,我在质疑我是否以正确的方式处理这个问题?我是否误解了在 Plone 中删除对象的问题限制?我应该寻找 plone.app.linkintegrity 源来借用技巧吗?

我的用例:“项目”文件夹内的“设置文件夹”——本质上,除非项目文件夹本身被删除,否则绝对不允许删除设置文件夹。我想我是在要求一个非常具体的包含关系的引用完整性。

如何防止对象被删除,除非该对象是由于其父对象被删除而直接导致被删除的情况?

I want to prevent deletion of instance of a folderish type in Plone, excepting when a parent folder is being deleted. I have a hunch that an event handler can prevent deletion (raise an exception in an IObjectRemovedEvent handler bound to a marker interface), but implementing the exception to this rule seems harder to pin down: I want to allow deletion of the item when its parent folder is being deleted.

My initial hunch was that I could traverse __parent__ pointers and check if an attribute was set on the parent (or some distant indirect container) that it was being deleted, but I am not sure how I would set this attribute on deletion of the parent prior to an attempt to delete the contained child (otherwise not allowing deletion). So now, I'm questioning whether I am approaching this the right way? Am I misunderstanding the problem constraints for deleting objects in Plone? Should I look to plone.app.linkintegrity source to borrow tricks?

My use case: a "settings folder" inside a "project" folder -- intrinsically, the settings folder should never be allowed to be deleted unless the project folder itself is being deleted. I guess I'm asking for referential integrity for a very-specific containment relationship.

How would you prevent deletion of an object except in the case it was being deleted as a direct result of its parent being deleted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

別甾虛僞 2024-12-17 05:57:12

经过相当长的一段时间,我终于找到了这个普遍问题的解决方案(但在不同的上下文中):

  1. 在父级上为父级接口和 OFS.interfaces.IObjectWillBeMovedEvent 创建订阅者。
  2. 该处理程序应该使用 zope.globalrequest.getRequest() 来获取请求对象,并将其适应 IAnnotations 以获取请求上的注释对象(实际上,在请求期间是全局的)。
  3. IObjectWillBeMovedEvent 处理程序将在注释对象上保存物理路径元组 (context.getPhysicalPath()) 的元组形式。
  4. 如果 IObjectRemovedEvent 的路径共享父项的基本路径,则尝试阻止子项删除的 IObjectRemovedEvent 事件处理程序将通过(请参阅示例)。

因此,只有在尝试删除对象本身时才会引发异常,而在删除其父对象时则不会引发异常。

请参阅示例: http://bazaar.launchpad.net /~upiq-dev/upiq/dev-uu.formlibrary/revision/113

After a fair bit of time, I have finally found a solution to this general problem (but in a different context):

  1. Create a subscriber on the parent for the parent's interface and OFS.interfaces.IObjectWillBeMovedEvent.
  2. That handler should use zope.globalrequest.getRequest() to get the request object, and adapt that to IAnnotations to get an annotations object on the request (a global for the duration of the request, in practical terms).
  3. The IObjectWillBeMovedEvent handler will save a tuple form of the physical path tuple(context.getPhysicalPath()) on the annotation object.
  4. The event handler for IObjectRemovedEvent attempting to block deletion of the child item will pass if its path shares a base path of the parent (see example).

By consequence, an exception is only raised if an attempt is made to delete the object itself, but not when its parent is deleted.

See example: http://bazaar.launchpad.net/~upiq-dev/upiq/dev-uu.formlibrary/revision/113

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文