cancel
Showing results for 
Search instead for 
Did you mean: 

How to add all users to group EMAIL_CONTRIBUTORS?

mpeters
Champ in-the-making
Champ in-the-making
Hi,

what would be the easiest way to add all Alfresco users to the group EMAIL_CONTRIBUTORS (or any other group)? Unfortunately it is not possible to add the group EVERYONE to another group like EMAIL_CONTRIBUTORS (or did I overlooked the obvious solution)? Certainly one could add  user by user to the targeted group, but doing this with a few hundred (dayly changing) users is quite annoying Smiley Surprised.

Any hints, please?

Kind regards
Markus
23 REPLIES 23

supta
Champ in-the-making
Champ in-the-making
I had the same problem and came up with this solution: when adding user to EMAIL_CONTRIBUTORS in Explorer, I search all users with an * (asterisk). Select all users and add to the group.

anhua-jian
Champ in-the-making
Champ in-the-making
If you change the lucene query to:

search.luceneSearch("workspace://SpacesStore", "TYPE:\"cmSmiley Tongueerson\"");

you will get the following lines:

var nameTargetgroup = 'test';
  //get all users
var members = search.luceneSearch("workspace://SpacesStore", "TYPE:\"cmSmiley Tongueerson\"");

   if (members) {
      // get the target group
      var groupTarget = people.getGroup('GROUP_' + nameTargetgroup);

      // if not existent, create the target group
      if (!groupTarget) {
         groupTarget = people.createGroup(nameTargetgroup);
      };

      if (groupTarget) {
         // loop over all members of the source group and add them to the target group
         for(var i = 0; i < members.length; i++) {
         if(people.isAdmin(members))continue;
         if(people.isGuest(members))continue;
            people.addAuthority(groupTarget, members);
         };
      };
   };

agonirena
Champ in-the-making
Champ in-the-making
Based on previous post code, I have improved the script taking care of existing membership. If anyone belongs to EMAIL_CONTRIBUTORS group, adding the user again generates an exception.

Here the script:


var nameTargetgroup = 'EMAIL_CONTRIBUTORS';
var groupPrefix="GROUP_";

function userBelongsToGroup (_person, _groupTarget) {
  var found = false;
  var containerGroups = people.getContainerGroups(_person);
     
  for (var i = 0; i < containerGroups.length; i++) {
    if (containerGroups[i].properties["cm:authorityName"] == _groupTarget.properties["cm:authorityName"]) {
      found = true;
      break;
    };
    //logger.log(containerGroups[i].properties["cm:authorityName"]);
  };

  return found;
}

//get members
var members = search.luceneSearch("workspace://SpacesStore", "TYPE:\"cm:person\"");

if (members) {
  // get target group
  var groupTarget = people.getGroup(groupPrefix + nameTargetgroup);

  if (groupTarget) {
    // loop over all members of the source group and add them to the target group
    for(var i = 0; i < members.length; i++) {
      var person = members[i];
     
      if(people.isAdmin(person)) continue;
      if(people.isGuest(person)) continue;     
      if (userBelongsToGroup (person, groupTarget)) continue;
      var email = person.properties["cm:email"];
      if (!email || (0 == email.length)) continue;

      logger.log(person.properties["cm:userName"] + " is NOT member of EMAIL_CONTRIBUTORS group. Adding…");
     
      try {
        people.addAuthority(groupTarget, person);
      } catch (ex) {
        logger.log("ABORT: exception ocurred: " + ex);
        break;
      };
    };
  };
};

smcardle
Champ in-the-making
Champ in-the-making
Why can't we just switch off the test for members of a Group.

We want to let everybody email to a folder and we are not going to manually add (or add by script) users to the EMAIL_CONTRIBUTORS

We have external users whom need to email content to this folder and they are not setup as Alfresco users

Regards