Alfresco: 5 ways to add a user to a group (without) programming

[1] Using default Add Users button from Site Members page

[2] Inviting the user from Site Members page

[3] Using the Groups option from Admin Tools page

[4] Using JavaScript API from JavaScript Console page

var group = people.getGroup("GROUP_site_software_SiteCollaborator");
var authority = people.getPerson("ana.galindo");
people.addAuthority(group,authority);

[5] Using curl from command line

curl -H "Content-Type: application/json" -X POST -u admin:keensoft \
http://localhost:8080/alfresco/s/api/groups/site_software_SiteContributor/children/ana.galindo

DISCLAIMER: not all the available ways are covered in this post

Which Alfresco version am I using?

Till some months ago, Alfresco released Community and Enterprise editions by using two numbers for major version and

  • a letter for minor version in Community (5.0.d)
  • a third number for minor version in Enterprise (5.0.4)

However, from 5.1 release they are using a different approach for Community branch, as is identified by the following pattern

  • YEARMONTH-[EA | GA]
    • EA = Early access (only for testing purposes)
    • GA = Generally available (ready for prod environments)

So, the last mature version available for Community 5.1 is named 201605-GA and for Community 5.2 is named 201701-GA. This makes sense as alfresco and share components have been versioned individually, so Alfresco 201701-GA contains:

  • 5.2.e for Alfresco platform alfresco.war
  • 5.2.d for Alfresco share share.war

Share component has a single development line, so the same software is used for both Community and Enterprise releases. However, Enterprise release (which is named Alfresco One from some months ago) still uses 5.2.0 scheme for identifying the version, marking the alfresco component core for the release.

Once the server is running, Alfresco version can be obtained by accessing http://localhost:8080/alfresco  (although there are other places where this number is shown)

alfresco-version

As it can be seen, this naming convention is again different from previous ones Community – 5.2.0 (r134428-b13). Alfresco Community web site contains a list where this numbers are related to distribution ones: Release Cross Reference. So, in this case we have a 201701-GA (aka 5.2.e).

Many different naming conventions had been used for Alfresco products, but it is always possible to identify which version is running a server

Alfresco, massive delete of users

Since Share web interface nor admin web console have option to delete massively users, this operation has to be performed by your own rules.

I’m using Javascript Console to make easier the execution of Administration JavaScripts, but any other tool (even curl) can be used.

// Get every user in Alfresco
var nodes = people.getPeople(null);
 
for each(var node in nodes) { 
  // Build user object
  var user = utils.getNodeFromString(node);
  // Obtain userId
  var userName = user.properties["cm:userName"];
  // Obtain userHomeFolder
  var userHomeFolder = user.properties["cm:homeFolder"];
  // Filter users to be deleted by any criteria, starting by "CES" in this case
  if (userName.indexOf("CES") == 0) {
      logger.log(userName + ", " + userHomeFolder.properties["cm:name"]);
      // people.deletePerson(userName);
      // userHomeFolder.remove();
  }
} 

Once you have verified that every userName logged by this script has to be deleted, you can uncomment following lines…

      // people.deletePerson(userName);
      // userHomeFolder.remove();

… and run the script again to perform effectively the removal.

As other Alfresco community members have pointed out by Twitter and LinkedIn, this script is just a sample for your understanding. Many other factors (LDAP, repository permissions, ownership over contents…) have to be considered before using a script like this in a real environment.