Save objects to another instance in Plone 3.x - plone

When creating an object (like News) programmatically in Plone 3.x is it possible save it to a folder in another instance?

Short answer: it is generally possible and you have various options depending on your setup.
If I understood your question and your setup correctly, you have two Plone instances running in the same ZODB.
Something like this:
ipdb> self.context
<Application at >
ipdb> self.context.SiteA
<PloneSite at /SiteA>
ipdb> self.context.SiteB
<PloneSite at /SiteB>
If this is the case, you can copy or move the object in to the new site, as demonstrated by the following debug session:
ipdb> cpdata = self.context.SiteA.manage_copyObjects(['front-page'])
ipdb> self.context.SiteB.manage_pasteObjects(cpdata)
[{'new_id': 'copy_of_front-page', 'id': 'front-page'}]
ipdb> self.context.SiteB['copy_of_front-page'].Title()
'Welcome to Plone'
For example you can do the copy move operation adding an event subscriber.
Of course you have to take care of the permissions settings.
The example I pasted worked because I was using the user admin which is define in the acl_users folder of the zope application.
But technically you can achieve this result by tweaking the security manager.
If the two Plone sites are not in the same ZODB, do not worry :)
There are solutions that will work also if one of the 2 sites (or both) are not running Plone.
For example you can create on Site A a form that posts to the Site B.
If you have SSO between the two sites it may be as trivial as changing the action attribute url from /SiteA/folder1/add_form to /SiteB/folder2/add_form.
Another option is that when SiteA receives the form data, it crafts a request with the urllib and urllib2 to SiteB. In this case you wil miss the requests module (not available in Python2.4) a lot.

Related

Wanted to make alfresco site read only

Want to make alfresco site read only in alfresco community 5.0 so that no one can make any changes or edit that during migration.
I already tried changing the user/group permissions but that method doesn't work properly. Is there any other way to make the sites read only?
You need to make all sites in read only mode and so entire Repository should be in read-only mode for migration!
Try this property in your alfresco-global.prop file
server.allowWrite=false
Please check this for reference
The best way to make a site read only would probably be to modify all members of that site to have the consumer role (this would prevent them for creating new content or editing any existing content).
Unfortunately there is no bulk capability built into the UI to do this, however it should be a relatively straightforward exercise to create an admin only custom WebScript to achieve this. It would necessary for the Admin to become the site manager of each site before attempting to change the role of each site member, but there is an API for doing this.
Alternatively (if you have only a few sites) then you could do this manually through the UI using the Site Management Admin Console page. Again, the Admin would need to become the Site Manager for each Site and then visit the site and change the role of every member.
As suggested by #DaveDraper in a former answer, you could setup site memberships to the consumer role. However, this won't take into account any special permission given on a particular node (folder/document) in that site either with or without inheritance of permission.
So, if you intend to block any writes on the entire alfresco repo/site you could simply setup an extra security interceptor on your NodeService to block any write access using the NodeService.
PS : You could get some inspiration from the "NodeService_security" bean and implementation !
I can think of a turn-around or two, but those would be really sloppy so I won't be including them in this response

Products.Reflecto and Plone sharing, bug or feature?

I'm using Products.Reflecto in Plone 4 to mirror file system content and provide fine-grained security on that content (i.e. give specific groups access to selected folders)
I know Reflecto objects are not real Plone content, however there is a sharing tab on all the files inside the Reflecto object. It works as expected, until you reindex the reflector at which point the settings are only applied to the reflector object.
E.g.:
Mkdir (on the file system) -p test/foo/bar/baz
Create a reflector object mirroring a "test" directory on the file system.
Share "view" permission on baz with any user or group
Verify that sharing works as expected
Reindex "test"
Notice that the user or group now has "view" permission on "foo"
Curiously, as soon as you configure sharing on a child object the reflector object has the same settings, but they seem to be ignored. Also curious, if you configure a "live" reflector sharing does not work at all. Is this a bug or a feature? Is it reasonable to try to support this use case? I.e. reindex the reflector and maintain sharing settings?
I don't think this was ever meant to work; I don't recall covering the use case when developing Reflecto in any case.
I haven't touched the product in years though, and I didn't do any more than glance at the code base to remind myself.
What I suspect in your test case is that the sharing information is set (via acquisition) on the reflector object, but the directory proxy for baz is being reindexed. If you were to reindex the reflector the sharing settings would no longer be ignored.
If so, then the presence of the sharing tab on the directory proxies is the real bug here.

