Commit 0a7d584a authored by Patricio Bruna's avatar Patricio Bruna

Return Domain Admins

parent 458a4bf5
...@@ -316,3 +316,13 @@ domain.countAccounts(callback); ...@@ -316,3 +316,13 @@ domain.countAccounts(callback);
``` ```
If the `Domain` is empty, no 'Accounts', the result will be a `{}`. If the `Domain` is empty, no 'Accounts', the result will be a `{}`.
### Domain Admins
Return an Array of the Domain Admins `Accounts`.
```javascript
// domain is a Domain, you got it from zimbraApi.getDomain....
domain.admins(callback);
// [Account, Account]
```
...@@ -13103,7 +13103,47 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13103,7 +13103,47 @@ return /******/ (function(modules) { // webpackBootstrap
return _this; return _this;
} }
// TODO: Fix this fucking ugly code
(0, _createClass3.default)(Domain, [{ (0, _createClass3.default)(Domain, [{
key: 'admins',
value: function admins(callback) {
var that = this;
this.getAdminsIdsFromGrants(function (e, d) {
if (e) return callback(e);
if (d.length < 1) return [];
var query = "(|";
d.forEach(function (id) {
var zimbra_id = '(zimbraId=' + id + ')';
query += zimbra_id;
});
query += ")";
that.api.getAllAccounts(function (e, d) {
if (e) return callback(e);
if (d.total > 0) return callback(null, d.account);
callback(null, []);
}, { query: query });
});
}
// Return the ZimbraId if the grantee have the domainAdminRights right
// Grant.right_name() == domainAdminRights
}, {
key: 'getAdminsIdsFromGrants',
value: function getAdminsIdsFromGrants(callback) {
var ids = [];
var target_data = { type: 'domain', identifier: this.id };
this.api.getGrants(target_data, null, function (error, data) {
if (error) return callback(error);
if (data.length > 0) data.forEach(function (grant) {
if (grant.isDomainAdminGrant()) ids.push(grant.granteeId);
});
return callback(null, ids);
});
}
}, {
key: 'countAccounts', key: 'countAccounts',
value: function countAccounts(callback) { value: function countAccounts(callback) {
var maxAccountsByCos = this.maxAccountsByCos(); var maxAccountsByCos = this.maxAccountsByCos();
...@@ -40146,7 +40186,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -40146,7 +40186,7 @@ return /******/ (function(modules) { // webpackBootstrap
/* 283 */ /* 283 */
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports, __webpack_require__) {
"use strict"; 'use strict';
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
...@@ -40156,19 +40196,36 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -40156,19 +40196,36 @@ return /******/ (function(modules) { // webpackBootstrap
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = __webpack_require__(69);
var _createClass3 = _interopRequireDefault(_createClass2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Copyright (c) 2016 ZBox, Spa. All Rights Reserved. // Copyright (c) 2016 ZBox, Spa. All Rights Reserved.
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
var Grant = function Grant(grant) { var Grant = function () {
(0, _classCallCheck3.default)(this, Grant); function Grant(grant) {
(0, _classCallCheck3.default)(this, Grant);
this.grantee = grant.grantee[0]; this.grantee = grant.grantee[0];
this.target = grant.target[0]; this.target = grant.target[0];
this.right = grant.right[0]; this.right = grant.right[0];
}; this.rightName = this.right._content;
this.granteeId = this.grantee.id;
}
(0, _createClass3.default)(Grant, [{
key: 'isDomainAdminGrant',
value: function isDomainAdminGrant() {
if (this.rightName === 'domainAdminRights') return true;
return false;
}
}]);
return Grant;
}();
exports.default = Grant; exports.default = Grant;
/***/ } /***/ }
This diff is collapsed.
...@@ -9,6 +9,40 @@ export default class Domain extends Zimbra { ...@@ -9,6 +9,40 @@ export default class Domain extends Zimbra {
this.domainAdminRights = 'domainAdminRights'; this.domainAdminRights = 'domainAdminRights';
} }
// TODO: Fix this fucking ugly code
admins(callback) {
const that = this;
this.getAdminsIdsFromGrants(function(e,d){
if (e) return callback(e);
if (d.length < 1) return [];
let query = "(|";
d.forEach((id) => {
const zimbra_id = `(zimbraId=${id})`;
query += zimbra_id;
});
query += ")";
that.api.getAllAccounts(function(e,d){
if (e) return callback(e);
if (d.total > 0) return callback(null, d.account);
callback(null, []);
}, {query: query});
});
}
// Return the ZimbraId if the grantee have the domainAdminRights right
// Grant.right_name() == domainAdminRights
getAdminsIdsFromGrants(callback) {
const ids = [];
const target_data = { type: 'domain', identifier: this.id };
this.api.getGrants(target_data, null, function(error, data){
if (error) return callback(error);
if (data.length > 0) data.forEach((grant) => {
if (grant.isDomainAdminGrant()) ids.push(grant.granteeId);
});
return callback(null, ids);
});
}
countAccounts(callback) { countAccounts(callback) {
const maxAccountsByCos = this.maxAccountsByCos(); const maxAccountsByCos = this.maxAccountsByCos();
this.api.countAccounts(this.id, function(e,d){ this.api.countAccounts(this.id, function(e,d){
......
...@@ -6,5 +6,13 @@ export default class Grant { ...@@ -6,5 +6,13 @@ export default class Grant {
this.grantee = grant.grantee[0]; this.grantee = grant.grantee[0];
this.target = grant.target[0]; this.target = grant.target[0];
this.right = grant.right[0]; this.right = grant.right[0];
this.rightName = this.right._content;
this.granteeId = this.grantee.id;
} }
isDomainAdminGrant() {
if (this.rightName === 'domainAdminRights') return true;
return false;
}
} }
...@@ -340,6 +340,31 @@ ...@@ -340,6 +340,31 @@
}); });
}); });
it('domain.admins() should return the domain admins', function(done){
let api = new ZimbraAdminApi(auth_data);
api.getDomain('customer.dev', function(err, data){
if (err) console.error(err);
let domain = data;
domain.admins(function(e, d){
expect(d.length).to.be.above(1);
expect(d[0].constructor.name).to.be.equal('Account');
done();
});
});
});
it('domain.admins() should return empty array if no admins', function(done){
let api = new ZimbraAdminApi(auth_data);
api.getDomain('zboxapp.dev', function(err, data){
if (err) console.error(err);
let domain = data;
domain.admins(function(e, d){
expect(d.length).to.be.empty;
done();
});
});
});
}); });
describe('DistributionList tests', function() { describe('DistributionList tests', function() {
......
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