Hi once again,

as I said, I'm using $doc.save() to add objects to the page.
Everything works fine until I log-in with an user that have writing 
rights, but I get error if the user doesn't have writing rights:

Invocation of method 'save' in  class com.xpn.xwiki.api.Document threw 
exception com.xpn.xwiki.XWikiException: Error number 9001 in 9: Access 
denied in edit mode on document...

Is there a way to let users with no writing rights to call $doc.save()?

Vito



Vitantonio Messa wrote:
> Hi all,
> 
> here is the piece of code used to store a new object:
> 
>    ## Create a new object for this user
>    #set($attendee = $doc.newObject("XWiki.AttendeeClass"))
>    $attendee.set("name",$usr)
>    $attendee.set("answer","yes")
>    ## Add a new object to the page
>    $doc.save()
> 
> Of course the "XWiki.AttendeeClass" class was created before.
> It wasn't working at the first attempts because I was trying to create 
> the object with the function $Class.newObject(), I have no idea why, but 
> changing the creation of the object in $Document.newObject() makes 
> everything work fine.
> 
> Hopefully today (in my spare time) I'm going to write this information 
> in the www.xwiki.org.
> 
> Vito
> 
> 
> 
> Vincent Massol wrote:
>> On Oct 18, 2007, at 5:00 PM, David Israel wrote:
>>
>>> This example - 
>>> http://objectwebcon06.objectweb.org/xwiki/bin/view/XWiki/CFP?xpage=code&; 
>>> <http://objectwebcon06.objectweb.org/xwiki/bin/view/XWiki/CFP?xpage=code&;> 
>>> does
>>>
>>> #set($xwiki2 = $xwiki.xWiki)
>>>      #set($context2 = $context.context)
>>>      ## ID
>>>      #set ($sql = "select max(prop.value) from BaseObject as obj, 
>>> LongProperty as prop where obj.className='XWiki.CFPClass' and 
>>> prop.name='id' and obj.id=prop.id.id")
>>>      #set($id=1)
>>>      #foreach ($item in $xwiki.search($sql))
>>>        #set($id=$item.intValue() + 1)
>>>      #end
>>>      #set($newdoc = $xwiki2.getDocument("CFP.No${id}", $context2))
>>>      $xwiki2.saveDocument($newdoc, $context2)
>>>
>>> I'm not sure exactly what you were attempting to do but maybe this 
>>> trick of getting the internal xWiki and context and using them for 
>>> saveDocument can help you.  My use case also requires doing fancy 
>>> things with objects so please help out the documentation if you are 
>>> successful!
>> Checking the code it seems that this would be similar to $newdoc.save(). 
>> Not sure why that's not working.
>>
>> Getting the internal object has 2 issues:
>>
>> 1) It requires programming rights so if this page is edited and saved by 
>> someone without programming rights it'll fail
>> 2) we are planning to completely modify the internal implementation in 
>> the near future of xwiki so it shouldn't be used as much as possible. If 
>> APIs are missing in the public API then we should add it there instead.
>>
>> Thanks
>> -Vincent
>>
>>> On 10/18/07, *Vitantonio Messa* <[EMAIL PROTECTED] 
>>> <mailto:[EMAIL PROTECTED]>> wrote:
>>>
>>>     Ok, thanks. I'll go and have a look.
>>>
>>>     Vito
>>>
>>>
>>>
>>>     Vincent Massol wrote:
>>>     > On Oct 18, 2007, at 10:49 AM, Vitantonio Messa wrote:
>>>     >
>>>     >> It doesn't seem to work: I still get a 0 from this function:
>>>     >> $doc.getObjectNumbers("XWiki.ClassName"))
>>>     >
>>>     > I've never done it myself but maybe someone else here can help.
>>>     >
>>>     > You could also check if you find examples in the source code or in
>>>     > the pages of XE.
>>>     >
>>>     > -Vincent
>>>     >
>>>     >> Vincent Massol wrote:
>>>     >>> On Oct 18, 2007, at 10:35 AM, Vitantonio Messa wrote:
>>>     >>>
>>>     >>>> Thanks Vincent,
>>>     >>>>
>>>     >>>> I'll try it. If it is working, of course, I'm going to put some
>>>     >>>> information on xwiki.org <http://xwiki.org>. Thanks once again!
>>>     >>> hmm seems like the $xwiki.saveDocument() api is internal only.
>>>     >>>
>>>     >>> You should use the $mydocument.save() API instead.
>>>     >>>
>>>     >>> -Vincent
>>>     >>>
>>>     >>>> Vincent Massol wrote:
>>>     >>>>> Hi Vito,
>>>     >>>>>
>>>     >>>>> On Oct 18, 2007, at 10:13 AM, Vitantonio Messa wrote:
>>>     >>>>>
>>>     >>>>>> Hi,
>>>     >>>>>>
>>>     >>>>>> I have created my own class. In a document, I'm able to
>>>     create a
>>>     >>>>>> object
>>>     >>>>>> of that class, write and read fields in that object, but I
>>>     don't
>>>     >>>>>> know
>>>     >>>>>> how to memorize this object in the database: I was looking
>>>     on the
>>>     >>>>>> developer guide on xwiki.org <http://xwiki.org> and I found
>>>     only this page
>>>     >>>>>>
>>>     http://www.xwiki.org/xwiki/bin/view/DevGuide/DatabaseTutorial
>>>     <http://www.xwiki.org/xwiki/bin/view/DevGuide/DatabaseTutorial>
>>>     >>>>>> (which is
>>>     >>>>>> not complete, unfortunately for me).
>>>     >>>>>> Can anyone help me, please?
>>>     >>>>> Have you called $xwiki.saveDocument()?
>>>     >>>>>
>>>     >>>>> Would be nice if you could put this code snippet for creating an
>>>     >>>>> object using scripting on the following page:
>>>     >>>>> http://www.xwiki.org/xwiki/bin/view/DevGuide/APIGuide
>>>     >>>>>
>>>     >>>>> Thanks
>>>     >>>>> -Vincent
>>>     >>> _______________________________________________
>>>     >>> users mailing list
>>>     >>> [email protected] <mailto:[email protected]>
>>>     >>> http://lists.xwiki.org/mailman/listinfo/users
>>>     >> _______________________________________________
>>>     >> users mailing list
>>>     >> [email protected] <mailto:[email protected]>
>>>     >> http://lists.xwiki.org/mailman/listinfo/users
>>>     >
>>>     > _______________________________________________
>>>     > users mailing list
>>>     > [email protected] <mailto:[email protected]>
>>>     > http://lists.xwiki.org/mailman/listinfo/users
>>>     <http://lists.xwiki.org/mailman/listinfo/users>
>>>     _______________________________________________
>>>     users mailing list
>>>     [email protected] <mailto:[email protected]>
>>>     http://lists.xwiki.org/mailman/listinfo/users
>>>     <http://lists.xwiki.org/mailman/listinfo/users>
>>>
>>>
>>>
>>>
>>> -- 
>>> David Israel
>>> cell) (408) 802-2267
>>> _______________________________________________
>>> users mailing list
>>> [email protected] <mailto:[email protected]>
>>> http://lists.xwiki.org/mailman/listinfo/users
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> users mailing list
>> [email protected]
>> http://lists.xwiki.org/mailman/listinfo/users
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/users

Reply via email to