create a group on domain creation

Hi All i need to create a group on every domain creation, and assign some access rights to this group.

I am thinking of adding an operation and then using an event listener to call the operation on document creation.

I can not seem to find the right method to call for the creation of the group.

I am using version 5.6.

EDIT, rephrasing my question:

in this method call

DocumentModel createGroup(DocumentModel groupModel)
                      throws ClientException,
                             GroupAlreadyExistsException)

What should be the DocumentModel i should pass for a new group ?

0 votes

2 answers

1066 views

ANSWER



Here's the complete code for the operation

  package org.nuxeo.sample;

  import org.nuxeo.ecm.automation.core.Constants;
  import org.nuxeo.ecm.automation.core.annotations.Context;
  import org.nuxeo.ecm.automation.core.annotations.Operation;
  import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
  import org.nuxeo.ecm.automation.core.annotations.Param;
  import org.nuxeo.ecm.core.api.ClientException;
  import org.nuxeo.ecm.core.api.DocumentModel;
  import org.nuxeo.ecm.platform.usermanager.UserManager;

  /**
   * @author ldoguin
   */
  @Operation(id = CreateGroup.ID, category = Constants.CAT_USERS_GROUPS, label = "Create Group", description = "This operation creates a new group using the given       group label and group id.", since = "5.7.3")
  public class CreateGroup {

      public static final String ID = "CreateGroup";

      @Context
      UserManager userManager;

      @Param(name = "Group Id", required = true)
      String groupId;

      @Param(name = "Group Label", required = true)
      String goupLabel;

      @Param(name = "Group Description", required = false, widget = Constants.W_MULTILINE_TEXT )
      String description;

      @OperationMethod
      public DocumentModel run() throws ClientException {
          DocumentModel groupModel = userManager.getBareGroupModel();
          groupModel.setProperty("group", "groupname", groupId);
          groupModel.setProperty("group", "grouplabel", goupLabel);
          groupModel.setProperty("group", "description", description);
          groupModel = userManager.createGroup(groupModel);
          return groupModel;
      }

  }
0 votes



Hello Laurent thank you for the answer. The next step i am looking for is settinv ACE/ACL/ACP, any hints on which would be a good starting point?

Thanks

09/20/2013


The answer was already in some other question, just needed to dig deeper.

Here for reference of others who might need it :

Link

0 votes