cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically join new (authenticated) users to Public sites

cybertoast
Champ in-the-making
Champ in-the-making
I have a number of Public sites (with no membership moderation) which I automatically want to add users to, as they sign in to Alfresco (they're LDAP users who get set up when they sign up the first time). It seems like the only way to have users become members of a site is for them to click the Join button after searching for sites. Is there a way to automatically subscribe all authenticated users to Public sites? Is there a rule associated with sites that I should be looking at?

The reason for this request is so that users who are new to Alfresco don't have to think about what they have to do - when they sign in they'll have a dashlet with their sites, and they can just start working directly.
14 REPLIES 14

mikeh
Star Contributor
Star Contributor
Add a group to the Site(s) and then add the new users to that group.

Thanks,
Mike

cybertoast
Champ in-the-making
Champ in-the-making
Thanks Mike,
That's good, but since the users are authenticated against LDAP and I don't synchronize users (I didn't think I needed to), there's no way for me to get the user into the group until after they've signed in.

Basically I want the EVERYBODY group to automatically have new users (which it does), and to also have membership to Public sites.

mrogers
Star Contributor
Star Contributor
The EVERYBODY group does have consumer access to Public sites.

Could you have another go at explaining your problem?

cybertoast
Champ in-the-making
Champ in-the-making
Ok, let's say I've got a Users group, which has consumer access to all sites. I add the user group explicitly to a site, say Marketing.

When a new user User1, who is authenticated against LDAP, logs into the site, I want them to see that they have access to Marketing (in their My Sites list). I don't want to have them go to Sites, search for available sites and join the site.

I know I can add User1 to group Users, but the problem is that I don't know who the user is up front (I'm using LDAP for authentication, and not synchronizing all the users all the time). Basically I need to have a way to define a default group that authenticated users automatically become members of (Users in this case), and a default set of sites (the sites marked as Public) to which they have membership.

Hope this clarifies what I'm trying to do. Seems like the missing ingredient is the user automatically being a member of a group.

Thanks much

cybertoast
Champ in-the-making
Champ in-the-making
Seems like there's just no way to do this? There *must* be a way to have a person become a member of a site without them having to explicitly join or for me to join them through a script. Is there a configuration setting that specifies that Public sites are automatically joined?

mikeh
Star Contributor
Star Contributor
Why "must" there be? It's not a use case we've thought about, hence not designed for. You'll either have to write the code yourself, or raise an enhancement request in JIRA and wait for us to do it. I can see how it would be useful, so it's got a good chance of being added at some point.

Thanks,
Mike

cybertoast
Champ in-the-making
Champ in-the-making
Smiley Happy Ok, I guess my "must" is a bit excessive - just figured I was not understanding something.

I'm trying to create a webscript to do this, but my calls don't work:

function joinAllPublicSites()
{
  /* Get a list of all public sites
     Join site if we're not already a member
     Much of this code comes from the site-finder component
   */
  var result = remote.call("/api/sites?");
  if (result.status != status.STATUS_OK) {
    return;
  }
 
  // Ok, result's ok and we have something to do
  var publicSites = eval('(' + result + ')');
  var i, publicSite, retval, conn;

  var authority = {
      "authorityType" : "USER",
      "fullName" : user.userName,
      "userName" : user.userName,
      "firstName" : user.firstName,
      "lastName" : user.lastName
    }; 
  var data = {"role":"SiteConsumer", "person": {"userName" : user.name}};

  for (i = 0; i < publicSites.length; i++) {
    publicSite = publicSites[i];
    conn=remote.connect("alfresco");
    retval=conn.put("/api/sites/" + publicSite.shortName +
                    "/memberships/" + user.name, data);
  }


Calling this gives be error 500, with a

Error exucuting macro: membershipJSON
required parameter: authority is not specified'

I've tried adding the authority object to the call:

  var data = {"role":"SiteConsumer", "person": {"userName" : user.name}, "authority":authority };
But that didn't change anything.

It seems like I should be able to make this call from my webscript's js code, since it's pretty much like what the site-finder.js client-side code does. What am I doing wrong?

mikeh
Star Contributor
Star Contributor
Just tried this for myself and you're nearly there. You need to send the data as a JSON String (not an object) and also set the request to the correct mimetype, so the webscript framework knows to use the .put.json.js controller. Finally, for completeness, you should encode the user name on the request:

    retval=conn.put("/api/sites/" + publicSite.shortName +
                    "/memberships/" + encodeURIComponent(user.name), jsonUtils.toJSONString(data), "application/json");

Thanks,
Mike

cybertoast
Champ in-the-making
Champ in-the-making
Thanks MikeH, that helps a lot! Is there documentation in the wiki that I missed on how to make these calls? If not, I'll start writing this up from the complete newbie's perspective. Perhaps the Idiot's Guide to Alfresco Development?