How do I implement a dynamic role in Plone 3?

I want to allow access to certain content to certain users for a limited time,
using a 'Dynamic Role' in Plone 3 ( http://collective-docs.readthedocs.org/en/latest/security/dynamic_roles.html ).
To this end I've created an add-on with a copy paste of example code - except that for now getDummyRolesOnContext() always returns my role.
But Plone never calls, or instanciates my DummyLocalRoleAdapter, and obviously my users never get the role assigned.
Here's what I know so far:
My dynamic role is defined in a rolemap.xml and get's created upon add-on installation.
My add-on is being imported - an exception on it's first line prevents Zope from starting
None of DummyLocalRoleAdapter are being called - I've spiked all of them with warnings and exceptions.
The adapter does get registered.
How do I continue debugging this - what's the magic part I'm missing?
Thanks!
My guess is that you need to somehow activate borg.localprole PAS plug-in in acl_users:
https://github.com/plone/borg.localrole/blob/master/borg/localrole/utils.py
There might have been borg.localrole add-on installer entry in the past, but now there doesn't seem to be one. My guess is that you need to call the actions from borg.localrole add-on setup code manually in your own add-on.
acl_users when borg.localroles is correctly installed:

Umbraco url's displaying home node in one node, sometimes

So I have an umbraco setup with a 'content' root node and then a 'home' node under that. Under the 'home' node is the content and the URLs are the name of those nodes for example I have a 'about u's node under home and it's URL is '/about-us/'
In the case of the 'news' node, below 'about us', its children some times get '/home/about-us/news/title' of the story as the URL, which throws a 404. I can see that this is the URL of the node on the properties tab, but if I republish it it returns to '/about-us/news/title' for a period before returning to the broken link.
I have only seen this behavior on this node, which contains new-item document types. I basically watched the umbraco tv video and created it following along.
It seems to be to be a umbraco bug, but I would really appreciate any help with the issue
In the web.config, there is a setting called umbracoHideTopLevelNodeFromPath. This causes the behavior you are describing when it is set to false. Do you perhaps have multiple people working on the site and publishing different versions of the web.config that have this setting changed?
When publishing a node with the setting set to false, it would add the /home part to the URL. Otherwise, it would leave off the /home.
Once the Umbraco application has started, there are several processes that run on a regular basis (e.g. to check for expired content). It is possible to piggy-back on these by creating a custom class that inherits from umbraco.cms.businesslogic.ApplicationBase. If you have created one that uses the Document.AfterPublish eventhandler then I would check that it is not causing the issue.
I'm assuming that you haven't written one of these though, so the only other thing I can suggest is checking whether it is an installed package that is causing the issue. Have you installed any Umbraco packages? If so, do they have any automated behaviours, like creating folders etc. If so, this may be causing the issue. The author of a package will usually have a website, codeplex project etc. and they will usually have a issue list or blog.
Edit
I've just quickly checked and uBlogsy, one of the plugins you mention exactly this. It has auto moving and sorting of posts. This is described in the release notes. If you are using this tool for creating news pages, then this will be your issue.
I followed obsidian's link in his answer and read about someone else having the same issue. It seems to be traces back to a umbraco.library:NiceUrlFullPath call in the RSS creator that was feeding news items. I replaced the umbraco.library:NiceUrlFullPath calls with umbraco.library:NiceUrl calls and the issue has disappeared.

Creating DNN Portal through Code (or programming)?

I have one portal with 3 modules inside it, now my requirement is i would like to create
new portal for every client registered in my DNN site.
So, i have one interface for registration, so as soon as client registers entirely new parent portal should be created with all the modules.
How can i achieve this functionality ???
I would suggest digging into the admin files that come as part of the default DNN installation and look for the code that creates a new portal from there. It will ultimately be calling a stored procedure to create the necessary data in the SQL tables. You might get away with just calling the stored procs but the admin code probably calls several different ones to setup the default security settings.
Curiously what alias will each of these portals use? It's not clear why you need a complete portal for each user. The DNN segmentation already allows you to show different content based on role membership. Why the need for a whole portal per user?
Use the site wizard to create template of the current portal and during client registration programmatically execute the template. You may also want to automate the site setup in IIS.
Well, You can easily do it! Login to host and go to portals. Click on create new protal.
See which control is responsible for creating new portal. you can simaply get it by using firebug and look into client id of link or text box.
Once you do that, you will find the code you can use.
tell me if you need more help with it, I'm good with what you want to do!

Resources