Commit b08c8d20 authored by Patricio Bruna's avatar Patricio Bruna

Fixed domain.addAdmin() with new rights

parent 1f3ee818
...@@ -302,10 +302,17 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -302,10 +302,17 @@ return /******/ (function(modules) { // webpackBootstrap
// type: (account|cos|dl|domain), // type: (account|cos|dl|domain),
// identifier: (name or zimbraId) // identifier: (name or zimbraId)
// } // }
// Right {
// deny: 0|1,
// canDelegate: 0|1,
// disinheritSubGroups: 0|1,
// subDomain: 0|1,
// _content: <RightName>
// }
}, { }, {
key: 'grantRight', key: 'grantRight',
value: function grantRight(target_data, grantee_data, right_name, callback) { value: function grantRight(target_data, grantee_data, right, callback) {
var request_data = this.buildRequestData('GrantRight', callback); var request_data = this.buildRequestData('GrantRight', callback);
var target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data); var target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data);
var target = target_grantee[0]; var target = target_grantee[0];
...@@ -313,7 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -313,7 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
request_data.params.params.grantee = grantee; request_data.params.params.grantee = grantee;
request_data.params.params.target = target; request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name }; request_data.params.params.right = right;
return this.performRequest(request_data); return this.performRequest(request_data);
} }
...@@ -366,7 +373,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -366,7 +373,7 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
var account = { by: this.dictionary.byIdOrName(account_id), _content: account_id }; var account = { by: this.dictionary.byIdOrName(account_id), _content: account_id };
var archive = { var archive = {
create: options.archive || 1, create: options.create || 1,
cos: { by: this.dictionary.byIdOrName(options.cos), '_content': options.cos } cos: { by: this.dictionary.byIdOrName(options.cos), '_content': options.cos }
}; };
if (options.name) archive.name = { '_content': options.name }; if (options.name) archive.name = { '_content': options.name };
...@@ -30748,7 +30755,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -30748,7 +30755,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = { module.exports = {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.2.13", "version": "0.2.14",
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
...@@ -31775,14 +31782,34 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31775,14 +31782,34 @@ return /******/ (function(modules) { // webpackBootstrap
var callback = arguments[2]; var callback = arguments[2];
var grantee_data = { 'type': 'usr', 'identifier': account_id }; var grantee_data = { 'type': 'usr', 'identifier': account_id };
var specialRighsReqs = this.grantSpecialDomainRights(grantee_data);
var cosRights = this.assignCosRights(grantee_data, coses, null);
var rightReqs = specialRighsReqs.concat(cosRights.requests);
this.addDelegatedAttributeToAccount(account_id, function (err, data) { this.addDelegatedAttributeToAccount(account_id, function (err, data) {
if (err) return callback(err); if (err) return callback(err);
_this2.grantRight(grantee_data, _this2.domainAdminRights, function (err, data) { _this2.api.makeBatchRequest(rightReqs, function (err, data) {
if (err) return callback(err); if (err) return callback(err);
return _this2.assignCosRights(grantee_data, coses, callback); return _this2.api.getDomain(_this2.id, callback);
}); });
}); });
} }
// This function grants several rights needed to manage the domain, as:
// * access to modify DLs owners,
// * access to modify domain Amavis Lists
// * access to add other domain admins
// * access to modify account cos
}, {
key: 'grantSpecialDomainRights',
value: function grantSpecialDomainRights(grantee_data) {
var requests = [];
requests.push(this.grantRight(grantee_data, { '_content': this.domainAdminRights, canDelegate: 1 }));
requests.push(this.grantRight(grantee_data, { '_content': 'set.dl.zimbraACE', canDelegate: 1 }));
requests.push(this.grantRight(grantee_data, { '_content': 'set.domain.amavisWhitelistSender', canDelegate: 1 }));
requests.push(this.grantRight(grantee_data, { '_content': 'set.domain.amavisBlacklistSender', canDelegate: 1 }));
return requests;
}
}, { }, {
key: 'addDelegatedAttributeToAccount', key: 'addDelegatedAttributeToAccount',
value: function addDelegatedAttributeToAccount(account_id, callback) { value: function addDelegatedAttributeToAccount(account_id, callback) {
...@@ -31803,11 +31830,8 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31803,11 +31830,8 @@ return /******/ (function(modules) { // webpackBootstrap
var request_data = {}; var request_data = {};
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke); request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke);
request_data.batch = true; request_data.batch = true;
request_data.callback = function (err, data) { request_data.callback = callback;
if (err) return callback(err); return this.api.performRequest(request_data);
return callback(null, data);
};
this.api.performRequest(request_data);
} }
}, { }, {
key: 'buildCosesGrantsRequest', key: 'buildCosesGrantsRequest',
...@@ -31820,13 +31844,14 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31820,13 +31844,14 @@ return /******/ (function(modules) { // webpackBootstrap
var revoke = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; var revoke = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
var requests = []; var requests = [];
var right = { '_content': 'assignCos' };
coses.forEach(function (c) { coses.forEach(function (c) {
var target_data = { type: 'cos', identifier: c }; var target_data = { type: 'cos', identifier: c };
var grant = null; var grant = null;
if (revoke) { if (revoke) {
grant = _this3.api.revokeRight(target_data, grantee_data, 'assignCos'); grant = _this3.api.revokeRight(target_data, grantee_data, 'assignCos');
} else { } else {
grant = _this3.api.grantRight(target_data, grantee_data, 'assignCos'); grant = _this3.api.grantRight(target_data, grantee_data, right);
} }
requests.push(grant); requests.push(grant);
}); });
...@@ -32235,15 +32260,17 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32235,15 +32260,17 @@ return /******/ (function(modules) { // webpackBootstrap
} }
}, { }, {
key: 'grantRight', key: 'grantRight',
value: function grantRight(grantee_data, right_name, callback, forBatch) { value: function grantRight(grantee_data, right) {
forBatch = forBatch || false; var callback = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right, callback);
} }
}, { }, {
key: 'revokeRight', key: 'revokeRight',
value: function revokeRight(grantee_data, right_name, callback, forBatch) { value: function revokeRight(grantee_data, right_name) {
forBatch = forBatch || false; var callback = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2];
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
} }
}]); }]);
return Zimbra; return Zimbra;
...@@ -32561,7 +32588,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32561,7 +32588,7 @@ return /******/ (function(modules) { // webpackBootstrap
value: function addOwner(account_id, callback) { value: function addOwner(account_id, callback) {
var _this2 = this; var _this2 = this;
var zimbraACES = this.attrs.zimbraACE || []; var zimbraACES = this.attrs.zimbraACE ? [].concat.apply([], [this.attrs.zimbraACE]) : [];
this.api.getAccount(account_id, function (err, data) { this.api.getAccount(account_id, function (err, data) {
if (err) return callback(err); if (err) return callback(err);
var account = data; var account = data;
...@@ -32641,11 +32668,12 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -32641,11 +32668,12 @@ return /******/ (function(modules) { // webpackBootstrap
var zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]); var zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]);
this.api.getAccount(account_id, function (err, account) { this.api.getAccount(account_id, function (err, account) {
if (err) return callback(err); if (err) return callback(err);
var newACES = zimbraACES.map(function (ace) { var newACES = zimbraACES.filter(function (ace) {
var granteeId = ace.split(/ /)[0]; var granteeId = ace.split(/ /)[0];
if (account.id !== granteeId) return ace; if (account.id !== granteeId) return true;
return false;
}); });
var attrs = { zimbraACE: newACES }; var attrs = newACES.length > 0 ? { zimbraACE: newACES } : { zimbraACE: '' };
return _this3.api.modifyDistributionList(_this3.id, attrs, callback); return _this3.api.modifyDistributionList(_this3.id, attrs, callback);
}); });
} }
......
{ {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.2.13", "version": "0.2.14",
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
......
...@@ -216,7 +216,15 @@ class ZimbraAdminApi { ...@@ -216,7 +216,15 @@ class ZimbraAdminApi {
// type: (account|cos|dl|domain), // type: (account|cos|dl|domain),
// identifier: (name or zimbraId) // identifier: (name or zimbraId)
// } // }
grantRight(target_data, grantee_data, right_name, callback) { // Right {
// deny: 0|1,
// canDelegate: 0|1,
// disinheritSubGroups: 0|1,
// subDomain: 0|1,
// _content: <RightName>
// }
grantRight(target_data, grantee_data, right, callback) {
const request_data = this.buildRequestData('GrantRight', callback); const request_data = this.buildRequestData('GrantRight', callback);
const target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data); const target_grantee = this.dictionary.buildTargetGrantee(target_data, grantee_data);
const target = target_grantee[0]; const target = target_grantee[0];
...@@ -224,7 +232,7 @@ class ZimbraAdminApi { ...@@ -224,7 +232,7 @@ class ZimbraAdminApi {
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
request_data.params.params.grantee = grantee; request_data.params.params.grantee = grantee;
request_data.params.params.target = target; request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name }; request_data.params.params.right = right;
return this.performRequest(request_data); return this.performRequest(request_data);
} }
...@@ -266,7 +274,7 @@ class ZimbraAdminApi { ...@@ -266,7 +274,7 @@ class ZimbraAdminApi {
request_data.parse_response = ResponseParser.emptyResponse; request_data.parse_response = ResponseParser.emptyResponse;
const account = { by: this.dictionary.byIdOrName(account_id), _content: account_id }; const account = { by: this.dictionary.byIdOrName(account_id), _content: account_id };
const archive = { const archive = {
create: (options.archive || 1), create: (options.create || 1),
cos: { by: this.dictionary.byIdOrName(options.cos), '_content': options.cos } cos: { by: this.dictionary.byIdOrName(options.cos), '_content': options.cos }
}; };
if (options.name) archive.name = { '_content': options.name }; if (options.name) archive.name = { '_content': options.name };
......
...@@ -25,7 +25,7 @@ class DistributionList extends Zimbra { ...@@ -25,7 +25,7 @@ class DistributionList extends Zimbra {
// this.grantRight(grantee_data, this.ownerRights, callback); // this.grantRight(grantee_data, this.ownerRights, callback);
// } // }
addOwner(account_id, callback) { addOwner(account_id, callback) {
const zimbraACES = this.attrs.zimbraACE || []; const zimbraACES = this.attrs.zimbraACE ? [].concat.apply([], [this.attrs.zimbraACE]) : [];
this.api.getAccount(account_id, (err, data) => { this.api.getAccount(account_id, (err, data) => {
if (err) return callback(err); if (err) return callback(err);
const account = data; const account = data;
...@@ -92,11 +92,12 @@ class DistributionList extends Zimbra { ...@@ -92,11 +92,12 @@ class DistributionList extends Zimbra {
const zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]); const zimbraACES = [].concat.apply([], [this.attrs.zimbraACE]);
this.api.getAccount(account_id, (err, account) => { this.api.getAccount(account_id, (err, account) => {
if (err) return callback(err); if (err) return callback(err);
const newACES = zimbraACES.map((ace) =>{ const newACES = zimbraACES.filter((ace) =>{
const granteeId = ace.split(/ /)[0]; const granteeId = ace.split(/ /)[0];
if (account.id !== granteeId) return ace; if (account.id !== granteeId) return true;
return false;
}); });
const attrs = {zimbraACE: newACES}; const attrs = (newACES.length > 0) ? {zimbraACE: newACES} : {zimbraACE: ''};
return this.api.modifyDistributionList(this.id, attrs, callback); return this.api.modifyDistributionList(this.id, attrs, callback);
}); });
} }
......
...@@ -15,15 +15,32 @@ class Domain extends Zimbra { ...@@ -15,15 +15,32 @@ class Domain extends Zimbra {
// TODO: Too ugly code // TODO: Too ugly code
addAdmin(account_id, coses = [], callback) { addAdmin(account_id, coses = [], callback) {
const grantee_data = { 'type': 'usr', 'identifier': account_id }; const grantee_data = { 'type': 'usr', 'identifier': account_id };
const specialRighsReqs = this.grantSpecialDomainRights(grantee_data);
const cosRights = this.assignCosRights(grantee_data, coses, null);
const rightReqs = specialRighsReqs.concat(cosRights.requests);
this.addDelegatedAttributeToAccount(account_id, (err,data) => { this.addDelegatedAttributeToAccount(account_id, (err,data) => {
if (err) return callback(err); if (err) return callback(err);
this.grantRight(grantee_data, this.domainAdminRights, (err, data) => { this.api.makeBatchRequest(rightReqs, (err, data) => {
if (err) return callback(err); if (err) return callback(err);
return this.assignCosRights(grantee_data, coses, callback); return this.api.getDomain(this.id, callback);
}); });
}); });
} }
// This function grants several rights needed to manage the domain, as:
// * access to modify DLs owners,
// * access to modify domain Amavis Lists
// * access to add other domain admins
// * access to modify account cos
grantSpecialDomainRights(grantee_data) {
const requests = [];
requests.push(this.grantRight(grantee_data, {'_content': this.domainAdminRights, canDelegate: 1}));
requests.push(this.grantRight(grantee_data, {'_content': 'set.dl.zimbraACE', canDelegate: 1}));
requests.push(this.grantRight(grantee_data, {'_content': 'set.domain.amavisWhitelistSender', canDelegate: 1}));
requests.push(this.grantRight(grantee_data, {'_content': 'set.domain.amavisBlacklistSender', canDelegate: 1}));
return requests;
}
addDelegatedAttributeToAccount(account_id, callback) { addDelegatedAttributeToAccount(account_id, callback) {
this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }, (err, data) => { this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }, (err, data) => {
if (err) return callback(err); if (err) return callback(err);
...@@ -37,22 +54,20 @@ class Domain extends Zimbra { ...@@ -37,22 +54,20 @@ class Domain extends Zimbra {
const request_data = {}; const request_data = {};
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke); request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke);
request_data.batch = true; request_data.batch = true;
request_data.callback = (err, data) => { request_data.callback = callback;
if (err) return callback(err); return this.api.performRequest(request_data);
return callback(null, data);
};
this.api.performRequest(request_data);
} }
buildCosesGrantsRequest(coses = [], grantee_data, revoke = false) { buildCosesGrantsRequest(coses = [], grantee_data, revoke = false) {
const requests = []; const requests = [];
const right = {'_content': 'assignCos'};
coses.forEach((c) => { coses.forEach((c) => {
const target_data = { type: 'cos', identifier: c }; const target_data = { type: 'cos', identifier: c };
let grant = null; let grant = null;
if (revoke) { if (revoke) {
grant = this.api.revokeRight(target_data, grantee_data, 'assignCos'); grant = this.api.revokeRight(target_data, grantee_data, 'assignCos');
} else { } else {
grant = this.api.grantRight(target_data, grantee_data, 'assignCos'); grant = this.api.grantRight(target_data, grantee_data, right);
} }
requests.push(grant); requests.push(grant);
}); });
......
...@@ -58,14 +58,12 @@ class Zimbra { ...@@ -58,14 +58,12 @@ class Zimbra {
}); });
} }
grantRight(grantee_data, right_name, callback, forBatch){ grantRight(grantee_data, right, callback = null){
forBatch = forBatch || false; return this.api.grantRight(this.buildRighTargetData(), grantee_data, right, callback);
return this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
} }
revokeRight(grantee_data, right_name, callback, forBatch){ revokeRight(grantee_data, right_name, callback = null){
forBatch = forBatch || false; return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
return this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback, forBatch);
} }
} }
......
...@@ -287,7 +287,7 @@ ...@@ -287,7 +287,7 @@
it('Should Get The Account Mailbox', function(done){ it('Should Get The Account Mailbox', function(done){
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
api.getAccount('cos_basic_14@customer.dev', function(err, data){ api.getAccount('cos_basic_13@customer.dev', function(err, data){
let account = data; let account = data;
account.getMailbox(function(err, data){ account.getMailbox(function(err, data){
if (err) return console.log(err); if (err) return console.log(err);
...@@ -299,7 +299,7 @@ ...@@ -299,7 +299,7 @@
it('Should Get The Account Mailbox Size', function(done){ it('Should Get The Account Mailbox Size', function(done){
let api = new ZimbraAdminApi(auth_data); let api = new ZimbraAdminApi(auth_data);
api.getAccount('cos_basic_14@customer.dev', function(err, data){ api.getAccount('cos_basic_13@customer.dev', function(err, data){
let account = data; let account = data;
account.getMailboxSize(function(err, data){ account.getMailboxSize(function(err, data){
if (err) return console.log(err); if (err) return console.log(err);
...@@ -590,7 +590,10 @@ ...@@ -590,7 +590,10 @@
expect(err).to.be.null; expect(err).to.be.null;
domain.getACLs(function(e, d){ domain.getACLs(function(e, d){
if (e) return console.error(e); if (e) return console.error(e);
expect(d[0].grantee.name).to.be.equal(account.name); const expectedGrants = ["domainAdminRights", "set.dl.zimbraACE", "set.domain.amavisBlacklistSender", "set.domain.amavisWhitelistSender"];
const actualGrants = d.map(function(d){return d.rightName}).sort()
expect(expectedGrants[0]).to.be.equal(actualGrants[0]);
expect(expectedGrants[2]).to.be.equal(actualGrants[2]);
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