Commit 631ba8a7 authored by Patricio Bruna's avatar Patricio Bruna

Commit

parents 091e2577 b4421e32
{ {
"esnext": true "esnext": true,
"node": true,
"predef": [ "describe", "it", "beforeEach", "afterEach" ]
} }
...@@ -9,7 +9,10 @@ server.js ...@@ -9,7 +9,10 @@ server.js
webpack.config.js webpack.config.js
lib/ lib/
TODOS.md TODOS.md
<<<<<<< HEAD
=======
>>>>>>> manager
.* .*
### JetBrains template ### JetBrains template
......
...@@ -306,21 +306,16 @@ account.setPassword(password, callback); ...@@ -306,21 +306,16 @@ account.setPassword(password, callback);
### Enable and Disable Archive ### Enable and Disable Archive
**Only Zimbra Network Edition** **Only Zimbra Network Edition**
`Enable` can take the following options: You **must** pass a `COS Name` or `CosID` as firt params
* **create**: `(0|1)` if the archive mailbox should be created. Default its 1, create.
* **name**: Name of the archive mailbox, if empty the template will be used.
* **cos_id**: Name or ID of the COS to assign to the archive mailbox.
* **password**: password of the archive mailbox.
* **attributes**.
```javascript ```javascript
account.enableArchive({ cos_id: 'default' }, callback); account.enableArchiving('default', callback);
// {} // Account {}
// account.archiveEnabled === true;
account.disableArchive(callback); account.disableArchiving(callback);
// {} // Account {}
// account.archiveEnabled === false;
``` ```
### Get Mailbox ### Get Mailbox
...@@ -389,6 +384,20 @@ zimbraApi.getAllCos(callback); ...@@ -389,6 +384,20 @@ zimbraApi.getAllCos(callback);
## Domains ## Domains
This are functions especifics to `Domains`. This are functions especifics to `Domains`.
### isAliasDomain & masterDomainName
These are `properties`, **not functions**.
* `isAliasDomain`, return if a Domain is an Alias Domain.
* `masterDomainName`, return the name of the master domain.
```
domain.isAliasDomain
// true || false
domain.masterDomainName
// example.com
```
### Count Accounts ### Count Accounts
Count number of accounts by `CoS` in a domain. Count number of accounts by `CoS` in a domain.
...@@ -437,7 +446,7 @@ const coses = ['default', 'test', 'professional']; ...@@ -437,7 +446,7 @@ const coses = ['default', 'test', 'professional'];
domain.addAdmin(account.id, coses, callback); domain.addAdmin(account.id, coses, callback);
// {} if Success // {} if Success
domain.removeAdmin(account.id, callback); domain.removeAdmin(account.id, coses, callback);
// {} if Success // {} if Success
``` ```
......
...@@ -302,10 +302,17 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -302,10 +302,17 @@ return /******/ (function(modules) { // webpackBootstrap
// type: (account|cos|dl|domain), // type: (account|cos|dl|domain),
// identifier: (name or zimbraId) // identifier: (name or zimbraId)
// } // }
// Right {
// deny: 0|1,
// canDelegate: 0|1,
// disinheritSubGroups: 0|1,
// subDomain: 0|1,
// _content: <RightName>
// }
}, { }, {
key: 'grantRight', key: 'grantRight',
value: function grantRight(target_data, grantee_data, right_name, callback) { value: function grantRight(target_data, grantee_data, right, callback) {
var request_data = this.buildRequestData('GrantRight', callback); var request_data = this.buildRequestData('GrantRight', callback);
var target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data); var target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data);
var target = target_grantee[0]; var target = target_grantee[0];
...@@ -313,7 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -313,7 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
request_data.params.params.grantee = grantee; request_data.params.params.grantee = grantee;
request_data.params.params.target = target; request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name }; request_data.params.params.right = right;
return this.performRequest(request_data); return this.performRequest(request_data);
} }
...@@ -366,12 +373,12 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -366,12 +373,12 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
var account = { by: this.dictionary.byIdOrName(account_id), _content: account_id }; var account = { by: this.dictionary.byIdOrName(account_id), _content: account_id };
var archive = { var archive = {
create: options.archive || 1, create: options.create || 1,
name: { '_content': options.name }, cos: { by: this.dictionary.byIdOrName(options.cos), '_content': options.cos }
cos: { by: this.dictionary.byIdOrName(options.cos_id), '_content': options.cos_id },
password: { '_content': options.password },
a: this.dictionary.attributesToArray(options.attributes)
}; };
if (options.name) archive.name = { '_content': options.name };
if (options.password) archive.password = { '_content': options.password };
if (options.attributes) archive.a = this.dictionary.attributesToArray(options.attributes || {});
request_data.params.params.account = account; request_data.params.params.account = account;
request_data.params.params.archive = archive; request_data.params.params.archive = archive;
return this.performRequest(request_data); return this.performRequest(request_data);
...@@ -421,6 +428,34 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -421,6 +428,34 @@ return /******/ (function(modules) { // webpackBootstrap
var resource_data = this.buildResourceData(name, attributes); var resource_data = this.buildResourceData(name, attributes);
return this.create('DistributionList', resource_data, callback); return this.create('DistributionList', resource_data, callback);
} }
// flushData = {
// type: Comma separated list of cache types. e.g. from skin|locale|account|cos|domain|server|zimlet,
// allServers: 0|1,
// entry: Name or Id of the object, should be relevant to type
// }
}, {
key: 'flushCache',
value: function flushCache() {
var flushData = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var callback = arguments[1];
var request_data = this.buildRequestData('FlushCache', callback);
request_data.parse_response = ResponseParser.emptyResponse;
request_data.params.params = {
cache: {
type: flushData.type,
allServers: flushData.allServers || 0,
'_content': { entry: {} }
}
};
if (flushData.entry) request_data.params.params.cache._content.entry = {
'by': this.dictionary.byIdOrName(flushData.entry),
'_content': flushData.entry
};
return this.performRequest(request_data);
}
}, { }, {
key: 'getAllDomains', key: 'getAllDomains',
value: function getAllDomains(callback, query_object) { value: function getAllDomains(callback, query_object) {
...@@ -2481,6 +2516,13 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -2481,6 +2516,13 @@ return /******/ (function(modules) { // webpackBootstrap
this.token = response.get().AuthResponse.authToken[0]._content; this.token = response.get().AuthResponse.authToken[0]._content;
if ( response.get().AuthResponse.session && response.get().AuthResponse.session.id ) {
this.session = {
type: response.get().AuthResponse.session.type,
id: response.get().AuthResponse.session.id
}
}
if (this.debug) { if (this.debug) {
LOG.info('Retrieved auth token %s', this.token); LOG.info('Retrieved auth token %s', this.token);
} }
...@@ -2776,6 +2818,8 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -2776,6 +2818,8 @@ return /******/ (function(modules) { // webpackBootstrap
} }
requestOptions.context.session = this.session ? this.session : {};
var request; var request;
try { try {
...@@ -30739,7 +30783,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -30739,7 +30783,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = { module.exports = {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.2.6", "version": "0.2.15",
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
...@@ -31750,6 +31794,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31750,6 +31794,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Domain).call(this, domain_obj, zimbra_api_client)); var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Domain).call(this, domain_obj, zimbra_api_client));
_this.domainAdminRights = 'domainAdminRights'; _this.domainAdminRights = 'domainAdminRights';
_this.checkAliasDomain();
return _this; return _this;
} }
...@@ -31759,54 +31804,96 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31759,54 +31804,96 @@ return /******/ (function(modules) { // webpackBootstrap
(0, _createClass3.default)(Domain, [{ (0, _createClass3.default)(Domain, [{
key: 'addAdmin', key: 'addAdmin',
value: function addAdmin(account_id) { value: function addAdmin(account_id) {
var _this2 = this;
var coses = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; var coses = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var callback = arguments[2]; var callback = arguments[2];
var request_data = {};
var grantee_data = { 'type': 'usr', 'identifier': account_id }; var grantee_data = { 'type': 'usr', 'identifier': account_id };
var modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }); var specialRighsReqs = this.grantSpecialDomainRights(grantee_data);
var grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights); var cosRights = this.assignCosRights(grantee_data, coses, null);
var cosesRights = this.buildCosesGrantsRequest(coses, grantee_data); var rightReqs = specialRighsReqs.concat(cosRights.requests);
request_data.requests = [modifyAccountRequest, grantRightRequest]; this.addDelegatedAttributeToAccount(account_id, function (err, data) {
request_data.requests = request_data.requests.concat(cosesRights);
request_data.batch = true;
request_data.callback = function (err, data) {
if (err) return callback(err); if (err) return callback(err);
callback(null, data.GrantRightResponse); _this2.api.makeBatchRequest(rightReqs, function (err, data) {
}; if (err) return callback(err);
this.api.performRequest(request_data); return _this2.api.getDomain(_this2.id, callback);
}, { onError: 'continue' });
});
}
// This function grants several rights needed to manage the domain, as:
// * access to modify DLs owners,
// * access to modify domain Amavis Lists
// * access to add other domain admins
// * access to modify account cos
}, {
key: 'grantSpecialDomainRights',
value: function grantSpecialDomainRights(grantee_data) {
var requests = [];
requests.push(this.grantRight(grantee_data, { '_content': this.domainAdminRights, canDelegate: 1 }));
requests.push(this.grantRight(grantee_data, { '_content': 'set.dl.zimbraACE', canDelegate: 1 }));
requests.push(this.grantRight(grantee_data, { '_content': 'set.domain.amavisWhitelistSender', canDelegate: 1 }));
requests.push(this.grantRight(grantee_data, { '_content': 'set.domain.amavisBlacklistSender', canDelegate: 1 }));
return requests;
}
}, {
key: 'addDelegatedAttributeToAccount',
value: function addDelegatedAttributeToAccount(account_id, callback) {
this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }, function (err, data) {
if (err) return callback(err);
return callback(null, data);
});
}
// This functions add the rights to the domain admin
// to be able to change the accounts cos
}, {
key: 'assignCosRights',
value: function assignCosRights(grantee_data, coses, callback) {
var revoke = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
var request_data = {};
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke);
request_data.batch = true;
request_data.callback = callback;
return this.api.performRequest(request_data);
} }
}, { }, {
key: 'buildCosesGrantsRequest', key: 'buildCosesGrantsRequest',
value: function buildCosesGrantsRequest() { value: function buildCosesGrantsRequest() {
var _this2 = this;
var coses = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; var coses = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
var _this3 = this;
var grantee_data = arguments[1]; var grantee_data = arguments[1];
var revoke = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
var requests = []; var requests = [];
var right = { '_content': 'assignCos' };
coses.forEach(function (c) { coses.forEach(function (c) {
var target_data = { type: 'cos', identifier: c }; var target_data = { type: 'cos', identifier: c };
var grants = _this2.buildCosGrantByAcl(target_data, grantee_data); var grant = null;
requests.push(grants); if (revoke) {
grant = _this3.api.revokeRight(target_data, grantee_data, 'assignCos');
} else {
grant = _this3.api.grantRight(target_data, grantee_data, right);
}
requests.push(grant);
}); });
return [].concat.apply([], requests); return requests;
} }
// Return an array with all the rights
// needed 'assignCos', 'listCos', 'getCos'
}, { }, {
key: 'buildCosGrantByAcl', key: 'checkAliasDomain',
value: function buildCosGrantByAcl(target_data, grantee_data) { value: function checkAliasDomain() {
var _this3 = this; this.isAliasDomain = this.attrs.zimbraDomainType === 'alias' ? true : false;
var masterDomain = this.attrs.zimbraMailCatchAllForwardingAddress;
var grants = []; if (this.isAliasDomain && masterDomain) {
['assignCos', 'listCos', 'getCos'].forEach(function (right) { this.masterDomainName = masterDomain.split(/@/)[1];
var request = _this3.api.grantRight(target_data, grantee_data, right); }
grants.push(request); return true;
});
return grants;
} }
// TODO: Fix this fucking ugly code // TODO: Fix this fucking ugly code
...@@ -31815,7 +31902,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31815,7 +31902,7 @@ return /******/ (function(modules) { // webpackBootstrap
key: 'getAdmins', key: 'getAdmins',
value: function getAdmins(callback) { value: function getAdmins(callback) {
var that = this; var that = this;
var admins_ids = this.getAdminsIdsFromGrants(); var admins_ids = this.getAdminsIdsFromGrants(this.attrs.zimbraACE);
var query = this.makeAdminIdsQuery(admins_ids); var query = this.makeAdminIdsQuery(admins_ids);
return this.api.getAllAccounts(callback, { query: query }); return this.api.getAllAccounts(callback, { query: query });
} }
...@@ -31825,12 +31912,13 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31825,12 +31912,13 @@ return /******/ (function(modules) { // webpackBootstrap
}, { }, {
key: 'getAdminsIdsFromGrants', key: 'getAdminsIdsFromGrants',
value: function getAdminsIdsFromGrants() { value: function getAdminsIdsFromGrants(zimbraACES) {
var _this4 = this; var _this4 = this;
var ids = []; var ids = [];
this.parseACL(this.attrs.zimbraACE).forEach(function (grantee) { var regex = new RegExp(this.domainAdminRights + '$');
if (grantee.right === _this4.domainAdminRights) ids.push(grantee.id); this.parseACL(zimbraACES).forEach(function (grantee) {
if (regex.test(_this4.domainAdminRights)) ids.push(grantee.id);
}); });
return ids; return ids;
} }
...@@ -31888,12 +31976,17 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31888,12 +31976,17 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}, { }, {
key: 'removeAdmin', key: 'removeAdmin',
value: function removeAdmin(account_id, callback) { value: function removeAdmin(account_id, coses, callback) {
var _this5 = this;
var grantee_data = { var grantee_data = {
'type': 'usr', 'type': 'usr',
'identifier': account_id 'identifier': account_id
}; };
this.revokeRight(grantee_data, this.domainAdminRights, callback); this.revokeRight(grantee_data, this.domainAdminRights, function (err, data) {
if (err) return callback(err);
_this5.assignCosRights(grantee_data, coses, callback, true);
});
} }
}]); }]);
return Domain; return Domain;
...@@ -32196,15 +32289,17 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32196,15 +32289,17 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}, { }, {
key: 'grantRight', key: 'grantRight',
value: function grantRight(grantee_data, right_name, callback, forBatch) { value: function grantRight(grantee_data, right) {
forBatch = forBatch || false; var callback = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right, callback);
} }
}, { }, {
key: 'revokeRight', key: 'revokeRight',
value: function revokeRight(grantee_data, right_name, callback, forBatch) { value: function revokeRight(grantee_data, right_name) {
forBatch = forBatch || false; var callback = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
} }
}]); }]);
return Zimbra; return Zimbra;
...@@ -32254,6 +32349,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32254,6 +32349,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Account).call(this, account_obj, zimbra_api_client)); var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Account).call(this, account_obj, zimbra_api_client));
_this.domain = _this.name.split(/@/)[1]; _this.domain = _this.name.split(/@/)[1];
_this.archiveEnabled = _this.attrs.zimbraArchiveEnabled === 'TRUE';
return _this; return _this;
} }
...@@ -32285,14 +32381,23 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32285,14 +32381,23 @@ return /******/ (function(modules) { // webpackBootstrap
} }
} }
}, { }, {
key: 'enableArchive', key: 'enableArchiving',
value: function enableArchive(options, callback) { value: function enableArchiving(cos, callback) {
return this.api.enableArchive(this.id, options, callback); var that = this;
var options = { cos: cos };
return this.api.enableArchive(this.id, options, function (err, data) {
if (err) return callback(err);
return that.api.getAccount(that.id, callback);
});
} }
}, { }, {
key: 'disableArchive', key: 'disableArchiving',
value: function disableArchive(callback) { value: function disableArchiving(callback) {
return this.api.disableArchive(this.id, callback); var that = this;
return this.api.disableArchive(this.id, function (err, data) {
if (err) return callback(err);
return that.api.getAccount(that.id, callback);
});
} }
}, { }, {
key: 'setPassword', key: 'setPassword',
...@@ -32498,14 +32603,29 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32498,14 +32603,29 @@ return /******/ (function(modules) { // webpackBootstrap
value: function addMembers(members, callback) { value: function addMembers(members, callback) {
this.api.addDistributionListMember(this.id, members, callback); this.api.addDistributionListMember(this.id, members, callback);
} }
// addOwner(account_id, callback) {
// const grantee_data = {
// 'type': 'usr',
// 'identifier': account_id
// }
// this.grantRight(grantee_data, this.ownerRights, callback);
// }
}, { }, {
key: 'addOwner', key: 'addOwner',
value: function addOwner(account_id, callback) { value: function addOwner(account_id, callback) {
var grantee_data = { var _this2 = this;
'type': 'usr',
'identifier': account_id var zimbraACES = this.attrs.zimbraACE ? [].concat.apply([], [this.attrs.zimbraACE]) : [];
}; this.api.getAccount(account_id, function (err, data) {
this.grantRight(grantee_data, this.ownerRights, callback); if (err) return callback(err);
var account = data;
var newZimbraACE = account.id + ' usr sendToDistList';
zimbraACES.push(newZimbraACE);
var attrs = { zimbraACE: zimbraACES };
return _this2.api.modifyDistributionList(_this2.id, attrs, callback);
});
} }
// return the ID of the owner // return the ID of the owner
...@@ -32559,14 +32679,32 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32559,14 +32679,32 @@ return /******/ (function(modules) { // webpackBootstrap
value: function removeMembers(members, callback) { value: function removeMembers(members, callback) {
this.api.removeDistributionListMember(this.id, members, callback); this.api.removeDistributionListMember(this.id, members, callback);
} }
// removeOwner(account_id, callback) {
// const grantee_data = {
// 'type': 'usr',
// 'identifier': account_id
// }
// this.revokeRight(grantee_data, this.ownerRights, callback);
// }
}, { }, {
key: 'removeOwner', key: 'removeOwner',
value: function removeOwner(account_id, callback) { value: function removeOwner(account_id, callback) {
var grantee_data = { var _this3 = this;
'type': 'usr',
'identifier': account_id if (!this.attrs.zimbraACE) return this;
}; var zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]);
this.revokeRight(grantee_data, this.ownerRights, callback); this.api.getAccount(account_id, function (err, account) {
if (err) return callback(err);
var newACES = zimbraACES.filter(function (ace) {
var granteeId = ace.split(/ /)[0];
if (account.id !== granteeId) return true;
return false;
});
var attrs = newACES.length > 0 ? { zimbraACE: newACES } : { zimbraACE: '' };
return _this3.api.modifyDistributionList(_this3.id, attrs, callback);
});
} }
}, { }, {
key: 'rename', key: 'rename',
......
{ {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
<<<<<<< HEAD
"version": "0.2.9", "version": "0.2.9",
=======
"version": "0.2.10",
>>>>>>> manager
"main": "src/index.js", "main": "src/index.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
......
...@@ -216,7 +216,15 @@ class ZimbraAdminApi { ...@@ -216,7 +216,15 @@ class ZimbraAdminApi {
// type: (account|cos|dl|domain), // type: (account|cos|dl|domain),
// identifier: (name or zimbraId) // identifier: (name or zimbraId)
// } // }
grantRight(target_data, grantee_data, right_name, callback) { // Right {
// deny: 0|1,
// canDelegate: 0|1,
// disinheritSubGroups: 0|1,
// subDomain: 0|1,
// _content: <RightName>
// }
grantRight(target_data, grantee_data, right, callback) {
const request_data = this.buildRequestData('GrantRight', callback); const request_data = this.buildRequestData('GrantRight', callback);
const target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data); const target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data);
const target = target_grantee[0]; const target = target_grantee[0];
...@@ -224,7 +232,7 @@ class ZimbraAdminApi { ...@@ -224,7 +232,7 @@ class ZimbraAdminApi {
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
request_data.params.params.grantee = grantee; request_data.params.params.grantee = grantee;
request_data.params.params.target = target; request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name }; request_data.params.params.right = right;
return this.performRequest(request_data); return this.performRequest(request_data);
} }
...@@ -266,12 +274,12 @@ class ZimbraAdminApi { ...@@ -266,12 +274,12 @@ class ZimbraAdminApi {
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
const account = { by: this.dictionary.byIdOrName(account_id), _content: account_id }; const account = { by: this.dictionary.byIdOrName(account_id), _content: account_id };
const archive = { const archive = {
create: (options.archive || 1), create: (options.create || 1),
name: { '_content': options.name }, cos: { by: this.dictionary.byIdOrName(options.cos), '_content': options.cos }
cos: { by: this.dictionary.byIdOrName(options.cos_id), '_content': options.cos_id },
password: { '_content': options.password },
a: this.dictionary.attributesToArray(options.attributes)
}; };
if (options.name) archive.name = { '_content': options.name };
if (options.password) archive.password = { '_content': options.password };
if (options.attributes) archive.a = this.dictionary.attributesToArray(options.attributes || {});
request_data.params.params.account = account; request_data.params.params.account = account;
request_data.params.params.archive = archive; request_data.params.params.archive = archive;
return this.performRequest(request_data); return this.performRequest(request_data);
...@@ -336,6 +344,28 @@ class ZimbraAdminApi { ...@@ -336,6 +344,28 @@ class ZimbraAdminApi {
return this.create('DistributionList', resource_data, callback); return this.create('DistributionList', resource_data, callback);
} }
// flushData = {
// type: Comma separated list of cache types. e.g. from skin|locale|account|cos|domain|server|zimlet,
// allServers: 0|1,
// entry: Name or Id of the object, should be relevant to type
// }
flushCache(flushData = {}, callback) {
const request_data = this.buildRequestData('FlushCache', callback);
request_data.parse_response = ResponseParser.emptyResponse;
request_data.params.params = {
cache: {
type: flushData.type,
allServers: (flushData.allServers || 0),
'_content': { entry: { } }
}
};
if (flushData.entry) request_data.params.params.cache._content.entry = {
'by': this.dictionary.byIdOrName(flushData.entry),
'_content': flushData.entry
}
return this.performRequest(request_data);
}
getAllDomains(callback, query_object) { getAllDomains(callback, query_object) {
query_object = query_object || {}; query_object = query_object || {};
query_object.types = 'domains'; query_object.types = 'domains';
......
...@@ -9,6 +9,7 @@ class Account extends Zimbra { ...@@ -9,6 +9,7 @@ class Account extends Zimbra {
constructor(account_obj, zimbra_api_client) { constructor(account_obj, zimbra_api_client) {
super(account_obj, zimbra_api_client); super(account_obj, zimbra_api_client);
this.domain = this.name.split(/@/)[1]; this.domain = this.name.split(/@/)[1];
this.archiveEnabled = this.attrs.zimbraArchiveEnabled === 'TRUE';
} }
addAccountAlias(alias, callback) { addAccountAlias(alias, callback) {
...@@ -35,12 +36,21 @@ class Account extends Zimbra { ...@@ -35,12 +36,21 @@ class Account extends Zimbra {
} }
} }
enableArchive(options, callback) { enableArchiving(cos, callback) {
return this.api.enableArchive(this.id, options, callback); const that = this;
const options = { cos: cos };
return this.api.enableArchive(this.id, options, function(err, data){
if (err) return callback(err);
return that.api.getAccount(that.id, callback);
});
} }
disableArchive(callback) { disableArchiving(callback) {
return this.api.disableArchive(this.id, callback); const that = this;
return this.api.disableArchive(this.id, function(err, data){
if (err) return callback(err);
return that.api.getAccount(that.id, callback);
});
} }
setPassword(password, callback) { setPassword(password, callback) {
...@@ -69,4 +79,4 @@ class Account extends Zimbra { ...@@ -69,4 +79,4 @@ class Account extends Zimbra {
} }
module.exports = Account; module.exports = Account;
\ No newline at end of file
...@@ -17,12 +17,23 @@ class DistributionList extends Zimbra { ...@@ -17,12 +17,23 @@ class DistributionList extends Zimbra {
this.api.addDistributionListMember(this.id, members, callback); this.api.addDistributionListMember(this.id, members, callback);
} }
// addOwner(account_id, callback) {
// const grantee_data = {
// 'type': 'usr',
// 'identifier': account_id
// }
// this.grantRight(grantee_data, this.ownerRights, callback);
// }
addOwner(account_id, callback) { addOwner(account_id, callback) {
const grantee_data = { const zimbraACES = this.attrs.zimbraACE ? [].concat.apply([], [this.attrs.zimbraACE]) : [];
'type': 'usr', this.api.getAccount(account_id, (err, data) => {
'identifier': account_id if (err) return callback(err);
} const account = data;
this.grantRight(grantee_data, this.ownerRights, callback); const newZimbraACE = `${account.id} usr sendToDistList`;
zimbraACES.push(newZimbraACE);
const attrs = {zimbraACE: zimbraACES};
return this.api.modifyDistributionList(this.id, attrs, callback);
});
} }
// return the ID of the owner // return the ID of the owner
...@@ -69,12 +80,26 @@ class DistributionList extends Zimbra { ...@@ -69,12 +80,26 @@ class DistributionList extends Zimbra {
this.api.removeDistributionListMember(this.id, members, callback); this.api.removeDistributionListMember(this.id, members, callback);
} }
// removeOwner(account_id, callback) {
// const grantee_data = {
// 'type': 'usr',
// 'identifier': account_id
// }
// this.revokeRight(grantee_data, this.ownerRights, callback);
// }
removeOwner(account_id, callback) { removeOwner(account_id, callback) {
const grantee_data = { if (!this.attrs.zimbraACE) return this;
'type': 'usr', const zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]);
'identifier': account_id this.api.getAccount(account_id, (err, account) => {
} if (err) return callback(err);
this.revokeRight(grantee_data, this.ownerRights, callback); const newACES = zimbraACES.filter((ace) =>{
const granteeId = ace.split(/ /)[0];
if (account.id !== granteeId) return true;
return false;
});
const attrs = (newACES.length > 0) ? {zimbraACE: newACES} : {zimbraACE: ''};
return this.api.modifyDistributionList(this.id, attrs, callback);
});
} }
rename(new_name, callback) { rename(new_name, callback) {
...@@ -84,4 +109,4 @@ class DistributionList extends Zimbra { ...@@ -84,4 +109,4 @@ class DistributionList extends Zimbra {
} }
module.exports = DistributionList; module.exports = DistributionList;
\ No newline at end of file
...@@ -9,60 +9,104 @@ class Domain extends Zimbra { ...@@ -9,60 +9,104 @@ class Domain extends Zimbra {
constructor(domain_obj, zimbra_api_client) { constructor(domain_obj, zimbra_api_client) {
super(domain_obj, zimbra_api_client); super(domain_obj, zimbra_api_client);
this.domainAdminRights = 'domainAdminRights'; this.domainAdminRights = 'domainAdminRights';
this.checkAliasDomain();
} }
// TODO: Too ugly code // TODO: Too ugly code
<<<<<<< HEAD
addAdmin(account_id, coses, callback) { addAdmin(account_id, coses, callback) {
const request_data = {}; const request_data = {};
=======
addAdmin(account_id, coses = [], callback) {
>>>>>>> manager
const grantee_data = { 'type': 'usr', 'identifier': account_id }; const grantee_data = { 'type': 'usr', 'identifier': account_id };
const modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }); const specialRighsReqs = this.grantSpecialDomainRights(grantee_data);
const grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights); const cosRights = this.assignCosRights(grantee_data, coses, null);
const cosesRights = this.buildCosesGrantsRequest(coses, grantee_data); const rightReqs = specialRighsReqs.concat(cosRights.requests);
request_data.requests = [modifyAccountRequest, grantRightRequest]; this.addDelegatedAttributeToAccount(account_id, (err,data) => {
request_data.requests = request_data.requests.concat(cosesRights);
request_data.batch = true;
request_data.callback = function(err, data) {
if (err) return callback(err); if (err) return callback(err);
callback(null, data.GrantRightResponse); this.api.makeBatchRequest(rightReqs, (err, data) => {
}; if (err) return callback(err);
this.api.performRequest(request_data); return this.api.getDomain(this.id, callback);
}, {onError: 'continue'});
});
} }
// This function grants several rights needed to manage the domain, as:
// * access to modify DLs owners,
// * access to modify domain Amavis Lists
// * access to add other domain admins
// * access to modify account cos
grantSpecialDomainRights(grantee_data) {
const requests = [];
requests.push(this.grantRight(grantee_data, {'_content': this.domainAdminRights, canDelegate: 1}));
requests.push(this.grantRight(grantee_data, {'_content': 'set.dl.zimbraACE', canDelegate: 1}));
requests.push(this.grantRight(grantee_data, {'_content': 'set.domain.amavisWhitelistSender', canDelegate: 1}));
requests.push(this.grantRight(grantee_data, {'_content': 'set.domain.amavisBlacklistSender', canDelegate: 1}));
return requests;
}
addDelegatedAttributeToAccount(account_id, callback) {
this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }, (err, data) => {
if (err) return callback(err);
return callback(null, data);
});
}
<<<<<<< HEAD
buildCosesGrantsRequest(coses, grantee_data) { buildCosesGrantsRequest(coses, grantee_data) {
=======
// This functions add the rights to the domain admin
// to be able to change the accounts cos
assignCosRights(grantee_data, coses, callback, revoke = false) {
const request_data = {};
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke);
request_data.batch = true;
request_data.callback = callback;
return this.api.performRequest(request_data);
}
buildCosesGrantsRequest(coses = [], grantee_data, revoke = false) {
>>>>>>> manager
const requests = []; const requests = [];
const right = {'_content': 'assignCos'};
coses.forEach((c) => { coses.forEach((c) => {
const target_data = { type: 'cos', identifier: c }; const target_data = { type: 'cos', identifier: c };
const grants = this.buildCosGrantByAcl(target_data, grantee_data); let grant = null;
requests.push(grants); if (revoke) {
grant = this.api.revokeRight(target_data, grantee_data, 'assignCos');
} else {
grant = this.api.grantRight(target_data, grantee_data, right);
}
requests.push(grant);
}); });
return [].concat.apply([], requests); return requests;
} }
// Return an array with all the rights checkAliasDomain() {
// needed 'assignCos', 'listCos', 'getCos' this.isAliasDomain = this.attrs.zimbraDomainType === 'alias' ? true : false;
buildCosGrantByAcl(target_data, grantee_data) { const masterDomain = this.attrs.zimbraMailCatchAllForwardingAddress;
const grants = []; if (this.isAliasDomain && masterDomain) {
['assignCos', 'listCos', 'getCos'].forEach((right) => { this.masterDomainName = masterDomain.split(/@/)[1];
const request = this.api.grantRight(target_data, grantee_data, right); }
grants.push(request); return true;
});
return grants;
} }
// TODO: Fix this fucking ugly code // TODO: Fix this fucking ugly code
getAdmins(callback) { getAdmins(callback) {
const that = this; const that = this;
const admins_ids = this.getAdminsIdsFromGrants(); const admins_ids = this.getAdminsIdsFromGrants(this.attrs.zimbraACE);
const query = this.makeAdminIdsQuery(admins_ids); const query = this.makeAdminIdsQuery(admins_ids);
return this.api.getAllAccounts(callback, {query: query}); return this.api.getAllAccounts(callback, {query: query});
} }
// Return the ZimbraId if the grantee have the domainAdminRights right // Return the ZimbraId if the grantee have the domainAdminRights right
// Grant.right_name() == domainAdminRights // Grant.right_name() == domainAdminRights
getAdminsIdsFromGrants() { getAdminsIdsFromGrants(zimbraACES) {
const ids = []; const ids = [];
this.parseACL(this.attrs.zimbraACE).forEach((grantee) => { const regex = new RegExp(`${this.domainAdminRights}$`);
if (grantee.right === this.domainAdminRights) ids.push(grantee.id); this.parseACL(zimbraACES).forEach((grantee) => {
if (regex.test(this.domainAdminRights)) ids.push(grantee.id);
}); });
return ids; return ids;
} }
...@@ -114,12 +158,15 @@ class Domain extends Zimbra { ...@@ -114,12 +158,15 @@ class Domain extends Zimbra {
return results; return results;
} }
removeAdmin(account_id, callback) { removeAdmin(account_id, coses, callback) {
const grantee_data = { const grantee_data = {
'type': 'usr', 'type': 'usr',
'identifier': account_id 'identifier': account_id
}; };
this.revokeRight(grantee_data, this.domainAdminRights, callback); this.revokeRight(grantee_data, this.domainAdminRights, (err, data) => {
if (err) return callback(err);
this.assignCosRights(grantee_data, coses, callback, true);
});
} }
} }
......
...@@ -58,14 +58,12 @@ class Zimbra { ...@@ -58,14 +58,12 @@ class Zimbra {
}); });
} }
grantRight(grantee_data, right_name, callback, forBatch){ grantRight(grantee_data, right, callback = null){
forBatch = forBatch || false; return this.api.grantRight(this.buildRighTargetData(), grantee_data, right, callback);
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
} }
revokeRight(grantee_data, right_name, callback, forBatch){ revokeRight(grantee_data, right_name, callback = null){
forBatch = forBatch || false; return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
} }
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
'url': 'http://zimbra.zboxapp.dev:9000/service/admin/soap', 'url': 'http://zimbra.zboxapp.dev:9000/service/admin/soap',
'user': 'admin@zboxapp.dev', 'user': 'admin@zboxapp.dev',
'password':'12345678' 'password':'12345678'
// 'user': 'superadmin2@zboxtest.com',
// 'password':'zboxapp2016'
}; };
describe('Basic tests', function() { describe('Basic tests', function() {
...@@ -22,6 +24,16 @@ ...@@ -22,6 +24,16 @@
}); });
}); });
it('Should Flush the Cache', function(done){
let api = new ZimbraAdminApi(auth_data);
const flush_data = {type: 'domain', allServers: 1, entry: 'zboxapp.dev'};
api.flushCache(flush_data, function(err, data){
if (err) console.log(err);
expect(err).to.not.exist;
done();
})
});
it('should get all domains', function(done) { it('should get all domains', function(done) {
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
api.getAllDomains(function(err, data){ api.getAllDomains(function(err, data){
...@@ -172,6 +184,7 @@ ...@@ -172,6 +184,7 @@
const getAllDomains = api.directorySearch({types: 'domains'}); const getAllDomains = api.directorySearch({types: 'domains'});
api.login(function(err, data){ api.login(function(err, data){
api.makeBatchRequest([deleteAccount, getAllDomains, getAllAccounts], function(err, data){ api.makeBatchRequest([deleteAccount, getAllDomains, getAllAccounts], function(err, data){
console.log(data);
expect(data.errors.length).to.be.above(1); expect(data.errors.length).to.be.above(1);
expect(data.errors[0].constructor.name).to.equal('Error'); expect(data.errors[0].constructor.name).to.equal('Error');
expect(data.errors[0].extra.code).to.exist; expect(data.errors[0].extra.code).to.exist;
...@@ -184,7 +197,7 @@ ...@@ -184,7 +197,7 @@
}); });
describe('Account tests', function() { describe('Account tests', function() {
this.timeout(5000); this.timeout(10000);
it('should create and return an account', function(done){ it('should create and return an account', function(done){
let account_name = Date.now() + '@big.com'; let account_name = Date.now() + '@big.com';
...@@ -284,7 +297,7 @@ ...@@ -284,7 +297,7 @@
it('Should Get The Account Mailbox', function(done){ it('Should Get The Account Mailbox', function(done){
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
api.getAccount('cos_basic_14@customer.dev', function(err, data){ api.getAccount('cos_basic_13@customer.dev', function(err, data){
let account = data; let account = data;
account.getMailbox(function(err, data){ account.getMailbox(function(err, data){
if (err) return console.log(err); if (err) return console.log(err);
...@@ -296,7 +309,7 @@ ...@@ -296,7 +309,7 @@
it('Should Get The Account Mailbox Size', function(done){ it('Should Get The Account Mailbox Size', function(done){
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
api.getAccount('cos_basic_14@customer.dev', function(err, data){ api.getAccount('cos_basic_13@customer.dev', function(err, data){
let account = data; let account = data;
account.getMailboxSize(function(err, data){ account.getMailboxSize(function(err, data){
if (err) return console.log(err); if (err) return console.log(err);
...@@ -377,12 +390,65 @@ ...@@ -377,12 +390,65 @@
}); });
}); });
// it('Should enable the account Archiving', function(done){
// let account_name = Date.now() + '@zboxtest.com';
// let account_password = Date.now();
// let api = new ZimbraAdminApi(auth_data);
// api.createAccount(account_name, account_password, {}, function(err, account){
// if (err) return console.log(err);
// account.enableArchiving('default', function(err, account){
// if (err) return console.log(err);
// expect(account.archiveEnabled).to.be.true;
// expect(account.attrs.zimbraArchiveAccount).to.match(/com\.archive$/);
// done();
// });
// });
// });
//
// it('Should disable the account Archiving', function(done){
// let account_name = Date.now() + '@zboxtest.com';
// let account_password = Date.now();
// let api = new ZimbraAdminApi(auth_data);
// api.createAccount(account_name, account_password, {}, function(err, account){
// if (err) return console.log(err);
// account.enableArchiving('default', function(err, account){
// if (err) return console.log(err);
// account.disableArchiving(function(err, account){
// if (err) return console.log(err);
// expect(account.archiveEnabled).to.be.false;
// expect(account.attrs.zimbraArchiveAccount).to.match(/com\.archive$/);
// done();
// });
// });
// });
// });
}); });
describe('Domain tests', function() { describe('Domain tests', function() {
this.timeout(5000); this.timeout(5000);
it('Should return if the domain is an alias Domain', function(done){
let api = new ZimbraAdminApi(auth_data);
api.getDomain('reseller.alias', function(err, data){
if (err) return console.log(err);
expect(data.isAliasDomain).to.be.true;
expect(data.masterDomainName).to.be.equal('reseller.dev');
done();
});
});
it('Should return false if the domain is not an alias Domain', function(done){
let api = new ZimbraAdminApi(auth_data);
api.getDomain('reseller.dev', function(err, data){
if (err) return console.log(err);
expect(data.isAliasDomain).to.be.false;
expect(data.masterDomainName).to.be.undefined;
done();
});
});
it('should create and return Domain', function(done){ it('should create and return Domain', function(done){
let resource_name = Date.now() + '.dev'; let resource_name = Date.now() + '.dev';
let resource_attributes = {}; let resource_attributes = {};
...@@ -522,9 +588,9 @@ ...@@ -522,9 +588,9 @@
it('addAdmin should add Admin', function(done){ it('addAdmin should add Admin', function(done){
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
let domain_admin = 'domain_admin@customer.dev'; let domain_admin = Date.now() + '@customer.dev';
let resource_name = Date.now() + '.dev'; let resource_name = Date.now() + '.dev';
api.getAccount(domain_admin, function(err, account){ api.createAccount(domain_admin, '12dda.222', {}, function(err, account){
api.createDomain(resource_name, {}, function(err, data){ api.createDomain(resource_name, {}, function(err, data){
if (err) console.error(err); if (err) console.error(err);
let domain = data; let domain = data;
...@@ -532,10 +598,17 @@ ...@@ -532,10 +598,17 @@
domain.addAdmin(account.id, coses, function(e, d){ domain.addAdmin(account.id, coses, function(e, d){
if (e) return console.error(e); if (e) return console.error(e);
expect(err).to.be.null; expect(err).to.be.null;
domain.getACLs(function(e, d){ d.getACLs(function(e, acls){
if (e) return console.error(e); if (e) return console.error(e);
expect(d[0].grantee.name).to.be.equal(account.name); const expectedGrants = ["domainAdminRights", "set.dl.zimbraACE", "set.domain.amavisBlacklistSender", "set.domain.amavisWhitelistSender"];
done(); const actualGrants = acls.map(function(acl){return acl.rightName}).sort()
expect(expectedGrants[0]).to.be.equal(actualGrants[0]);
expect(expectedGrants[2]).to.be.equal(actualGrants[2]);
d.getAdmins(function(e, admins){
if (e) return console.error(e);
expect(admins.account[0].name).to.be.equal(domain_admin);
done();
})
}); });
}); });
}); });
...@@ -548,7 +621,7 @@ ...@@ -548,7 +621,7 @@
let resource_name = Date.now() + '.dev'; let resource_name = Date.now() + '.dev';
api.createDomain(resource_name, {}, function(err, domain){ api.createDomain(resource_name, {}, function(err, domain){
domain.addAdmin(domain_admin, [], function(e, d){ domain.addAdmin(domain_admin, [], function(e, d){
domain.removeAdmin(domain_admin, function(e, d){ domain.removeAdmin(domain_admin, [], function(e, d){
domain.getACLs(function(e, d){ domain.getACLs(function(e, d){
if (e) return console.error(e); if (e) return console.error(e);
expect(d.length).to.be.equal(0); expect(d.length).to.be.equal(0);
...@@ -661,7 +734,7 @@ ...@@ -661,7 +734,7 @@
let owner_email = 'domain_admin@customer.dev'; let owner_email = 'domain_admin@customer.dev';
let resource_name = Date.now() + '@customer.dev'; let resource_name = Date.now() + '@customer.dev';
api.createDistributionList(resource_name, {}, function(err, dl){ api.createDistributionList(resource_name, {}, function(err, dl){
dl.addOwner(owner_email, function(e, d){ dl.addOwner(owner_email, function(e, dl){
if (e) return console.error(e); if (e) return console.error(e);
expect(err).to.be.null; expect(err).to.be.null;
dl.getACLs(function(e, d){ dl.getACLs(function(e, d){
...@@ -679,8 +752,8 @@ ...@@ -679,8 +752,8 @@
let resource_name = Date.now() + '@customer.dev'; let resource_name = Date.now() + '@customer.dev';
api.createDistributionList(resource_name, {}, function(err, dl){ api.createDistributionList(resource_name, {}, function(err, dl){
dl.addOwner(owner_email, function(e, d){ dl.addOwner(owner_email, function(e, d){
dl.removeOwner(owner_email, function(e, d){ d.removeOwner(owner_email, function(e, d){
dl.getACLs(function(e, d){ d.getACLs(function(e, d){
if (e) return console.error(e); if (e) return console.error(e);
expect(d.length).to.be.equal(0); expect(d.length).to.be.equal(0);
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