Hi Developers,
i have been trying this the whole time already and decided to ask for help.
I want to create a space, a group and add a member to the group. The space
should only be viewed by this group.
Here is my code till now. The Space is created, the group too and the user
login in is added to the group. I can't figure how to assign the rights.
The CODE:
protected void addUserToGroup(String xwikiname, XWikiContext context)
throws XWikiException{
//
// Create a group and add the user to the newly created group.
BaseClass groupClass = context.getWiki().getGroupClass(context);
// Get document representing group
DocumentReference groupDocumentReference = new DocumentReference(
context.getDatabase(), "myspace",
"Testgroup");
XWikiDocument groupDoc = context.getWiki().getDocument(
groupDocumentReference, context);
BaseClass rightsClass = context.getWiki().getRightsClass(context);
if (groupDoc.isNew()) {
log.error("Creating Test group");
synchronized (groupDoc) {
// Add a member object to document
BaseObject memberObj = groupDoc.newXObject(
groupClass.getDocumentReference(), context);
memberObj.setStringValue("member", xwikiname);
BaseObject rights=
groupDoc.newXObject(rightsClass.getDocumentReference(),context);
rights.setStringValue("groups", "Testgroup");
rights.setStringValue("levels","view");
rights.setStringValue("levels", "edit");
rights.setStringValue("users", "");
rights.setIntValue("allow",1);
//groupDoc.getObject("XWiki.XWikiGlobalRights");
groupDoc.setSyntax(Syntax.XWIKI_2_1);
groupDoc.setContent("{{include
document='XWiki.XWikiGroupSheet' /}}");
// Save modifications
context.getWiki().saveDocument(groupDoc, context);
}
log.error("Added user"+ xwikiname +"to Testgroup");
}
}
Thanks for any help.