Commit 25c76025 authored by Patricio Bruna's avatar Patricio Bruna

Domains: Add/Remove Admins - DLs: Add/Remove Owners

parent 8a64acef
......@@ -351,6 +351,15 @@ domain.countAccounts(callback);
If the `Domain` is empty, no 'Accounts', the result will be a `{}`.
### Add / Remove Admin
```javascript
domain.addAdmin('new_member@example.com', callback);
// {} if Success
domain.removeAdmin('new_member@example.com', callback);
// {} if Success
```
### Domain Admins
Return an Array of the Domain Admins `Accounts`.
......@@ -387,6 +396,16 @@ dl.removeMembers(['1@example.com', '2@example.com'], callback);
// Return Error if any of the emails isn't a member
```
### Add / Remove Owner
```javascript
dl.addOwner('new_member@example.com', callback);
// {} if Success
dl.removeOwner('new_member@example.com', callback);
// {} if Success
```
### Get Owners
Owners are the Zimbra emails addresses that are allowed to send emails to the `DL`.
If a `DL` has at least one `Owener` is a **Private DL**.
......
......@@ -11,15 +11,15 @@
## DistributionList
* [ ] Listas privadas
* [ ] Toda su gestion
* [X] Listas privadas
* [X] Toda su gestion
## Domains
* [ ] Add y remove Admins
* [X] Add y remove Admins
* [ ] Devolver Tipo de renovación
* [ ] Devolver Empresa (esto entiendo necesitamos otro API)
* [X] Devolver Tipo de renovación
* [X] Devolver Empresa (esto entiendo necesitamos otro API)
* [X] Devolver casillas segun el tipo de plan, cantidad asignadas y cantidad utilizadas para un dominio
* [X] Limite de casillas
* [X] Devolver Fecha de la proxima renovación
......
This diff is collapsed.
This diff is collapsed.
{
"name": "zimbra-admin-api-js",
"version": "0.0.14",
"version": "0.0.15",
"private": true,
"main": "lib/zimbra-admin-api.js",
"dependencies": {
......
......@@ -262,23 +262,15 @@ export default class ZimbraAdminApi {
// }
grantRight(target_data, grantee_data, right_name, callback) {
const request_data = { };
const [target, grantee] = this.dictionary.buildTargetGrantee(target_data, grantee_data);
request_data.params = this.requestParams();
request_data.request_name = 'GrantRight';
request_data.params.name = `${request_data.request_name}Request`;
request_data.response_name = `${request_data.request_name}Response`;
request_data.callback = callback;
request_data.parse_response = this.parseEmptyResponse;
if (target_data) request_data.params.params.target = {
'type': target_data.type,
'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier
};
if (grantee_data) request_data.params.params.grantee = {
'type': grantee_data.type,
'by': this.dictionary.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
request_data.params.params.grantee = grantee;
request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name };
this.performRequest(request_data);
}
......@@ -399,6 +391,7 @@ export default class ZimbraAdminApi {
// }
getGrants(target_data, grantee_data, callback) {
const request_data = { };
const [target, grantee] = this.dictionary.buildTargetGrantee(target_data, grantee_data);
const resource = 'Grant';
request_data.params = this.requestParams();
request_data.request_name = `Get${resource}s`;
......@@ -407,17 +400,8 @@ export default class ZimbraAdminApi {
request_data.callback = callback;
request_data.resource = resource;
request_data.parse_response = this.parseAllResponse;
if (target_data) request_data.params.params.target = {
'type': target_data.type,
'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier
};
if (grantee_data) request_data.params.params.grantee = {
'type': grantee_data.type,
'by': this.dictionary.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
request_data.params.params.grantee = grantee;
request_data.params.params.target = target;
this.performRequest(request_data);
}
......@@ -507,6 +491,21 @@ export default class ZimbraAdminApi {
this.performRequest(request_data);
}
revokeRight(target_data, grantee_data, right_name, callback) {
const request_data = { };
const [target, grantee] = this.dictionary.buildTargetGrantee(target_data, grantee_data);
request_data.params = this.requestParams();
request_data.request_name = 'RevokeRight';
request_data.params.name = `${request_data.request_name}Request`;
request_data.response_name = `${request_data.request_name}Response`;
request_data.callback = callback;
request_data.parse_response = this.parseEmptyResponse;
request_data.params.params.grantee = grantee;
request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name };
this.performRequest(request_data);
}
// Search the Directory
// search_object = {
// query: An LDAP query or null for everything,
......
......@@ -37,6 +37,33 @@ export default class Dictionary {
return result;
}
buildTargetGrantee(target_data, grantee_data) {
let target = null, grantee = null;
if (target_data) target = {
'type': target_data.type,
'by': this.byIdOrName(target_data.identifier),
'_content': target_data.identifier
}
if (grantee_data) grantee =
{
'type': grantee_data.type,
'by': this.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
return([target, grantee]);
}
buildGranteeData(grantee_id, type) {
return {
'type': type,
'by': this.byIdOrName(grantee_id),
'all': 1,
'_content': grantee_id,
'identifier': grantee_id
};
}
classFactory (resource, object, client) {
const class_name = this.resourceToClass(resource.toLowerCase());
return new class_name(object, client);
......
......@@ -7,6 +7,7 @@ export default class DistributionList extends Zimbra {
constructor(dl_obj, zimbra_api_client) {
super(dl_obj, zimbra_api_client);
this.members = this.parseMembers(dl_obj);
this.ownerRights = 'sendToDistList';
}
// Add members to DL
......@@ -14,6 +15,14 @@ export default 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);
}
// return the ID of the owner
getOwners(callback) {
if (this.owners) return callback(null, this.owners);
......@@ -53,4 +62,13 @@ export default 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);
}
}
......@@ -10,7 +10,10 @@ export default class Domain extends Zimbra {
}
addAdmin(account_id, callback) {
const grantee_data = this.buildGranteeData(account_id, 'Account');
const grantee_data = {
'type': 'usr',
'identifier': account_id
}
this.grantRight(grantee_data, this.domainAdminRights, callback);
}
......@@ -80,4 +83,12 @@ export default class Domain extends Zimbra {
return results;
}
removeAdmin(account_id, callback) {
const grantee_data = {
'type': 'usr',
'identifier': account_id
}
this.revokeRight(grantee_data, this.domainAdminRights, callback);
}
}
......@@ -28,13 +28,8 @@ export default class Zimbra {
return { type: type, identifier: this.id };
}
buildGranteeData(object_id, type) {
return {
'type': type,
'by': this.api.dictionary.byIdOrName(object_id),
'all': 1,
'_content': object_id
};
buildGranteeData(grantee_id, type) {
return this.api.dictionary.buildGranteeData(grantee_id, type);
}
parseACL(acls) {
......@@ -62,4 +57,8 @@ export default class Zimbra {
this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback);
}
revokeRight(grantee_data, right_name, callback){
this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
}
}
......@@ -456,7 +456,41 @@
});
});
it('addAdmin should add Admin', function(done){
let api = new ZimbraAdminApi(auth_data);
let domain_admin = 'domain_admin@customer.dev';
let resource_name = Date.now() + '.dev';
api.createDomain(resource_name, {}, function(err, data){
if (err) console.error(err);
let domain = data;
domain.addAdmin(domain_admin, function(e, d){
if (e) return console.error(e);
expect(err).to.be.null;
domain.getACLs(function(e, d){
if (e) return console.error(e);
expect(d[0].grantee.name).to.be.equal(domain_admin);
done();
});
});
});
});
it('removeAdmin should remove the Admin', function(done){
let api = new ZimbraAdminApi(auth_data);
let domain_admin = 'domain_admin@customer.dev';
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.getACLs(function(e, d){
if (e) return console.error(e);
expect(d.length).to.be.equal(0);
done();
});
});
});
});
});
});
......@@ -554,6 +588,40 @@
});
});
it('addOwner 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){
dl.addOwner(owner_email, function(e, d){
if (e) return console.error(e);
expect(err).to.be.null;
dl.getACLs(function(e, d){
if (e) return console.error(e);
expect(d[0].grantee.name).to.be.equal(owner_email);
done();
});
});
});
});
it('removeOwner 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){
dl.removeOwner(owner_email, function(e, d){
dl.getACLs(function(e, d){
if (e) return console.error(e);
expect(d.length).to.be.equal(0);
done();
});
});
});
});
});
});
describe('Grants tests', function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment