Commit 080be678 authored by Patricio Bruna's avatar Patricio Bruna

Added DLs Owner methods to main api

parent 391f3ada
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
First, instantiate the wrapper. First, instantiate the wrapper.
```javascript ```javascript
var zimbraApi = new ZimbraAdminApi({ var client = new ZimbraAdminApi({
'url': 'http://zimbra.zboxapp.dev:8000/service/admin/soap', 'url': 'http://zimbra.zboxapp.dev:8000/service/admin/soap',
'user': 'admin@zboxapp.dev', 'user': 'admin@zboxapp.dev',
'password':'12345678' 'password':'12345678'
...@@ -32,7 +32,7 @@ var callback = function(err, data) { ...@@ -32,7 +32,7 @@ var callback = function(err, data) {
console.log(data); console.log(data);
}; };
zimbraApi.getAllDomains(callback); client.getAllDomains(callback);
ZimbraAdminApi.version(); ZimbraAdminApi.version();
// "version" // "version"
...@@ -61,7 +61,7 @@ If Zimbra returns an Error, the library returns an `Error` Object with the Zimbr ...@@ -61,7 +61,7 @@ If Zimbra returns an Error, the library returns an `Error` Object with the Zimbr
information. For example, if you look for a non existing `Domain`: information. For example, if you look for a non existing `Domain`:
```javascript ```javascript
api.getDomain('example.com', callback); client.getDomain('example.com', callback);
// Error: {status: 500, title: "Internal Server Error", extra: Object} // Error: {status: 500, title: "Internal Server Error", extra: Object}
// Error.extra: { // Error.extra: {
...@@ -88,17 +88,17 @@ for brevity: ...@@ -88,17 +88,17 @@ for brevity:
You can use the resource `name` or `zimbraId`: You can use the resource `name` or `zimbraId`:
```javascript ```javascript
zimbraApi.getAccount('account@domain.com', callback); client.getAccount('account@domain.com', callback);
// Account {name: "admin@domain.com", id: "eda93f93-ba26-4344-8ae0-1d03964b612a", attrs: Object} // Account {name: "admin@domain.com", id: "eda93f93-ba26-4344-8ae0-1d03964b612a", attrs: Object}
zimbraApi.getAccount('eda93f93-ba26-4344-8ae0-1d03964b612a', callback); client.getAccount('eda93f93-ba26-4344-8ae0-1d03964b612a', callback);
// Account {name: "admin@domain.com", id: "eda93f93-ba26-4344-8ae0-1d03964b612a", attrs: Object} // Account {name: "admin@domain.com", id: "eda93f93-ba26-4344-8ae0-1d03964b612a", attrs: Object}
zimbraApi.getDomain('domain.com', callback); client.getDomain('domain.com', callback);
// Domain {name: "domain.com", id: "cc0fd82b-7833-4de2-8954-88eb97fb81e9", attrs: Object} // Domain {name: "domain.com", id: "cc0fd82b-7833-4de2-8954-88eb97fb81e9", attrs: Object}
zimbraApi.getDistributionList('list@domain.com', callback); client.getDistributionList('list@domain.com', callback);
// DistributionList {name: "list@domain.com", id: "747972ab-a410-4f17-8d5e-db7be21d75e9", attrs: Object, members: Array[4]} // DistributionList {name: "list@domain.com", id: "747972ab-a410-4f17-8d5e-db7be21d75e9", attrs: Object, members: Array[4]}
``` ```
...@@ -131,7 +131,7 @@ If you need to get the result as an Object with the resource `id` or `name` as t ...@@ -131,7 +131,7 @@ If you need to get the result as an Object with the resource `id` or `name` as t
of the object you need to initialize the Api like this: of the object you need to initialize the Api like this:
```javascript ```javascript
var zimbraApi = new ZimbraAdminApi({ var client = new ZimbraAdminApi({
'url': 'http://zimbra.zboxapp.dev:8000/service/admin/soap', 'url': 'http://zimbra.zboxapp.dev:8000/service/admin/soap',
'user': 'admin@zboxapp.dev', 'user': 'admin@zboxapp.dev',
'password':'12345678', 'password':'12345678',
...@@ -144,7 +144,7 @@ var callback = function(err, data) { ...@@ -144,7 +144,7 @@ var callback = function(err, data) {
console.log(data); console.log(data);
}; };
zimbraApi.getAllDomains(callback); client.getAllDomains(callback);
// Object {total: 261, more: false, domain: Object} <== Object!! // Object {total: 261, more: false, domain: Object} <== Object!!
``` ```
...@@ -153,7 +153,7 @@ zimbraApi.getAllDomains(callback); ...@@ -153,7 +153,7 @@ zimbraApi.getAllDomains(callback);
##### 1. Get All Accounts without a query_object ##### 1. Get All Accounts without a query_object
```javascript ```javascript
zimbraApi.getAllAccounts(callback); client.getAllAccounts(callback);
// Object {total: 261, more: false, account: Array[261]} // Object {total: 261, more: false, account: Array[261]}
``` ```
...@@ -168,7 +168,7 @@ This is useful if you are doing pagination. ...@@ -168,7 +168,7 @@ This is useful if you are doing pagination.
```javascript ```javascript
var query_object = { limit: 10, offset: 2 } var query_object = { limit: 10, offset: 2 }
zimbraApi.getAllAccounts(callback); client.getAllAccounts(callback);
// Object {total: 261, more: true, account: Array[10]} // Object {total: 261, more: true, account: Array[10]}
``` ```
...@@ -176,7 +176,7 @@ zimbraApi.getAllAccounts(callback); ...@@ -176,7 +176,7 @@ zimbraApi.getAllAccounts(callback);
```javascript ```javascript
var query_object = { domain: 'example.com' } var query_object = { domain: 'example.com' }
zimbraApi.getAllDistributionLists(query_object, callback); client.getAllDistributionLists(query_object, callback);
// Object {total: 6, more: false, dl: Array[6]} // Object {total: 6, more: false, dl: Array[6]}
``` ```
...@@ -184,7 +184,7 @@ zimbraApi.getAllDistributionLists(query_object, callback); ...@@ -184,7 +184,7 @@ zimbraApi.getAllDistributionLists(query_object, callback);
```javascript ```javascript
var query_object = { query: 'mail=*basic*' } var query_object = { query: 'mail=*basic*' }
zimbraApi.getAllAccounts(query_object, callback); client.getAllAccounts(query_object, callback);
// Object {total: 29, more: false, account: Array[29]} // Object {total: 29, more: false, account: Array[29]}
``` ```
...@@ -195,13 +195,13 @@ the result in just one answer. ...@@ -195,13 +195,13 @@ the result in just one answer.
Every function here works for `BatchRequest` if you do not pass a `callback`. For example: Every function here works for `BatchRequest` if you do not pass a `callback`. For example:
```javascript ```javascript
var allAccounts = zimbraApi.getAllAccounts(); var allAccounts = client.getAllAccounts();
var allDomains = zimbraApi.getAllDomains(); var allDomains = client.getAllDomains();
zimbraApi.makeBatchRequest([allAccounts, allDomains], callback); client.makeBatchRequest([allAccounts, allDomains], callback);
// Object {SearchDirectoryResponse: Array[2], _jsns: "urn:zimbra"} // Object {SearchDirectoryResponse: Array[2], _jsns: "urn:zimbra"}
// SearchDirectoryResponse[0].account, SearchDirectoryResponse[1].domain // SearchDirectoryResponse[0].account, SearchDirectoryResponse[1].domain
zimbraApi.makeBatchRequest([allAccounts, allDomains], callback, {onError: 'continue'}); client.makeBatchRequest([allAccounts, allDomains], callback, {onError: 'continue'});
// By default is {onError: 'stop'} // By default is {onError: 'stop'}
``` ```
...@@ -212,7 +212,7 @@ objects. The response arrays has the same order of the request array: ...@@ -212,7 +212,7 @@ objects. The response arrays has the same order of the request array:
```javascript ```javascript
var domains = ['zboxapp.com', 'example.com', 'zboxnow.com']; var domains = ['zboxapp.com', 'example.com', 'zboxnow.com'];
zimbraApi.batchCountAccounts(domains, callback); client.batchCountAccounts(domains, callback);
// [Object, Object]; // [Object, Object];
``` ```
...@@ -231,7 +231,7 @@ Always have to pass an `email_address` and a `password`: ...@@ -231,7 +231,7 @@ Always have to pass an `email_address` and a `password`:
```javascript ```javascript
var zimbra_attributes = {}; var zimbra_attributes = {};
zimbraApi.createAccount('user1@example.com', 'SuP3rS3cur3P4ss', zimbra_attributes, callback); client.createAccount('user1@example.com', 'SuP3rS3cur3P4ss', zimbra_attributes, callback);
// Account {name: "user1@example.com", id: "1919c856-08cc-43c9-b927-0c4cf88f50c7", attrs: Object} // Account {name: "user1@example.com", id: "1919c856-08cc-43c9-b927-0c4cf88f50c7", attrs: Object}
``` ```
...@@ -243,7 +243,7 @@ Check the *space* between `user` and `1@example.com` ...@@ -243,7 +243,7 @@ Check the *space* between `user` and `1@example.com`
```javascript ```javascript
var zimbra_attributes = {}; var zimbra_attributes = {};
zimbraApi.createAccount('user 1@example.com', 'SuP3rS3cur3P4ss', zimbra_attributes, callback); client.createAccount('user 1@example.com', 'SuP3rS3cur3P4ss', zimbra_attributes, callback);
// Error {status: 500, title: "Internal Server Error", extra: Object} // Error {status: 500, title: "Internal Server Error", extra: Object}
// Error.extra { // Error.extra {
// code: "service.INVALID_REQUEST", // code: "service.INVALID_REQUEST",
...@@ -269,7 +269,7 @@ var zimbra_attributes = { ...@@ -269,7 +269,7 @@ var zimbra_attributes = {
sn: 'Smith', sn: 'Smith',
zimbraMailQuota: 53687091200 zimbraMailQuota: 53687091200
} }
zimbraApi.createAccount('user@example.com', 'SuP3rS3cur3P4ss', zimbra_attributes, callback); client.createAccount('user@example.com', 'SuP3rS3cur3P4ss', zimbra_attributes, callback);
// Account {name: "user@example.com", id: "1919c856-08cc-43c9-b927-0c4cf88f50c7", attrs: Object} // Account {name: "user@example.com", id: "1919c856-08cc-43c9-b927-0c4cf88f50c7", attrs: Object}
``` ```
...@@ -292,7 +292,7 @@ var zimbra_attributes = { ...@@ -292,7 +292,7 @@ var zimbra_attributes = {
// user@example.com // user@example.com
var zimbraId = "1919c856-08cc-43c9-b927-0c4cf88f50c7"; var zimbraId = "1919c856-08cc-43c9-b927-0c4cf88f50c7";
zimbraApi.modifyAccount(zimbraId, zimbra_attributes, callback); client.modifyAccount(zimbraId, zimbra_attributes, callback);
// Account {name: "user@example.com", id: "1919c856-08cc-43c9-b927-0c4cf88f50c7", attrs: Object} // Account {name: "user@example.com", id: "1919c856-08cc-43c9-b927-0c4cf88f50c7", attrs: Object}
// attrs.sn = 'Hanks' // attrs.sn = 'Hanks'
// attrs.givenName = 'Tom' // attrs.givenName = 'Tom'
...@@ -310,7 +310,7 @@ For example: ...@@ -310,7 +310,7 @@ For example:
```javascript ```javascript
// user@example.com // user@example.com
var zimbraId = "1919c856-08cc-43c9-b927-0c4cf88f50c7"; var zimbraId = "1919c856-08cc-43c9-b927-0c4cf88f50c7";
zimbraApi.removeAccount(zimbraId, callback); client.removeAccount(zimbraId, callback);
``` ```
* If everything goes OK you receive **nothing** as result. * If everything goes OK you receive **nothing** as result.
...@@ -345,7 +345,7 @@ account.disableArchiving(callback); ...@@ -345,7 +345,7 @@ account.disableArchiving(callback);
Get distribution lists an account is a member of. Get distribution lists an account is a member of.
```javascript ```javascript
api.getAccountMembership(account, callback); client.getAccountMembership(account, callback);
// [DistributionList, DistributionList, ...] // [DistributionList, DistributionList, ...]
// Or as a method of the account // Or as a method of the account
...@@ -398,7 +398,7 @@ account.viewMailPath(3600, callback); ...@@ -398,7 +398,7 @@ account.viewMailPath(3600, callback);
The account only has the Id of the Cos, `zimbraCOSId`, but not the name. To get the name you call `zimbraCosName` on the Account: The account only has the Id of the Cos, `zimbraCOSId`, but not the name. To get the name you call `zimbraCosName` on the Account:
```javascript ```javascript
// account is a Account, you got it from zimbraApi.getAccount.... // account is a Account, you got it from client.getAccount....
account.cosName(callback); account.cosName(callback);
// professional // professional
...@@ -413,7 +413,7 @@ This are functions especifics to `Cos`. ...@@ -413,7 +413,7 @@ This are functions especifics to `Cos`.
### Get All Cos ### Get All Cos
```javascript ```javascript
zimbraApi.getAllCos(callback); client.getAllCos(callback);
``` ```
## Domains ## Domains
...@@ -437,7 +437,7 @@ domain.masterDomainName ...@@ -437,7 +437,7 @@ domain.masterDomainName
Count number of accounts by `CoS` in a domain. Count number of accounts by `CoS` in a domain.
```javascript ```javascript
zimbraApi.countAccounts('example.com', callback); client.countAccounts('example.com', callback);
// Object { premium: Object, professional: Object} // Object { premium: Object, professional: Object}
// premium: { // premium: {
...@@ -450,7 +450,7 @@ zimbraApi.countAccounts('example.com', callback); ...@@ -450,7 +450,7 @@ zimbraApi.countAccounts('example.com', callback);
If you have a `Domain` you can call `countAccounts(callback)` on it and it will returns the **Limit of Accounts** for the `Domain`: If you have a `Domain` you can call `countAccounts(callback)` on it and it will returns the **Limit of Accounts** for the `Domain`:
```javascript ```javascript
// domain is a Domain, you got it from zimbraApi.getDomain.... // domain is a Domain, you got it from client.getDomain....
domain.countAccounts(callback); domain.countAccounts(callback);
// Object { premium: Object, professional: Object} // Object { premium: Object, professional: Object}
// premium: { // premium: {
...@@ -489,7 +489,7 @@ domain.removeAdmin(account.id, coses, callback); ...@@ -489,7 +489,7 @@ domain.removeAdmin(account.id, coses, callback);
Return an Array of the Domain Admins `Accounts`. Return an Array of the Domain Admins `Accounts`.
```javascript ```javascript
// domain is a Domain, you got it from zimbraApi.getDomain.... // domain is a Domain, you got it from client.getDomain....
domain.getAdmins(callback); domain.getAdmins(callback);
// [Account, Account] // [Account, Account]
``` ```
...@@ -498,7 +498,7 @@ domain.getAdmins(callback); ...@@ -498,7 +498,7 @@ domain.getAdmins(callback);
Return an Array of the Domain `DistributionList`s. Return an Array of the Domain `DistributionList`s.
```javascript ```javascript
// domain is a Domain, you got it from zimbraApi.getDomain.... // domain is a Domain, you got it from client.getDomain....
domain.getAllDistributionLists(callback); domain.getAllDistributionLists(callback);
// [DistributionList, DistributionList] // [DistributionList, DistributionList]
``` ```
...@@ -530,9 +530,13 @@ dl.removeMembers(['1@example.com', '2@example.com'], callback); ...@@ -530,9 +530,13 @@ dl.removeMembers(['1@example.com', '2@example.com'], callback);
### Add / Remove Owner ### Add / Remove Owner
```javascript ```javascript
client.addDistributionListOwner(dl.name, 'new_member@example.com', callback);
// OR
dl.addOwner('new_member@example.com', callback); dl.addOwner('new_member@example.com', callback);
// {} if Success // {} if Success
client.removeDistributionListOwner(dl.name, 'new_member@example.com', callback);
// OR
dl.removeOwner('new_member@example.com', callback); dl.removeOwner('new_member@example.com', callback);
// {} if Success // {} if Success
``` ```
...@@ -542,6 +546,8 @@ Owners are the Zimbra emails addresses that are allowed to send emails to the `D ...@@ -542,6 +546,8 @@ Owners are the Zimbra emails addresses that are allowed to send emails to the `D
If a `DL` has at least one `Owener` is a **Private DL**. If a `DL` has at least one `Owener` is a **Private DL**.
```javascript ```javascript
client.getDistributionListOwners(dl.name, callback);
// OR
dl.getOwners(callback); dl.getOwners(callback);
// Array of Objects // Array of Objects
// {name: 'email_address', id: 'ZimbraId', type: 'usr|grp'} // {name: 'email_address', id: 'ZimbraId', type: 'usr|grp'}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -256,6 +256,13 @@ class ZimbraAdminApi { ...@@ -256,6 +256,13 @@ class ZimbraAdminApi {
return this.performRequest(request_data); return this.performRequest(request_data);
} }
addDistributionListOwner(distributionList, ownerId, callback) {
this.getDistributionList(distributionList, (err, dl) => {
if (err) return callback(err);
return dl.addOwner(ownerId, callback);
});
}
// Return a token for access an account // Return a token for access an account
// {authToken: _TOKEN_, lifetime: _miliseconds_ } // {authToken: _TOKEN_, lifetime: _miliseconds_ }
delegateAuth(account_id, lifetime_seconds, callback) { delegateAuth(account_id, lifetime_seconds, callback) {
...@@ -321,6 +328,13 @@ class ZimbraAdminApi { ...@@ -321,6 +328,13 @@ class ZimbraAdminApi {
return this.get('Account', identifier, callback); return this.get('Account', identifier, callback);
} }
getDistributionListOwners(distributionList, callback) {
this.getDistributionList(distributionList, (err, dl) => {
if (err) return callback(err);
return dl.getOwners(callback);
});
}
// attributes debe ser un arreglo de objetos: // attributes debe ser un arreglo de objetos:
// let resource_attributes = { // let resource_attributes = {
// zimbraSkinLogoURL: 'http://www.zboxapp.com', // zimbraSkinLogoURL: 'http://www.zboxapp.com',
...@@ -525,6 +539,13 @@ class ZimbraAdminApi { ...@@ -525,6 +539,13 @@ class ZimbraAdminApi {
return this.performRequest(request_data); return this.performRequest(request_data);
} }
removeDistributionListOwner(distributionList, ownerId, callback) {
this.getDistributionList(distributionList, (err, dl) => {
if (err) return callback(err);
return dl.removeOwner(ownerId, callback);
});
}
renameAccount(zimbra_id, new_name, callback) { renameAccount(zimbra_id, new_name, callback) {
const resource_data = { id: zimbra_id, newName: new_name }; const resource_data = { id: zimbra_id, newName: new_name };
return this.rename('Account', resource_data, callback); return this.rename('Account', resource_data, callback);
......
...@@ -14,6 +14,51 @@ ...@@ -14,6 +14,51 @@
this.timeout(10000); this.timeout(10000);
it('getDistributionListOwners should return the DL owners', function(done) {
let api = new ZimbraAdminApi(auth_data);
api.getDistributionListOwners('restringida@customer.dev', function(err, data){
if (err) console.log(err);
expect(data[0].type).to.be.exist;
done();
});
});
it('addDistributionListOwner to DL should add Owner', function(done){
let api = new ZimbraAdminApi(auth_data);
let owner_email = 'domain_admin@customer.dev';
let resource_name = Date.now() + '@customer.dev';
api.createDistributionList(resource_name, {}, function(err, dl){
if (err) return console.error(err);
api.addDistributionListOwner(dl.name, owner_email, function(e, dl){
if (e) return console.error(e);
expect(e).to.be.null;
api.getDistributionListOwners(resource_name, function(err, data){
if (err) return console.error(err);
expect(data[0].name).to.be.equal(owner_email);
done();
})
});
});
});
it('removeDistributionListOwner should remove the Owner', function(done){
let api = new ZimbraAdminApi(auth_data);
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){
api.removeDistributionListOwner(dl.name, owner_email, function(err, data){
if (err) return console.error(err);
api.getDistributionListOwners(resource_name, function(err, data){
if (err) return console.error(err);
expect(data).to.be.empty;
done();
});
})
});
});
});
it('should return the Delegated Token', function(done){ it('should return the Delegated Token', function(done){
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
api.delegateAuth('admin', 3672, function(err, data) { api.delegateAuth('admin', 3672, function(err, data) {
......
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