Commit 1f3ee818 authored by Patricio Bruna's avatar Patricio Bruna

Change method to add DL owner

parent be38a15d
...@@ -30748,7 +30748,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -30748,7 +30748,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = { module.exports = {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.2.12", "version": "0.2.13",
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
...@@ -32547,14 +32547,29 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32547,14 +32547,29 @@ 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);
} }
// addOwner(account_id, callback) {
// const grantee_data = {
// 'type': 'usr',
// 'identifier': account_id
// }
// this.grantRight(grantee_data, this.ownerRights, callback);
// }
}, { }, {
key: 'addOwner', key: 'addOwner',
value: function addOwner(account_id, callback) { value: function addOwner(account_id, callback) {
var grantee_data = { var _this2 = this;
'type': 'usr',
'identifier': account_id var zimbraACES = this.attrs.zimbraACE || [];
}; this.api.getAccount(account_id, function (err, data) {
this.grantRight(grantee_data, this.ownerRights, callback); 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 // return the ID of the owner
...@@ -32608,14 +32623,31 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32608,14 +32623,31 @@ return /******/ (function(modules) { // webpackBootstrap
value: function removeMembers(members, callback) { value: function removeMembers(members, callback) {
this.api.removeDistributionListMember(this.id, 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', key: 'removeOwner',
value: function removeOwner(account_id, callback) { value: function removeOwner(account_id, callback) {
var grantee_data = { var _this3 = this;
'type': 'usr',
'identifier': account_id if (!this.attrs.zimbraACE) return this;
}; var zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]);
this.revokeRight(grantee_data, this.ownerRights, callback); this.api.getAccount(account_id, function (err, account) {
if (err) return callback(err);
var newACES = zimbraACES.map(function (ace) {
var granteeId = ace.split(/ /)[0];
if (account.id !== granteeId) return ace;
});
var attrs = { zimbraACE: newACES };
return _this3.api.modifyDistributionList(_this3.id, attrs, callback);
});
} }
}, { }, {
key: 'rename', key: 'rename',
......
{ {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.2.12", "version": "0.2.13",
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
......
...@@ -17,12 +17,23 @@ class DistributionList extends Zimbra { ...@@ -17,12 +17,23 @@ class DistributionList extends Zimbra {
this.api.addDistributionListMember(this.id, 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);
// }
addOwner(account_id, callback) { addOwner(account_id, callback) {
const grantee_data = { const zimbraACES = this.attrs.zimbraACE || [];
'type': 'usr', this.api.getAccount(account_id, (err, data) => {
'identifier': account_id if (err) return callback(err);
} const account = data;
this.grantRight(grantee_data, this.ownerRights, callback); 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 // return the ID of the owner
...@@ -69,12 +80,25 @@ class DistributionList extends Zimbra { ...@@ -69,12 +80,25 @@ class DistributionList extends Zimbra {
this.api.removeDistributionListMember(this.id, 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);
// }
removeOwner(account_id, callback) { removeOwner(account_id, callback) {
const grantee_data = { if (!this.attrs.zimbraACE) return this;
'type': 'usr', const zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]);
'identifier': account_id this.api.getAccount(account_id, (err, account) => {
} if (err) return callback(err);
this.revokeRight(grantee_data, this.ownerRights, callback); const newACES = zimbraACES.map((ace) =>{
const granteeId = ace.split(/ /)[0];
if (account.id !== granteeId) return ace;
});
const attrs = {zimbraACE: newACES};
return this.api.modifyDistributionList(this.id, attrs, callback);
});
} }
rename(new_name, callback) { rename(new_name, callback) {
......
...@@ -717,7 +717,7 @@ ...@@ -717,7 +717,7 @@
let owner_email = 'domain_admin@customer.dev'; let owner_email = 'domain_admin@customer.dev';
let resource_name = Date.now() + '@customer.dev'; let resource_name = Date.now() + '@customer.dev';
api.createDistributionList(resource_name, {}, function(err, dl){ api.createDistributionList(resource_name, {}, function(err, dl){
dl.addOwner(owner_email, function(e, d){ dl.addOwner(owner_email, function(e, dl){
if (e) return console.error(e); if (e) return console.error(e);
expect(err).to.be.null; expect(err).to.be.null;
dl.getACLs(function(e, d){ dl.getACLs(function(e, d){
...@@ -735,8 +735,8 @@ ...@@ -735,8 +735,8 @@
let resource_name = Date.now() + '@customer.dev'; let resource_name = Date.now() + '@customer.dev';
api.createDistributionList(resource_name, {}, function(err, dl){ api.createDistributionList(resource_name, {}, function(err, dl){
dl.addOwner(owner_email, function(e, d){ dl.addOwner(owner_email, function(e, d){
dl.removeOwner(owner_email, function(e, d){ d.removeOwner(owner_email, function(e, d){
dl.getACLs(function(e, d){ d.getACLs(function(e, d){
if (e) return console.error(e); if (e) return console.error(e);
expect(d.length).to.be.equal(0); expect(d.length).to.be.equal(0);
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