Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zimbra-admin-api-js
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Public
zimbra-admin-api-js
Commits
631ba8a7
Commit
631ba8a7
authored
Jul 15, 2016
by
Patricio Bruna
Browse files
Options
Browse Files
Download
Plain Diff
Commit
parents
091e2577
b4421e32
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
488 additions
and
149 deletions
+488
-149
.jshintrc
.jshintrc
+3
-1
.npmignore
.npmignore
+3
-0
README.md
README.md
+22
-13
zimbra-admin-api.js
lib/zimbra-admin-api.js
+204
-66
package.json
package.json
+4
-0
index.js
src/index.js
+37
-7
account.js
src/zimbra/account.js
+15
-5
distribution_list.js
src/zimbra/distribution_list.js
+36
-11
domain.js
src/zimbra/domain.js
+75
-28
zimbra.js
src/zimbra/zimbra.js
+4
-6
test.js
test/js/spec/test.js
+85
-12
No files found.
.jshintrc
View file @
631ba8a7
{
"esnext": true
"esnext": true,
"node": true,
"predef": [ "describe", "it", "beforeEach", "afterEach" ]
}
.npmignore
View file @
631ba8a7
...
...
@@ -9,7 +9,10 @@ server.js
webpack.config.js
lib/
TODOS.md
<<<<<<< HEAD
=======
>>>>>>> manager
.*
### JetBrains template
...
...
README.md
View file @
631ba8a7
...
...
@@ -306,21 +306,16 @@ account.setPassword(password, callback);
### Enable and Disable Archive
**Only Zimbra Network Edition**
`Enable`
can take the following options:
*
**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**
.
You
**must**
pass a
`COS Name`
or
`CosID`
as firt params
```
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
...
...
@@ -389,6 +384,20 @@ zimbraApi.getAllCos(callback);
## 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 number of accounts by
`CoS`
in a domain.
...
...
@@ -437,7 +446,7 @@ const coses = ['default', 'test', 'professional'];
domain
.
addAdmin
(
account
.
id
,
coses
,
callback
);
// {} if Success
domain
.
removeAdmin
(
account
.
id
,
callback
);
domain
.
removeAdmin
(
account
.
id
,
c
oses
,
c
allback
);
// {} if Success
```
...
...
lib/zimbra-admin-api.js
View file @
631ba8a7
...
...
@@ -302,10 +302,17 @@ return /******/ (function(modules) { // webpackBootstrap
// type: (account|cos|dl|domain),
// identifier: (name or zimbraId)
// }
// Right {
// deny: 0|1,
// canDelegate: 0|1,
// disinheritSubGroups: 0|1,
// subDomain: 0|1,
// _content: <RightName>
// }
}, {
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 target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data);
var target = target_grantee[0];
...
...
@@ -313,7 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.parse_response = ResponseParser.emptyResponse;
request_data.params.params.grantee = grantee;
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);
}
...
...
@@ -366,12 +373,12 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.parse_response = ResponseParser.emptyResponse;
var account = { by: this.dictionary.byIdOrName(account_id), _content: account_id };
var archive = {
create: options.archive || 1,
name: { '_content': options.name },
cos: { by: this.dictionary.byIdOrName(options.cos_id), '_content': options.cos_id },
password: { '_content': options.password },
a: this.dictionary.attributesToArray(options.attributes)
create: options.create || 1,
cos: { by: this.dictionary.byIdOrName(options.cos), '_content': options.cos }
};
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.archive = archive;
return this.performRequest(request_data);
...
...
@@ -421,6 +428,34 @@ return /******/ (function(modules) { // webpackBootstrap
var resource_data = this.buildResourceData(name, attributes);
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',
value: function getAllDomains(callback, query_object) {
...
...
@@ -2481,6 +2516,13 @@ return /******/ (function(modules) { // webpackBootstrap
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) {
LOG.info('Retrieved auth token %s', this.token);
}
...
...
@@ -2776,6 +2818,8 @@ return /******/ (function(modules) { // webpackBootstrap
}
requestOptions.context.session = this.session ? this.session : {};
var request;
try {
...
...
@@ -30739,7 +30783,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = {
"name": "zimbra-admin-api-js",
"version": "0.2.
6
",
"version": "0.2.
15
",
"main": "lib/zimbra-admin-api.js",
"dependencies": {
"crypto-browserify": "^3.11.0",
...
...
@@ -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));
_this.domainAdminRights = 'domainAdminRights';
_this.checkAliasDomain();
return _this;
}
...
...
@@ -31759,54 +31804,96 @@ return /******/ (function(modules) { // webpackBootstrap
(0, _createClass3.default)(Domain, [{
key: 'addAdmin',
value: function addAdmin(account_id) {
var _this2 = this;
var coses = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var callback = arguments[2];
var request_data = {};
var grantee_data = { 'type': 'usr', 'identifier': account_id };
var modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' });
var grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights);
var cosesRights = this.buildCosesGrantsRequest(coses, grantee_data);
request_data.requests = [modifyAccountRequest, grantRightRequest];
request_data.requests = request_data.requests.concat(cosesRights);
request_data.batch = true;
request_data.callback = function (err, data) {
var specialRighsReqs = this.grantSpecialDomainRights(grantee_data);
var cosRights = this.assignCosRights(grantee_data, coses, null);
var rightReqs = specialRighsReqs.concat(cosRights.requests);
this.addDelegatedAttributeToAccount(account_id, function (err, data) {
if (err) return callback(err);
callback(null, data.GrantRightResponse);
};
this.api.performRequest(request_data);
_this2.api.makeBatchRequest(rightReqs, function (err, data) {
if (err) return callback(err);
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',
value: function buildCosesGrantsRequest() {
var _this2 = this;
var coses = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
var _this3 = this;
var grantee_data = arguments[1];
var revoke = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
var requests = [];
var right = { '_content': 'assignCos' };
coses.forEach(function (c) {
var target_data = { type: 'cos', identifier: c };
var grants = _this2.buildCosGrantByAcl(target_data, grantee_data);
requests.push(grants);
var grant = null;
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',
value: function buildCosGrantByAcl(target_data, grantee_data) {
var _this3 = this;
var grants = [];
['assignCos', 'listCos', 'getCos'].forEach(function (right) {
var request = _this3.api.grantRight(target_data, grantee_data, right);
grants.push(request);
});
return grants;
key: 'checkAliasDomain',
value: function checkAliasDomain() {
this.isAliasDomain = this.attrs.zimbraDomainType === 'alias' ? true : false;
var masterDomain = this.attrs.zimbraMailCatchAllForwardingAddress;
if (this.isAliasDomain && masterDomain) {
this.masterDomainName = masterDomain.split(/@/)[1];
}
return true;
}
// TODO: Fix this fucking ugly code
...
...
@@ -31815,7 +31902,7 @@ return /******/ (function(modules) { // webpackBootstrap
key: 'getAdmins',
value: function getAdmins(callback) {
var that = this;
var admins_ids = this.getAdminsIdsFromGrants();
var admins_ids = this.getAdminsIdsFromGrants(
this.attrs.zimbraACE
);
var query = this.makeAdminIdsQuery(admins_ids);
return this.api.getAllAccounts(callback, { query: query });
}
...
...
@@ -31825,12 +31912,13 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'getAdminsIdsFromGrants',
value: function getAdminsIdsFromGrants() {
value: function getAdminsIdsFromGrants(
zimbraACES
) {
var _this4 = this;
var ids = [];
this.parseACL(this.attrs.zimbraACE).forEach(function (grantee) {
if (grantee.right === _this4.domainAdminRights) ids.push(grantee.id);
var regex = new RegExp(this.domainAdminRights + '$');
this.parseACL(zimbraACES).forEach(function (grantee) {
if (regex.test(_this4.domainAdminRights)) ids.push(grantee.id);
});
return ids;
}
...
...
@@ -31888,12 +31976,17 @@ return /******/ (function(modules) { // webpackBootstrap
}
}, {
key: 'removeAdmin',
value: function removeAdmin(account_id, callback) {
value: function removeAdmin(account_id, coses, callback) {
var _this5 = this;
var grantee_data = {
'type': 'usr',
'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;
...
...
@@ -32196,15 +32289,17 @@ return /******/ (function(modules) { // webpackBootstrap
}
}, {
key: 'grantRight',
value: function grantRight(grantee_data, right_name, callback, forBatch) {
forBatch = forBatch || false;
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
value: function grantRight(grantee_data, right) {
var callback = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right, callback);
}
}, {
key: 'revokeRight',
value: function revokeRight(grantee_data, right_name, callback, forBatch) {
forBatch = forBatch || false;
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
value: function revokeRight(grantee_data, right_name) {
var callback = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
}
}]);
return Zimbra;
...
...
@@ -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));
_this.domain = _this.name.split(/@/)[1];
_this.archiveEnabled = _this.attrs.zimbraArchiveEnabled === 'TRUE';
return _this;
}
...
...
@@ -32285,14 +32381,23 @@ return /******/ (function(modules) { // webpackBootstrap
}
}
}, {
key: 'enableArchive',
value: function enableArchive(options, callback) {
return this.api.enableArchive(this.id, options, callback);
key: 'enableArchiving',
value: function enableArchiving(cos, 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',
value: function disableArchive(callback) {
return this.api.disableArchive(this.id, callback);
key: 'disableArchiving',
value: function disableArchiving(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',
...
...
@@ -32498,14 +32603,29 @@ return /******/ (function(modules) { // webpackBootstrap
value: function addMembers(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',
value: function addOwner(account_id, callback) {
var grantee_data = {
'type': 'usr',
'identifier': account_id
};
this.grantRight(grantee_data, this.ownerRights, callback);
var _this2 = this;
var zimbraACES = this.attrs.zimbraACE ? [].concat.apply([], [this.attrs.zimbraACE]) : [];
this.api.getAccount(account_id, function (err, data) {
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
...
...
@@ -32559,14 +32679,32 @@ return /******/ (function(modules) { // webpackBootstrap
value: function removeMembers(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',
value: function removeOwner(account_id, callback) {
var grantee_data = {
'type': 'usr',
'identifier': account_id
};
this.revokeRight(grantee_data, this.ownerRights, callback);
var _this3 = this;
if (!this.attrs.zimbraACE) return this;
var zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]);
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',
...
...
package.json
View file @
631ba8a7
{
"name"
:
"zimbra-admin-api-js"
,
<<<<<<<
HEAD
"version"
:
"0.2.9"
,
=======
"version"
:
"0.2.10"
,
>>>>>>>
manager
"main"
:
"src/index.js"
,
"dependencies"
:
{
"crypto-browserify"
:
"^3.11.0"
,
...
...
src/index.js
View file @
631ba8a7
...
...
@@ -216,7 +216,15 @@ class ZimbraAdminApi {
// type: (account|cos|dl|domain),
// 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
target_grantee
=
this
.
dictionary
.
buildTargetGrantee
(
target_data
,
grantee_data
);
const
target
=
target_grantee
[
0
];
...
...
@@ -224,7 +232,7 @@ class ZimbraAdminApi {
request_data
.
parse_response
=
ResponseParser
.
emptyResponse
;
request_data
.
params
.
params
.
grantee
=
grantee
;
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
);
}
...
...
@@ -266,12 +274,12 @@ class ZimbraAdminApi {
request_data
.
parse_response
=
ResponseParser
.
emptyResponse
;
const
account
=
{
by
:
this
.
dictionary
.
byIdOrName
(
account_id
),
_content
:
account_id
};
const
archive
=
{
create
:
(
options
.
archive
||
1
),
name
:
{
'_content'
:
options
.
name
},
cos
:
{
by
:
this
.
dictionary
.
byIdOrName
(
options
.
cos_id
),
'_content'
:
options
.
cos_id
},
password
:
{
'_content'
:
options
.
password
},
a
:
this
.
dictionary
.
attributesToArray
(
options
.
attributes
)
create
:
(
options
.
create
||
1
),
cos
:
{
by
:
this
.
dictionary
.
byIdOrName
(
options
.
cos
),
'_content'
:
options
.
cos
}
};
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
.
archive
=
archive
;
return
this
.
performRequest
(
request_data
);
...
...
@@ -336,6 +344,28 @@ class ZimbraAdminApi {
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
)
{
query_object
=
query_object
||
{};
query_object
.
types
=
'domains'
;
...
...
src/zimbra/account.js
View file @
631ba8a7
...
...
@@ -9,6 +9,7 @@ class Account extends Zimbra {
constructor
(
account_obj
,
zimbra_api_client
)
{
super
(
account_obj
,
zimbra_api_client
);
this
.
domain
=
this
.
name
.
split
(
/@/
)[
1
];
this
.
archiveEnabled
=
this
.
attrs
.
zimbraArchiveEnabled
===
'TRUE'
;
}
addAccountAlias
(
alias
,
callback
)
{
...
...
@@ -35,12 +36,21 @@ class Account extends Zimbra {
}
}
enableArchive
(
options
,
callback
)
{
return
this
.
api
.
enableArchive
(
this
.
id
,
options
,
callback
);
enableArchiving
(
cos
,
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
)
{
return
this
.
api
.
disableArchive
(
this
.
id
,
callback
);
disableArchiving
(
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
)
{
...
...
@@ -69,4 +79,4 @@ class Account extends Zimbra {
}
module
.
exports
=
Account
;
\ No newline at end of file
module
.
exports
=
Account
;
src/zimbra/distribution_list.js
View file @
631ba8a7
...
...
@@ -17,12 +17,23 @@ class DistributionList extends Zimbra {
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
)
{
const
grantee_data
=
{
'type'
:
'usr'
,
'identifier'
:
account_id
}
this
.
grantRight
(
grantee_data
,
this
.
ownerRights
,
callback
);
const
zimbraACES
=
this
.
attrs
.
zimbraACE
?
[].
concat
.
apply
([],
[
this
.
attrs
.
zimbraACE
])
:
[];
this
.
api
.
getAccount
(
account_id
,
(
err
,
data
)
=>
{
if
(
err
)
return
callback
(
err
);
const
account
=
data
;
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
...
...
@@ -69,12 +80,26 @@ class DistributionList extends Zimbra {
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
)
{
const
grantee_data
=
{
'type'
:
'usr'
,
'identifier'
:
account_id
}
this
.
revokeRight
(
grantee_data
,
this
.
ownerRights
,
callback
);
if
(
!
this
.
attrs
.
zimbraACE
)
return
this
;
const
zimbraACES
=
[].
concat
.
apply
([],
[
this
.
attrs
.
zimbraACE
]);
this
.
api
.
getAccount
(
account_id
,
(
err
,
account
)
=>
{
if
(
err
)
return
callback
(
err
);
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
)
{
...
...
@@ -84,4 +109,4 @@ class DistributionList extends Zimbra {
}
module
.
exports
=
DistributionList
;
\ No newline at end of file
module
.
exports
=
DistributionList
;
src/zimbra/domain.js
View file @
631ba8a7
...
...
@@ -9,60 +9,104 @@ class Domain extends Zimbra {
constructor
(
domain_obj
,
zimbra_api_client
)
{
super
(
domain_obj
,
zimbra_api_client
);
this
.
domainAdminRights
=
'domainAdminRights'
;
this
.
checkAliasDomain
();
}
// TODO: Too ugly code
<<<<<<<
HEAD
addAdmin
(
account_id
,
coses
,
callback
)
{
const
request_data
=
{};
=======
addAdmin
(
account_id
,
coses
=
[],
callback
)
{
>>>>>>>
manager
const
grantee_data
=
{
'type'
:
'usr'
,
'identifier'
:
account_id
};
const
modifyAccountRequest
=
this
.
api
.
modifyAccount
(
account_id
,
{
zimbraIsDelegatedAdminAccount
:
'TRUE'
});
const
grantRightRequest
=
this
.
grantRight
(
grantee_data
,
this
.
domainAdminRights
);
const
cosesRights
=
this
.
buildCosesGrantsRequest
(
coses
,
grantee_data
);
request_data
.
requests
=
[
modifyAccountRequest
,
grantRightRequest
];
request_data
.
requests
=
request_data
.
requests
.
concat
(
cosesRights
);
request_data
.
batch
=
true
;
request_data
.
callback
=
function
(
err
,
data
)
{
const
specialRighsReqs
=
this
.
grantSpecialDomainRights
(
grantee_data
);
const
cosRights
=
this
.
assignCosRights
(
grantee_data
,
coses
,
null
);
const
rightReqs
=
specialRighsReqs
.
concat
(
cosRights
.
requests
);
this
.
addDelegatedAttributeToAccount
(
account_id
,
(
err
,
data
)
=>
{
if
(
err
)
return
callback
(
err
);
callback
(
null
,
data
.
GrantRightResponse
);
};
this
.
api
.
performRequest
(
request_data
);
this
.
api
.
makeBatchRequest
(
rightReqs
,
(
err
,
data
)
=>
{
if
(
err
)
return
callback
(
err
);
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
)
{
=======
// 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
right
=
{
'_content'
:
'assignCos'
};
coses
.
forEach
((
c
)
=>
{
const
target_data
=
{
type
:
'cos'
,
identifier
:
c
};
const
grants
=
this
.
buildCosGrantByAcl
(
target_data
,
grantee_data
);
requests
.
push
(
grants
);
let
grant
=
null
;
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
// needed 'assignCos', 'listCos', 'getCos'
buildCosGrantByAcl
(
target_data
,
grantee_data
)
{
const
grants
=
[];
[
'assignCos'
,
'listCos'
,
'getCos'
].
forEach
((
right
)
=>
{
const
request
=
this
.
api
.
grantRight
(
target_data
,
grantee_data
,
right
);
grants
.
push
(
request
);
});
return
grants
;
checkAliasDomain
()
{
this
.
isAliasDomain
=
this
.
attrs
.
zimbraDomainType
===
'alias'
?
true
:
false
;
const
masterDomain
=
this
.
attrs
.
zimbraMailCatchAllForwardingAddress
;
if
(
this
.
isAliasDomain
&&
masterDomain
)
{
this
.
masterDomainName
=
masterDomain
.
split
(
/@/
)[
1
];
}
return
true
;
}
// TODO: Fix this fucking ugly code
getAdmins
(
callback
)
{
const
that
=
this
;
const
admins_ids
=
this
.
getAdminsIdsFromGrants
();
const
admins_ids
=
this
.
getAdminsIdsFromGrants
(
this
.
attrs
.
zimbraACE
);
const
query
=
this
.
makeAdminIdsQuery
(
admins_ids
);
return
this
.
api
.
getAllAccounts
(
callback
,
{
query
:
query
});
}
// Return the ZimbraId if the grantee have the domainAdminRights right
// Grant.right_name() == domainAdminRights
getAdminsIdsFromGrants
()
{
getAdminsIdsFromGrants
(
zimbraACES
)
{
const
ids
=
[];
this
.
parseACL
(
this
.
attrs
.
zimbraACE
).
forEach
((
grantee
)
=>
{
if
(
grantee
.
right
===
this
.
domainAdminRights
)
ids
.
push
(
grantee
.
id
);
const
regex
=
new
RegExp
(
`
${
this
.
domainAdminRights
}
$`
);
this
.
parseACL
(
zimbraACES
).
forEach
((
grantee
)
=>
{
if
(
regex
.
test
(
this
.
domainAdminRights
))
ids
.
push
(
grantee
.
id
);
});
return
ids
;
}
...
...
@@ -114,12 +158,15 @@ class Domain extends Zimbra {
return
results
;
}
removeAdmin
(
account_id
,
callback
)
{
removeAdmin
(
account_id
,
c
oses
,
c
allback
)
{
const
grantee_data
=
{
'type'
:
'usr'
,
'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
);
});
}
}
...
...
src/zimbra/zimbra.js
View file @
631ba8a7
...
...
@@ -58,14 +58,12 @@ class Zimbra {
});
}
grantRight
(
grantee_data
,
right_name
,
callback
,
forBatch
){
forBatch
=
forBatch
||
false
;
return
this
.
api
.
grantRight
(
this
.
buildRighTargetData
(),
grantee_data
,
right_name
,
callback
,
forBatch
);
grantRight
(
grantee_data
,
right
,
callback
=
null
){
return
this
.
api
.
grantRight
(
this
.
buildRighTargetData
(),
grantee_data
,
right
,
callback
);
}
revokeRight
(
grantee_data
,
right_name
,
callback
,
forBatch
){
forBatch
=
forBatch
||
false
;
return
this
.
api
.
revokeRight
(
this
.
buildRighTargetData
(),
grantee_data
,
right_name
,
callback
,
forBatch
);
revokeRight
(
grantee_data
,
right_name
,
callback
=
null
){
return
this
.
api
.
revokeRight
(
this
.
buildRighTargetData
(),
grantee_data
,
right_name
,
callback
);
}
}
...
...
test/js/spec/test.js
View file @
631ba8a7
...
...
@@ -6,6 +6,8 @@
'url'
:
'http://zimbra.zboxapp.dev:9000/service/admin/soap'
,
'user'
:
'admin@zboxapp.dev'
,
'password'
:
'12345678'
// 'user': 'superadmin2@zboxtest.com',
// 'password':'zboxapp2016'
};
describe
(
'Basic tests'
,
function
()
{
...
...
@@ -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
)
{
let
api
=
new
ZimbraAdminApi
(
auth_data
);
api
.
getAllDomains
(
function
(
err
,
data
){
...
...
@@ -172,6 +184,7 @@
const
getAllDomains
=
api
.
directorySearch
({
types
:
'domains'
});
api
.
login
(
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
[
0
].
constructor
.
name
).
to
.
equal
(
'Error'
);
expect
(
data
.
errors
[
0
].
extra
.
code
).
to
.
exist
;
...
...
@@ -184,7 +197,7 @@
});
describe
(
'Account tests'
,
function
()
{
this
.
timeout
(
5
000
);
this
.
timeout
(
10
000
);
it
(
'should create and return an account'
,
function
(
done
){
let
account_name
=
Date
.
now
()
+
'@big.com'
;
...
...
@@ -284,7 +297,7 @@
it
(
'Should Get The Account Mailbox'
,
function
(
done
){
let
api
=
new
ZimbraAdminApi
(
auth_data
);
api
.
getAccount
(
'cos_basic_1
4
@customer.dev'
,
function
(
err
,
data
){
api
.
getAccount
(
'cos_basic_1
3
@customer.dev'
,
function
(
err
,
data
){
let
account
=
data
;
account
.
getMailbox
(
function
(
err
,
data
){
if
(
err
)
return
console
.
log
(
err
);
...
...
@@ -296,7 +309,7 @@
it
(
'Should Get The Account Mailbox Size'
,
function
(
done
){
let
api
=
new
ZimbraAdminApi
(
auth_data
);
api
.
getAccount
(
'cos_basic_1
4
@customer.dev'
,
function
(
err
,
data
){
api
.
getAccount
(
'cos_basic_1
3
@customer.dev'
,
function
(
err
,
data
){
let
account
=
data
;
account
.
getMailboxSize
(
function
(
err
,
data
){
if
(
err
)
return
console
.
log
(
err
);
...
...
@@ -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
()
{
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
){
let
resource_name
=
Date
.
now
()
+
'.dev'
;
let
resource_attributes
=
{};
...
...
@@ -522,9 +588,9 @@
it
(
'addAdmin should add Admin'
,
function
(
done
){
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'
;
api
.
getAccount
(
domain_admin
,
function
(
err
,
account
){
api
.
createAccount
(
domain_admin
,
'12dda.222'
,
{},
function
(
err
,
account
){
api
.
createDomain
(
resource_name
,
{},
function
(
err
,
data
){
if
(
err
)
console
.
error
(
err
);
let
domain
=
data
;
...
...
@@ -532,10 +598,17 @@
domain
.
addAdmin
(
account
.
id
,
coses
,
function
(
e
,
d
){
if
(
e
)
return
console
.
error
(
e
);
expect
(
err
).
to
.
be
.
null
;
d
omain
.
getACLs
(
function
(
e
,
d
){
d
.
getACLs
(
function
(
e
,
acls
){
if
(
e
)
return
console
.
error
(
e
);
expect
(
d
[
0
].
grantee
.
name
).
to
.
be
.
equal
(
account
.
name
);
done
();
const
expectedGrants
=
[
"domainAdminRights"
,
"set.dl.zimbraACE"
,
"set.domain.amavisBlacklistSender"
,
"set.domain.amavisWhitelistSender"
];
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 @@
let
resource_name
=
Date
.
now
()
+
'.dev'
;
api
.
createDomain
(
resource_name
,
{},
function
(
err
,
domain
){
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
){
if
(
e
)
return
console
.
error
(
e
);
expect
(
d
.
length
).
to
.
be
.
equal
(
0
);
...
...
@@ -661,7 +734,7 @@
let
owner_email
=
'domain_admin@customer.dev'
;
let
resource_name
=
Date
.
now
()
+
'@customer.dev'
;
api
.
createDistributionList
(
resource_name
,
{},
function
(
err
,
dl
){
dl
.
addOwner
(
owner_email
,
function
(
e
,
d
){
dl
.
addOwner
(
owner_email
,
function
(
e
,
d
l
){
if
(
e
)
return
console
.
error
(
e
);
expect
(
err
).
to
.
be
.
null
;
dl
.
getACLs
(
function
(
e
,
d
){
...
...
@@ -679,8 +752,8 @@
let
resource_name
=
Date
.
now
()
+
'@customer.dev'
;
api
.
createDistributionList
(
resource_name
,
{},
function
(
err
,
dl
){
dl
.
addOwner
(
owner_email
,
function
(
e
,
d
){
d
l
.
removeOwner
(
owner_email
,
function
(
e
,
d
){
d
l
.
getACLs
(
function
(
e
,
d
){
d
.
removeOwner
(
owner_email
,
function
(
e
,
d
){
d
.
getACLs
(
function
(
e
,
d
){
if
(
e
)
return
console
.
error
(
e
);
expect
(
d
.
length
).
to
.
be
.
equal
(
0
);
done
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment