[xwiki-users] AddUserToGroup Programmatically
Hi, i am adding Users to a group as shown below d want to prevent that a user be added to a group twice. It is not working this way. if( null == groupDoc.getXObject(groupDocumentReference, "member", xwikiname)){ // Add a member object to document BaseObject memberObj = groupDoc.newXObject( groupClass.getDocumentReference(), context); memberObj.setStringValue("member", xwikiname); context.getWiki().saveDocument(groupDoc, context); }else log.error("the user already existed in the requested group..."); I will appreciate any help. Thanks
Hi, Le 10 juin 2014 21:09, "Daniel Ebanja" <[email protected]> a écrit :
Hi, i am adding Users to a group as shown below d want to prevent that a user be added to a group twice. It is not working this way.
if( null == groupDoc.getXObject(groupDocumentReference, "member", xwikiname)){
I never used this method, and its javadoc could be improved, are you sure it does what you think ? ;) You could use something like (to be checked): xwiki.getUser("username", context).isUserInGroup("group")
// Add a member object to document BaseObject memberObj = groupDoc.newXObject( groupClass.getDocumentReference(), context); memberObj.setStringValue("member", xwikiname);
context.getWiki().saveDocument(groupDoc, context); }else log.error("the user already existed in the requested group...");
You say it doesn't work, but do you see that log ? What happens ?
I will appreciate any help. Thanks _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Hi Jeremie, adding the member to the group works just well. The problem is that the same user or say member can be added several times to the same group. I need some means to stop this. I can't see that log. Thanks Am 11.06.2014 01:08 schrieb "Jeremie BOUSQUET" <[email protected]>:
Hi, Le 10 juin 2014 21:09, "Daniel Ebanja" <[email protected]> a écrit :
Hi, i am adding Users to a group as shown below d want to prevent that a user be added to a group twice. It is not working this way.
if( null == groupDoc.getXObject(groupDocumentReference, "member", xwikiname)){
I never used this method, and its javadoc could be improved, are you sure it does what you think ? ;) You could use something like (to be checked): xwiki.getUser("username", context).isUserInGroup("group")
// Add a member object to document BaseObject memberObj = groupDoc.newXObject( groupClass.getDocumentReference(), context); memberObj.setStringValue("member", xwikiname);
context.getWiki().saveDocument(groupDoc, context); }else log.error("the user already existed in the requested group...");
You say it doesn't work, but do you see that log ? What happens ?
I will appreciate any help. Thanks _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
So you're saying that getXObject returns null even if there is a matching object? Can you try it outside the context of your current code? Thanks, Marius On Tue, Jun 10, 2014 at 10:06 PM, Daniel Ebanja <[email protected]> wrote:
Hi, i am adding Users to a group as shown below d want to prevent that a user be added to a group twice. It is not working this way.
if( null == groupDoc.getXObject(groupDocumentReference, "member", xwikiname)){ // Add a member object to document BaseObject memberObj = groupDoc.newXObject( groupClass.getDocumentReference(), context); memberObj.setStringValue("member", xwikiname);
context.getWiki().saveDocument(groupDoc, context); }else log.error("the user already existed in the requested group...");
I will appreciate any help. Thanks _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (3)
-
Daniel Ebanja -
Jeremie BOUSQUET -
Marius Dumitru Florea