Commit b82a9d11 authored by Patricio Bruna's avatar Patricio Bruna

Get Owners for DLs

parent 1ada2a0b
...@@ -386,3 +386,13 @@ dl.removeMembers('new_member@example.com', callback); ...@@ -386,3 +386,13 @@ dl.removeMembers('new_member@example.com', callback);
dl.removeMembers(['1@example.com', '2@example.com'], callback); dl.removeMembers(['1@example.com', '2@example.com'], callback);
// Return Error if any of the emails isn't a member // Return Error if any of the emails isn't a member
``` ```
### 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**.
```javascript
dl.getOwners(callback);
// Array of Objects
// {name: 'email_address', id: 'ZimbraId', type: 'usr|grp'}
```
...@@ -359,6 +359,38 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -359,6 +359,38 @@ return /******/ (function(modules) { // webpackBootstrap
this.performRequest(request_data); this.performRequest(request_data);
} }
// Grant a right on a target to an individual or group grantee.
// target_data and grantee_data are both objects like:
// {
// type: (account|cos|dl|domain),
// identifier: (name or zimbraId)
// }
}, {
key: 'grantRight',
value: function grantRight(target_data, grantee_data, right_name, callback) {
var request_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.right = { '_content': right_name };
this.performRequest(request_data);
}
// Specific functions // Specific functions
}, { }, {
...@@ -13593,6 +13625,17 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13593,6 +13625,17 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
return attrs; return attrs;
} }
}, {
key: "parseACL",
value: function parseACL(acls) {
var elements = [].concat.apply([], [acls]);
var grantees = {};
elements.forEach(function (el) {
grantee_data = el.split(/ /);
grantees[grantee_data[0]] = { type: grantee_data[1], right: grantee_data[2] };
});
return grantees;
}
}]); }]);
return Zimbra; return Zimbra;
}(); }();
...@@ -13805,6 +13848,12 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13805,6 +13848,12 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.rightName === 'domainAdminRights') return true; if (this.rightName === 'domainAdminRights') return true;
return false; return false;
} }
}, {
key: 'isDistributionListOwnerGrant',
value: function isDistributionListOwnerGrant() {
if (this.rightName === 'sendToDistList') return true;
return false;
}
}]); }]);
return Grant; return Grant;
}(); }();
...@@ -13867,6 +13916,31 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13867,6 +13916,31 @@ 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);
} }
// return the ID of the owner
}, {
key: 'getOwners',
value: function getOwners(callback) {
if (this.owners) return callback(null, this.owners);
var owners = [];
var target_data = { type: 'dl', identifier: this.id };
var that = this;
this.api.getGrants(target_data, null, function (error, data) {
if (error) return callback(error);
if (data.length > 0) data.forEach(function (grant) {
if (grant.isDistributionListOwnerGrant()) {
owners.push({
name: grant.grantee.name,
id: grant.granteeId,
type: grant.grantee.type
});
}
});
that.owners = owners;
return callback(null, owners);
});
}
}, { }, {
key: 'parseMembers', key: 'parseMembers',
value: function parseMembers(obj) { value: function parseMembers(obj) {
This diff is collapsed.
...@@ -254,6 +254,35 @@ export default class ZimbraAdminApi { ...@@ -254,6 +254,35 @@ export default class ZimbraAdminApi {
this.performRequest(request_data); this.performRequest(request_data);
} }
// Grant a right on a target to an individual or group grantee.
// target_data and grantee_data are both objects like:
// {
// type: (account|cos|dl|domain),
// identifier: (name or zimbraId)
// }
grantRight(target_data, grantee_data, right_name, callback) {
const request_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.right = { '_content': right_name };
this.performRequest(request_data);
}
// Specific functions // Specific functions
addAccountAlias(account_id, alias, callback) { addAccountAlias(account_id, alias, callback) {
......
...@@ -14,6 +14,28 @@ export default class DistributionList extends Zimbra { ...@@ -14,6 +14,28 @@ export default class DistributionList extends Zimbra {
this.api.addDistributionListMember(this.id, members, callback); this.api.addDistributionListMember(this.id, members, callback);
} }
// return the ID of the owner
getOwners(callback) {
if (this.owners) return callback(null, this.owners);
const owners = [];
const target_data = { type: 'dl', identifier: this.id };
const that = this;
this.api.getGrants(target_data, null, function(error, data){
if (error) return callback(error);
if (data.length > 0) data.forEach((grant) => {
if (grant.isDistributionListOwnerGrant()) {
owners.push({
name: grant.grantee.name,
id: grant.granteeId,
type: grant.grantee.type
});
}
});
that.owners = owners;
return callback(null, owners);
});
}
parseMembers(obj) { parseMembers(obj) {
let members = []; let members = [];
if (obj.dlm) { if (obj.dlm) {
......
...@@ -15,4 +15,9 @@ export default class Grant { ...@@ -15,4 +15,9 @@ export default class Grant {
return false; return false;
} }
isDistributionListOwnerGrant() {
if (this.rightName === 'sendToDistList') return true;
return false;
}
} }
...@@ -23,4 +23,14 @@ export default class Zimbra { ...@@ -23,4 +23,14 @@ export default class Zimbra {
return attrs; return attrs;
} }
parseACL(acls) {
const elements = [].concat.apply([], [acls]);
const grantees = {};
elements.forEach((el) => {
grantee_data = el.split(/ /);
grantees[grantee_data[0]] = {type: grantee_data[1], right: grantee_data[2]};
});
return grantees;
}
} }
...@@ -541,6 +541,20 @@ ...@@ -541,6 +541,20 @@
}); });
}); });
it('dl.getOwners should return the DL owners', function(done) {
let api = new ZimbraAdminApi(auth_data);
api.getDistributionList('restringida@customer.dev', function(err, data){
if (err) console.log(err);
const dl = data;
dl.getOwners(function(err, data){
if (err) console.log(err);
console.log(data);
expect(data[0].type).to.be.exist;
done();
});
});
});
}); });
describe('Grants tests', function() { describe('Grants tests', function() {
...@@ -560,6 +574,7 @@ ...@@ -560,6 +574,7 @@
let target_data = {type: 'domain', identifier: 'customer.dev'}; let target_data = {type: 'domain', identifier: 'customer.dev'};
api.getGrants(target_data, null, function(err, data){ api.getGrants(target_data, null, function(err, data){
if (err) console.log(err); if (err) console.log(err);
console.log(data);
expect(data[0].constructor.name).to.equal('Grant'); expect(data[0].constructor.name).to.equal('Grant');
expect(data[0].right._content).to.equal("domainAdminRights"); expect(data[0].right._content).to.equal("domainAdminRights");
done(); done();
...@@ -575,8 +590,6 @@ ...@@ -575,8 +590,6 @@
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