I have written a very simple event listener that is supposed to set user profile documents to hidden at creation or modification due to some business/security concerns we have around user profiles.
The event listener was working just fine in the test bed but on our production server it doesn’t seem to be marking the pages as hidden when an admin creates the user.
Here’s the relevant code I have:
GetEvents:
import org.xwiki.bridge.event.* xcontext.method.output.value = [new DocumentCreatingEvent(), new DocumentUpdatingEvent()]
OnEvent:
if (docSource.getParent() == "xwiki:Main.UserDirectory") { docSource.setHidden(true) }
Now, I’m not sure if what I’m trying to do is supposed to even work with how I’m doing it but I have some other needs to create an event listener that will listen for new documents or modifications to documents that have a particular xclass object associated with them and send emails or do other things such as create a sub-page. So I’m a bit stumped as to how to determine if the doc has an object or not.
For example: the instance provided above I can define a variable like this:
#set($obj = $doc.getObject(‘XWiki.XWikiUsers’))
but how do I then determine if the object is present or not?
Thanks!