cancel
Showing results for 
Search instead for 
Did you mean: 

adding to favorites (Solved)

michaelc
Champ on-the-rise
Champ on-the-rise
So one of the user requests I have is that a site when initially added should also be added to the users favorites.
the first 1/2 adding into site-finder.js worked like a champ.

I next added the same logic to accept-invite.get.js and here it did not work.
any thoughts on why this seems to not work as expected.

 

<import resource="classpath:alfresco/site-webscripts/org/alfresco/callutils.js">

function main()
{
   // make sure we don't redirect by default
   model.doRedirect = false;
   
   // fetch the user information from the url
   var inviteId = page.url.args.inviteId,
      inviteTicket = page.url.args.inviteTicket,
      inviteeUserName = page.url.args.inviteeUserName;
     
  
   if ((inviteId == undefined) || (inviteTicket == undefined))
   {
      model.error = "Parameters missing!";
      return;
   }
            
   // do invite request and redirect if it succeedes, show error otherwise
   var theUrl, connector, result, json, data;

   theUrl = '/api/invite/' + inviteId + '/' + inviteTicket + '/accept';
   // for MT share
   if (inviteeUserName != undefined)
   {
      inviteeUserName = encodeURIComponent(inviteeUserName);
      theUrl = theUrl + '?inviteeUserName=' + inviteeUserName;
   }
  
   connector = remote.connect("alfresco-noauth");
   result = connector.put(theUrl, "{}", "application/json");
   if (result.status != status.STATUS_OK)
   {
      model.doRedirect = false;
      json = eval('(' + result.response + ')');
      model.error = json.message; // result.response;
   }
   else
   {
      // redirect to the site dashboard
      // model.doRedirect = false;
      data = eval('(' + result.response + ')');
      model.siteShortName = data.siteShortName;
      var favourites = {};
      favourites[data.siteShortName] = true
      var dataPass =
      { 'org' :
        { 'alfresco' :
          { 'share' :
            { 'sites' :
              { 'favourites' : favourites }
            }
          }
        }
      };
      theUrl = '/api/people/' + inviteeUserName + '/preferences';
      result = connector.post(theUrl, dataPass, "application/json");
      if (result.status != status.STATUS_OK)
      {
         model.doRedirect = true;
      }
      else
      {
          model.doRedirect = false;
          json = eval('(' + result.response + ')');
          model.error = json.message; // result.response; 
      }     
   }
}

main();
4 REPLIES 4

mikeh
Star Contributor
Star Contributor
any thoughts on why this seems to not work as expected.
That's pretty vague - what exactly was the error and/or problem?

Mike

shahsnehal
Champ in-the-making
Champ in-the-making
Can you provide more details on this? Either your error trace

michaelc
Champ on-the-rise
Champ on-the-rise
I was out a few days sorry for the slow return.

there was no error in the log, the user was added to the site but the site was not added to the users favorites.
no error and no action.

  I thought it's possible it did not work because I used "alfresco-noauth"  so I tried to change the connection
  connector = remote.connect('alfresco");
  user = "specialUser";
  passWord = "secret1";
  result = connector.post(theUrl,dataPass,UserId,passWord,"application/json");
 
  this failed with Can't find method org.springframework.extensions.webscripts.ScriptRemoteConnector.post(string,object,string,string,string).
  this I understand.

this seems simple but I am not getting there.

michaelc
Champ on-the-rise
Champ on-the-rise
I fixed by backdooring it a bit.

  I modified the email to call my service that added the sites to favorites as I can do this from a restful service.
  this then forwarded the the request.

  now when a user is added to a site the site is a favorite unless the user changes this.
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.