Commit 983b7758 authored by Patricio Bruna's avatar Patricio Bruna

Removing Resources

parent 2f1dea10
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
- [Common Functions](#common-functions) - [Common Functions](#common-functions)
- [Creating Resources](#creating-resources) - [Creating Resources](#creating-resources)
- [Modify Resources](#modify-resources) - [Modify Resources](#modify-resources)
- [Remove Resources](#remove-resources)
## Example ## Example
...@@ -237,3 +238,22 @@ zimbraApi.modifyAccount(zimbraId, zimbra_attributes, callback); ...@@ -237,3 +238,22 @@ zimbraApi.modifyAccount(zimbraId, zimbra_attributes, callback);
// attrs.sn = 'Hanks' // attrs.sn = 'Hanks'
// attrs.givenName = 'Tom' // attrs.givenName = 'Tom'
``` ```
## Remove Resources
For deleting resources **you have** to use the `ZimbraId`
* `removeAccount(zimbra_id, callback)`,
* `removeDomain(zimbra_id, callback)`,
* `removeDistributionList(zimbra_id, callback)`
For example:
```javascript
// user@example.com
var zimbraId = "1919c856-08cc-43c9-b927-0c4cf88f50c7";
zimbraApi.removeAccount(zimbraId, callback);
```
* If everything goes OK you receive **nothing** as result.
* You **can't delete** a `Domain` that is not empty, that has `Accounts` or `DistributionList`. You
have to empty it first.
## Todos los Resourcers ## Todos los Resourcers
* [X] Poder Modificar * [X] Poder Modificar
* [ ] Poder Elmininar * [X] Poder Elmininar
## Accounts ## Accounts
......
...@@ -125,6 +125,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -125,6 +125,7 @@ return /******/ (function(modules) { // webpackBootstrap
this._client = new jszimbra.Communication({ url: auth_object.url }); this._client = new jszimbra.Communication({ url: auth_object.url });
this.parseAllResponse = this.parseAllResponse.bind(this); this.parseAllResponse = this.parseAllResponse.bind(this);
this.parseResponse = this.parseResponse.bind(this); this.parseResponse = this.parseResponse.bind(this);
this.parseRemoveResponse = this.parseRemoveResponse.bind(this);
this.parseSearchResponse = this.parseSearchResponse.bind(this); this.parseSearchResponse = this.parseSearchResponse.bind(this);
this.dictionary = new _dictionary2.default(); this.dictionary = new _dictionary2.default();
} }
...@@ -217,6 +218,12 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -217,6 +218,12 @@ return /******/ (function(modules) { // webpackBootstrap
var result = that.dictionary.classFactory(resource, response_object); var result = that.dictionary.classFactory(resource, response_object);
return callback(null, result); return callback(null, result);
} }
}, {
key: 'parseRemoveResponse',
value: function parseRemoveResponse(data, request_data, callback) {
var response_object = data.get()[request_data.response_name];
return callback(null, response_object);
}
}, { }, {
key: 'parseSearchResponse', key: 'parseSearchResponse',
value: function parseSearchResponse(data, request_data, callback) { value: function parseSearchResponse(data, request_data, callback) {
...@@ -264,6 +271,20 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -264,6 +271,20 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.params.params = resource_data; request_data.params.params = resource_data;
this.performRequest(request_data); this.performRequest(request_data);
} }
}, {
key: 'remove',
value: function remove(resource, resource_data, callback) {
var request_data = {};
request_data.params = this.requestParams();
request_data.request_name = 'Delete' + resource;
request_data.response_name = 'Delete' + resource + 'Response';
request_data.params.name = request_data.request_name + 'Request';
request_data.resource = resource;
request_data.callback = callback;
request_data.parse_response = this.parseRemoveResponse;
request_data.params.params = resource_data;
this.performRequest(request_data);
}
}, { }, {
key: 'modify', key: 'modify',
value: function modify(resource, resource_data, callback) { value: function modify(resource, resource_data, callback) {
...@@ -350,6 +371,15 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -350,6 +371,15 @@ return /******/ (function(modules) { // webpackBootstrap
value: function getDistributionList(identifier, callback) { value: function getDistributionList(identifier, callback) {
this.get('DistributionList', identifier, callback); this.get('DistributionList', identifier, callback);
} }
}, {
key: 'createDistributionList',
value: function createDistributionList(name, attributes, callback) {
var resource_data = {
name: { '_content': name },
a: this.dictionary.attributesToArray(attributes)
};
this.create('DistributionList', resource_data, callback);
}
}, { }, {
key: 'getAllDomains', key: 'getAllDomains',
value: function getAllDomains(callback) { value: function getAllDomains(callback) {
...@@ -436,6 +466,33 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -436,6 +466,33 @@ return /******/ (function(modules) { // webpackBootstrap
this.modify('DistributionList', resource_data, callback); this.modify('DistributionList', resource_data, callback);
} }
// Remove Account
}, {
key: 'removeAccount',
value: function removeAccount(zimbra_id, callback) {
var resource_data = { id: zimbra_id };
this.remove('Account', resource_data, callback);
}
// Remove Account
}, {
key: 'removeDomain',
value: function removeDomain(zimbra_id, callback) {
var resource_data = { id: zimbra_id };
this.remove('Domain', resource_data, callback);
}
// Remove DL
}, {
key: 'removeDistributionList',
value: function removeDistributionList(zimbra_id, callback) {
var resource_data = { id: zimbra_id };
this.remove('DistributionList', resource_data, callback);
}
// Search the Directory // Search the Directory
// search_object = { // search_object = {
// query: An LDAP query or null for everything, // query: An LDAP query or null for everything,
This diff is collapsed.
...@@ -32,6 +32,7 @@ export default class ZimbraAdminApi { ...@@ -32,6 +32,7 @@ export default class ZimbraAdminApi {
this._client = new jszimbra.Communication({url: auth_object.url}); this._client = new jszimbra.Communication({url: auth_object.url});
this.parseAllResponse = this.parseAllResponse.bind(this); this.parseAllResponse = this.parseAllResponse.bind(this);
this.parseResponse = this.parseResponse.bind(this); this.parseResponse = this.parseResponse.bind(this);
this.parseRemoveResponse = this.parseRemoveResponse.bind(this);
this.parseSearchResponse = this.parseSearchResponse.bind(this); this.parseSearchResponse = this.parseSearchResponse.bind(this);
this.dictionary = new Dictionary(); this.dictionary = new Dictionary();
} }
...@@ -125,6 +126,11 @@ export default class ZimbraAdminApi { ...@@ -125,6 +126,11 @@ export default class ZimbraAdminApi {
return callback(null, result); return callback(null, result);
} }
parseRemoveResponse(data, request_data, callback){
const response_object = data.get()[request_data.response_name];
return callback(null, response_object);
}
parseSearchResponse(data, request_data, callback) { parseSearchResponse(data, request_data, callback) {
const response_types = this.dictionary.searchResponseTypes(); const response_types = this.dictionary.searchResponseTypes();
const response_object = data.get()[request_data.response_name]; const response_object = data.get()[request_data.response_name];
...@@ -169,6 +175,20 @@ export default class ZimbraAdminApi { ...@@ -169,6 +175,20 @@ export default class ZimbraAdminApi {
this.performRequest(request_data); this.performRequest(request_data);
} }
remove(resource, resource_data, callback){
let request_data = { };
request_data.params = this.requestParams();
request_data.request_name = `Delete${resource}`;
request_data.response_name = `Delete${resource}Response`;
request_data.params.name = `${request_data.request_name}Request`;
request_data.resource = resource;
request_data.callback = callback;
request_data.parse_response = this.parseRemoveResponse;
request_data.params.params = resource_data;
this.performRequest(request_data);
}
modify(resource, resource_data, callback){ modify(resource, resource_data, callback){
let request_data = { }; let request_data = { };
request_data.params = this.requestParams(); request_data.params = this.requestParams();
...@@ -245,6 +265,15 @@ export default class ZimbraAdminApi { ...@@ -245,6 +265,15 @@ export default class ZimbraAdminApi {
this.get('DistributionList', identifier, callback); this.get('DistributionList', identifier, callback);
} }
createDistributionList(name, attributes, callback) {
let resource_data = {
name: { '_content': name },
a: this.dictionary.attributesToArray(attributes)
};
this.create('DistributionList', resource_data, callback);
}
getAllDomains(callback, query_object = {}) { getAllDomains(callback, query_object = {}) {
query_object.types = 'domains'; query_object.types = 'domains';
this.directorySearch(query_object, callback); this.directorySearch(query_object, callback);
...@@ -306,6 +335,24 @@ export default class ZimbraAdminApi { ...@@ -306,6 +335,24 @@ export default class ZimbraAdminApi {
this.modify('DistributionList', resource_data, callback); this.modify('DistributionList', resource_data, callback);
} }
// Remove Account
removeAccount(zimbra_id, callback) {
let resource_data = { id: zimbra_id };
this.remove('Account', resource_data, callback);
}
// Remove Account
removeDomain(zimbra_id, callback) {
let resource_data = { id: zimbra_id };
this.remove('Domain', resource_data, callback);
}
// Remove DL
removeDistributionList(zimbra_id, callback) {
let resource_data = { id: zimbra_id };
this.remove('DistributionList', resource_data, callback);
}
// Search the Directory // Search the Directory
// search_object = { // search_object = {
// query: An LDAP query or null for everything, // query: An LDAP query or null for everything,
......
...@@ -280,7 +280,48 @@ ...@@ -280,7 +280,48 @@
}); });
}); });
it('should remove account', function(done){
let account_name = Date.now() + '@big.com';
let account_password = Date.now();
let account_attributes = {};
let api = new ZimbraAdminApi(auth_data);
api.createAccount(account_name, account_password, account_attributes, function(err, data){
if (err) return console.log(err);
api.removeAccount(data.id, function(err, data){
if (err) return console.log(err);
expect(data._jsns).to.equal("urn:zimbraAdmin");
done();
});
});
});
it('should remove Domain', function(done){
let resource_name = Date.now() + '.dev';
let resource_attributes = {};
let api = new ZimbraAdminApi(auth_data);
api.createDomain(resource_name, resource_attributes, function(err, data){
if (err) return console.log(err);
api.removeDomain(data.id, function(err, data){
if (err) return console.log(err);
expect(data._jsns).to.equal("urn:zimbraAdmin");
done();
});
});
}); });
})();
it('should remove DL', function(done){
let resource_name = Date.now() + '@zboxapp.dev';
let resource_attributes = {};
let api = new ZimbraAdminApi(auth_data);
api.createDistributionList(resource_name, resource_attributes, function(err, data){
if (err) return console.log(err);
api.removeDistributionList(data.id, function(err, data){
if (err) return console.log(err);
expect(data._jsns).to.equal("urn:zimbraAdmin");
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