[xwiki-users] XWikiAllGroup
Hi, how do I manually add a user in XWikiAllGroup using Java Code? Thanks in advance. Allen
Hi, On Feb 8, 2010, at 6:03 PM, J. Allen Q. Santos wrote:
Hi,
how do I manually add a user in XWikiAllGroup using Java Code? Thanks in advance.
This should help you: http://code.xwiki.org/xwiki/bin/view/Snippets/RestoreXWikiAllGroupSnippet -Vincent
Hi Allen, On Mon, Feb 8, 2010 at 6:03 PM, J. Allen Q. Santos <[email protected]> wrote:
Hi,
how do I manually add a user in XWikiAllGroup using Java Code? Thanks in advance.
It's the same thing as programatically adding an object to a page and setting its properties. In velocity you would do: #set($allgroupdoc = $xwiki.getDocument('XWiki.XWikiAllGroup')) #set($newuseringroup = $doc.getObject('XWiki.XWikiGroups', true)) $newuseringroup.set('member', 'XWiki.UserName') $allgroupdoc.save() Or something similar. Guillaume
Allen _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Guillaume Lerouge Product Manager - XWiki SAS Skype: wikibc Twitter: glerouge http://guillaumelerouge.com/
On 02/08/2010 06:18 PM, Guillaume Lerouge wrote:
Hi Allen,
On Mon, Feb 8, 2010 at 6:03 PM, J. Allen Q. Santos<[email protected]> wrote:
Hi,
how do I manually add a user in XWikiAllGroup using Java Code? Thanks in advance.
It's the same thing as programatically adding an object to a page and setting its properties. In velocity you would do:
#set($allgroupdoc = $xwiki.getDocument('XWiki.XWikiAllGroup')) #set($newuseringroup = $doc.getObject('XWiki.XWikiGroups', true))
No, that's wrong, getObject will return an existing object, which means that it will replace an existing member with the new one. XWikiDocument doc = xwiki.getDocument("XWiki.XWikiAllGroup", context); if (doc.getObject("XWiki.XWikiGroups", "member", userDocName) == null) { BaseObject obj = doc.newObject("XWiki.XWikiGroups")); obj.set("member", userDocName, context); xwiki.save(doc, context); }
$newuseringroup.set('member', 'XWiki.UserName') $allgroupdoc.save()
Or something similar.
Guillaume
-- Sergiu Dumitriu http://purl.org/net/sergiu/
Thanks for all the replies! This would really help. Allen -------------------------------------------------- From: "Sergiu Dumitriu" <[email protected]> Sent: Tuesday, February 09, 2010 1:32 AM To: "XWiki Users" <[email protected]> Subject: Re: [xwiki-users] XWikiAllGroup
On 02/08/2010 06:18 PM, Guillaume Lerouge wrote:
Hi Allen,
On Mon, Feb 8, 2010 at 6:03 PM, J. Allen Q. Santos<[email protected]> wrote:
Hi,
how do I manually add a user in XWikiAllGroup using Java Code? Thanks in advance.
It's the same thing as programatically adding an object to a page and setting its properties. In velocity you would do:
#set($allgroupdoc = $xwiki.getDocument('XWiki.XWikiAllGroup')) #set($newuseringroup = $doc.getObject('XWiki.XWikiGroups', true))
No, that's wrong, getObject will return an existing object, which means that it will replace an existing member with the new one.
XWikiDocument doc = xwiki.getDocument("XWiki.XWikiAllGroup", context); if (doc.getObject("XWiki.XWikiGroups", "member", userDocName) == null) { BaseObject obj = doc.newObject("XWiki.XWikiGroups")); obj.set("member", userDocName, context); xwiki.save(doc, context); }
$newuseringroup.set('member', 'XWiki.UserName') $allgroupdoc.save()
Or something similar.
Guillaume
-- Sergiu Dumitriu http://purl.org/net/sergiu/ _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (4)
-
Guillaume Lerouge -
J. Allen Q. Santos -
Sergiu Dumitriu -
Vincent Massol