Commit 33f8ff07 authored by Patricio Bruna's avatar Patricio Bruna

domain.countAccounts() returns the Accounts limits infor by Cos

parent 19bb8d9c
...@@ -293,14 +293,24 @@ Count number of accounts by `CoS` in a domain. ...@@ -293,14 +293,24 @@ Count number of accounts by `CoS` in a domain.
```javascript ```javascript
zimbraApi.countAccounts('example.com', callback); zimbraApi.countAccounts('example.com', callback);
// Object {unknow: 2, default: 33, basic: 28, premium: 31, professional: 31} // Object { premium: Object, professional: Object}
// premium: {
// id: _COSId_,
// used: 50
// }
}
``` ```
If you have a `Domain` you can call `countAccounts(callback)` on it: If you have a `Domain` you can call `countAccounts(callback)` on it and it will returns the **Limit of Accounts** for the `Domain`:
```javascript ```javascript
// domain is a Domain, you got it from zimbraApi.getDomain.... // domain is a Domain, you got it from zimbraApi.getDomain....
domain.countAccounts(callback); domain.countAccounts(callback);
// Object { premium: Object, professional: Object}
// Object {unknow: 2, default: 33, basic: 28, premium: 31, professional: 31} // premium: {
// id: _COSId_,
// used: 50,
// limit: 28
// }
}
``` ```
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
{ {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.0.8", "version": "0.0.9",
"private": true, "private": true,
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
......
...@@ -124,7 +124,10 @@ export default class ZimbraAdminApi { ...@@ -124,7 +124,10 @@ export default class ZimbraAdminApi {
const result = {}; const result = {};
const coses = data.get().CountAccountResponse.cos; const coses = data.get().CountAccountResponse.cos;
coses.forEach((cos) => { coses.forEach((cos) => {
result[cos.name] = parseInt(cos._content); result[cos.name] = {
used: parseInt(cos._content),
id: cos.id
}
}); });
// const counts = Object.values(result); // const counts = Object.values(result);
// result.total = counts.reduce((a,b) => {return(a+b);}); // result.total = counts.reduce((a,b) => {return(a+b);});
......
...@@ -9,14 +9,27 @@ export default class Domain extends Zimbra { ...@@ -9,14 +9,27 @@ export default class Domain extends Zimbra {
} }
countAccounts(callback) { countAccounts(callback) {
const maxAccountsByCos = this.maxAccountsByCos();
this.api.countAccounts(this.id, function(e,d){ this.api.countAccounts(this.id, function(e,d){
if(e) return callback(e); if(e) return callback(e);
if (maxAccountsByCos) Object.entries(d).forEach((cos) => {
cos[1].limit = maxAccountsByCos[cos[1].id];
});
return callback(null, d); return callback(null, d);
}); });
} }
maxAccounts(callback) { maxAccountsByCos() {
const results = {};
if (typeof this.attrs.zimbraDomainCOSMaxAccounts === 'undefined') return null;
// zimbraDomainCOSMaxAccounts can be only a String
// so we force it into an Array
const accounts_limits = [].concat.apply([], [this.attrs.zimbraDomainCOSMaxAccounts]);
accounts_limits.forEach((cos) => {
const split = cos.split(/:/);
results[split[0]] = parseInt(split[1]);
});
return results;
} }
} }
...@@ -13,7 +13,13 @@ export default class Zimbra { ...@@ -13,7 +13,13 @@ export default class Zimbra {
buildAttrsMap(obj_ary) { buildAttrsMap(obj_ary) {
const attrs = {}; const attrs = {};
obj_ary.forEach((r) => { obj_ary.forEach((r) => {
if (attrs[r.n]) {
const ary = [attrs[r.n]];
attrs[r.n] = ary;
attrs[r.n].push(r._content);
} else {
attrs[r.n] = r._content; attrs[r.n] = r._content;
}
}); });
return attrs; return attrs;
} }
......
...@@ -327,7 +327,7 @@ ...@@ -327,7 +327,7 @@
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
api.countAccounts('zboxapp.dev', function(err, data){ api.countAccounts('zboxapp.dev', function(err, data){
if (err) console.error(err); if (err) console.error(err);
expect(data.default).to.be.above(1); expect(data.default.used).to.be.above(1);
done(); done();
}); });
}); });
...@@ -339,7 +339,19 @@ ...@@ -339,7 +339,19 @@
if (err) console.error(err); if (err) console.error(err);
let domain = data; let domain = data;
domain.countAccounts(function(e, d){ domain.countAccounts(function(e, d){
expect(d.default).to.be.above(1); expect(d.default.used).to.be.above(1);
done();
});
});
});
it('domain.countAccounts() should return the account Limits', function(done){
let api = new ZimbraAdminApi(auth_data);
api.getDomain('customer.dev', function(err, data){
if (err) console.error(err);
let domain = data;
domain.countAccounts(function(e, d){
expect(d.basic.limit).to.be.above(1);
done(); done();
}); });
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment