Hi, to add access rights to a space, you have to add an "XWiki.XWikiRight" object to the page <spacename>."WebPreferences". I have not tested it, but it should look somewhat like: DocumentReference spacePrefsReference = new DocumentReference( context.getWiki().getName(), spaceName, "WebPreferences") XWikiDocument spacePrefs = context.getWiki().getDocument(spacePrefsReference, context) [...] then add the "rights" object like you did in your code, except that you add it to spacePrefs instead of groupDoc. (I guess you also need to set rights.setStringValue("levels","view,edit"); instead of doing two calls) Do not forget to save spacePrefs, too. hope this helps, clemens On 04/19/2014 08:14 AM, Daniel Ebanja wrote:
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. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users