Skip to content

Commit

Permalink
Update organization method to return only non-empty unique strings
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Oct 9, 2016
1 parent 21b263b commit 1fc4adf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

All Notable changes to `chargify-zendesk` will be documented in this file

## 1.3.1 - 2016-10-09

### Added
- User organization domains will only include unique values, reducing duplicative API calls to Chargify

### Deprecated
- Nothing

### Fixed
- Users with no organization domains returning results for `/customers.json?q=@` - thanks @jmatthewpryor

### Removed
- Nothing

### Security
- Nothing

## 1.3.0 - 2016-10-06

### Added
Expand Down
37 changes: 26 additions & 11 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
(function() {

if (typeof Array.prototype.getUnique == 'undefined') {
Array.prototype.getUnique = function () {
var u = {}, a = [];
for (var i = 0, l = this.length; i < l; ++i) {
if(u.hasOwnProperty(this[i])) {
continue;
}
a.push(this[i]);
u[this[i]] = 1;
}
return a;
};
}

return {
resources: {
DOMAIN_PATTERN: /[a-zA-Z0-9]+\.[a-zA-Z0-9]+\.[a-zA-Z0-9]+/,
Expand Down Expand Up @@ -139,7 +153,14 @@
},

getCustomerOrganizationDomains: function () {
var organization, user;
var organization, user, domains = [];

var appendDomain = function (domain) {
domain = (domain + '').trim();
if (domain.length) {
domains.push(domain);
}
};

if (this.currentLocation() === 'ticket_sidebar') {
user = this.ticket().requester();
Expand All @@ -150,23 +171,17 @@
}

if (organization) {
return organization.domains().split(' ');
organization.domains().split(' ').map(appendDomain);
}

if (user) {
var organizations = user.organizations(),
domains = [];

var organizations = user.organizations();
organizations.map(function (organization) {
organization.domains().split(' ').map(function (domain) {
domains.push(domain);
});
organization.domains().split(' ').map(appendDomain);
});

return domains;
}

return;
return domains.length ? domains.getUnique() : null;
},

getDomainFromURL: function(baseURI) {
Expand Down

0 comments on commit 1fc4adf

Please sign in to comment.