delivered / chargify-zendesk

Access your Chargify subscription data from within Zendesk.
MIT License
6 stars 5 forks source link

Users without a domain set up pull too many customer records into App #4

Closed jmatthewpryor closed 7 years ago

jmatthewpryor commented 7 years ago

Hi

We have a lot of customers who don't have a domain set up in their organization, and as a result the app ends up pulling in 20 extra customers using the query

https://obsrv.chargify.com/customers.json?q=@

This is the code that causes it (I think)

    var organizationDomains = app.getCustomerOrganizationDomains();
    if (organizationDomains) {
      organizationDomains.map(function (domain) {
        pageData.expected_queries.push(domain);
        app.ajax('fetchCustomersByQuery', '@' + domain).done(aggregateResults);
      });
    }

I think the issue is that organizationDomains is an array with one empty string in it. So the app ends up issuing the following query https://obsrv.chargify.com/customers.json?q=@ Which returns 20 customers that are not related to the user currently being viewed

I can likely work up a pull request if needed, but I think the fix is simple; getCustomerOrganizationDomains() should refuse to return any empty string elements

Thanks

stevenmaguire commented 7 years ago

Nice catch. A fix should be straightforward. I'll keep an eye out for a PR or take care of it Monday, whichever comes first :)

stevenmaguire commented 7 years ago

Version 1.3.1 has a fix for this issue, as well as a second condition I've observed wherein multiple organizations have the same domain. So, now the method will only return an array non-empty unique strings or null.

https://github.com/delivered/chargify-zendesk/releases/tag/1.3.1