Hi,

Thank you for the reply!

I'm trying to implement the groovy listener but I'm doing something wrong..

This is what I'm trying to do:

{{groovy}}
import org.xwiki.observation.*
import org.xwiki.observation.event.*
import com.xpn.xwiki.web.*
import com.xpn.xwiki.*

class RightsEventListener implements EventListener
{
    def xwiki
    def context
    def doc

    RightsEventListener(xwiki, context, doc)
    {
        this.xwiki = xwiki
        this.context = context
        this.doc = doc
    }

    String getName()
    {
        // The unique name of this event listener
        return "dynamicRights"
    }

    List<Event> getEvents()
    {
        // The list of events this listener listens to
        return Arrays.asList(new DocumentUpdateEvent())
    }

    // Called by the Observation Manager when an event matches the list of
events returned
    // by getEvents()
    void onEvent(Event event, Object source, Object data)
    {
        def rightsObject = doc.getObject("XWiki.XWikiRights", true)
        rightsObject.set("groups", "")
        rightsObject.set("levels", "edit")
        rightsObject.set("users", "Luis Braga")
        rightsObject.set("allow", 1)
        doc.save()
    }
}

// Register against the Observation Manager
def observation = Utils.getComponent(ObservationManager.class)
observation.removeListener("dynamicRights")
def listener = new RightsEventListener(xwiki, xcontext, doc)
observation.addListener(listener)

{{/groovy}}

When I update the file I get an error:

Detailed information:
   Error number 3201 in 3: Exception while saving document
xwiki:Publication.FonteICEIS2010
Wrapped Exception: Failed to commit or rollback transaction. Root cause []
com.xpn.xwiki.XWikiException: Error number 3201 in 3: Exception while saving
document xwiki:Publication.FonteICEIS2010
Wrapped Exception: Failed to commit or rollback transaction. Root cause []
        at
com.xpn.xwiki.store.XWikiHibernateStore.saveXWikiDoc(XWikiHibernateStore.java:653)
        at
com.xpn.xwiki.store.XWikiCacheStore.saveXWikiDoc(XWikiCacheStore.java:181)
        at
com.xpn.xwiki.store.XWikiCacheStore.saveXWikiDoc(XWikiCacheStore.java:175)
        at com.xpn.xwiki.XWiki.saveDocument(XWiki.java:1451)
        at com.xpn.xwiki.web.SaveAction.save(SaveAction.java:162)
        at com.xpn.xwiki.web.SaveAction.action(SaveAction.java:184)
        at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:215)
        at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:117)
        at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
        at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at 
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
(...)

For my surprise the XWikiRights object is created but don't work. If I
create the exactly same object manually it works.

Luís Braga

-- 
View this message in context: 
http://xwiki.475771.n2.nabble.com/Dynamically-set-rights-over-document-tp6060830p6073930.html
Sent from the XWiki- Users mailing list archive at Nabble.com.
_______________________________________________
users mailing list
users@xwiki.org
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to