Python脚本,用于在用户填写表单后隐藏ploneformgen表单. (对于Plone-4.3.2-64.) [英] Python script to hide ploneformgen form after user has filled it out. (For Plone-4.3.2-64.)

查看:67
本文介绍了Python脚本,用于在用户填写表单后隐藏ploneformgen表单. (对于Plone-4.3.2-64.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户填写了(ploneformgen)表单后,我想使用自定义脚本适配器调用python脚本来更改用户的本地角色,以使他们无法再看到该表单.换句话说,我想防止用户两次填写(或查看)表单.

After a user has filled out a (ploneformgen) form , I would like to use a custom script adapter to call a python script to change the user’s local role so that they can’t see the form anymore. In other words, I want to prevent the user from filling out (or viewing) the form twice.

我认为实现此目的的一种方法是调用位于form文件夹中的脚本Permission_changer.py.我在该脚本中拥有的代码是这样的:

I figured that one way to do this is to call the script permission_changer.py which is located in the form folder. The code I have in that script is this:

 container.manage_delLocalRoles((‘bob',)) 
 container.reindexObjectSecurity() 

其中"bob"只是一个示例用户,仅具有全局角色FormFiller(我在ZMI的安全性"选项卡下创建)和本地角色"Reader"(用于表单文件夹).

Where ‘bob’ is just an example user, who has only the global role FormFiller (which I created under the Security tab of the ZMI) and the local role "Reader" for the form folder.

当我以系统管理员的身份填写表单(状态为私有")时,脚本被成功调用,并且bob失去了其"Reader"本地角色(这是他必须开始的全部工作),而他看不到表格了.但是,当bob填写表格时,您没有足够的权限查看此页面."显示错误,并且bob的本地角色未删除.我不知道为什么-并且我尝试了许多不同的方法:

When I fill out the form (which has a "private" state) as a system admin, the script is called successfully and bob loses his "Reader" local role (which is all he had to begin with), and he can’t see the form anymore. However, when bob fills out the form, a "You do not have sufficient privileges to view this page." error is displayed, and bob’s local role is not removed. I can’t work out why –– and I’ve tried many different things:

我通过单击ZMI中脚本的代理"标签来更改了permission_changer.py的代理.我将其更改为经理",系统管理员"和所有者",但这并不能解决问题(也没有进行任何组合).

I’ve changed the proxy for the permission_changer.py by clicking on "Proxy" tab for the script in ZMI. I changed it to "Manager", "System Administrator", and "Owner", but that didn’t solve the problem (nor did any combination of those).

我尝试通过在表单文件夹中创建文件permission_changer.py.metdadata并包括以下内容来更改代理:

I tried changing the proxy by creating a file permission_changer.py.metdadata in the form folder and including this:

 [default]
 proxy = Manager

但是那也不起作用.

奇怪的是,当我将bob的全局角色更改为Manager,System Administrator,甚至Viewer或Editor时,问题消失了,脚本运行得很好(我也可以更改脚本,以便添加和删除任意其他脚本)本地角色). (这些选项对我来说不是解决方案,因为由于鲍勃的全球角色,他仍然可以看到表格.)

Strangely, when I change bob’s global role to Manager, or System Administrator, or even Viewer, or Editor, the problem goes away and the script runs just fine (I can also change the script so that it adds and removes arbitrary other local roles). (These options are not solutions for me because bob will still be able to see the form because of his global role.)

我还尝试在安全性标签下为角色FormFiller授予所有可能的权限,但没有用.

Also, I tried giving the role FormFiller role every possible permission under the Security tab, but didn’t work.

因此,我猜测问题可能与代理设置有关,但我无法弄清我做错了什么.我搜索了很多东西,但找不到任何讨论类似问题的人.

So, I’m guessing that the problem has to do with the proxy settings, but I can’t work out what I’m doing wrong. I've searched around a lot, and I can't find anyone discussing a similar problem.

任何帮助将不胜感激!

推荐答案

要授予和撤消提交表单的权限,您可以:

For granting and revoking the permissions to submit a form, you could:

  1. 创建一个组(例如ID为"Submitters"的组)并将选定的用户分配给该组
  2. 确保表单文件夹的状态为私有",并通过表单文件夹的共享"标签将查看权限授予该组
  3. 在表单文件夹的父项中添加一个类型为"Page"的内容项(例如,其ID为"submitted"),并将其状态设置为"public"
  4. 添加类型为自定义脚本适配器"的内容项,在代理角色"字段中选择管理器",然后将以下各行插入到脚本主体"字段中:

# Remove current user of group and redirect to [FORM_PARENT_URL]/landing_page_id'.
# If user is not in group, fail silently and continue.
# Fail if landing_page_id does not exist in form-folder, or one of its parents.
#
# Assumes a page with the ID as declared in `landing_page_id` lives in the
# form-folder's parent (or one of its grand-parents, first found wins),
# and holds the state 'public', so users can view it regardless of their
# group-memberships.
#
# Ment to be used after submission of a PloneFormGen-form with private-state and
# a locally assigned Reader-role for the group, so only group-members can view and
# submit the form.

from Products.CMFCore.utils import getToolByName


group_id = 'Submitters' # change as needed

landing_page_id = 'submitted' # change as needed

portal_groups = getToolByName(ploneformgen, 'portal_groups')

user_id = ploneformgen.memberId()

parent_url = '/'.join(ploneformgen.absolute_url().split('/')[:-1])

redirect_to_url = parent_url + '/' + landing_page_id

# Revoke current user's group-membership:
portal_groups.removePrincipalFromGroup(user_id, group_id)

# Let user land in userland:
request.response.redirect(redirect_to_url)

经过Plone-4.3.11和Products.PloneFormGen-1.7.25的测试

Tested with Plone-4.3.11 and Products.PloneFormGen-1.7.25

这篇关于Python脚本,用于在用户填写表单后隐藏ploneformgen表单. (对于Plone-4.3.2-64.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