Commit 4703cbf4 authored by Patricio Bruna's avatar Patricio Bruna

change addAdmin from batch to callbacks

parent b4be3c5f
......@@ -30739,7 +30739,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = {
"name": "zimbra-admin-api-js",
"version": "0.2.7",
"version": "0.2.8",
"main": "lib/zimbra-admin-api.js",
"dependencies": {
"crypto-browserify": "^3.11.0",
......@@ -31764,17 +31764,22 @@ return /******/ (function(modules) { // webpackBootstrap
var coses = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var callback = arguments[2];
var request_data = {};
var grantee_data = { 'type': 'usr', 'identifier': account_id };
var modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' });
var grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights);
request_data.requests = [modifyAccountRequest, grantRightRequest];
request_data.batch = true;
request_data.callback = function (err, data) {
this.addDelegatedAttributeToAccount(account_id, function (err, data) {
if (err) return callback(err);
_this2.assignCosRights(grantee_data, coses, callback);
};
this.api.performRequest(request_data);
_this2.grantRight(grantee_data, _this2.domainAdminRights, function (err, data) {
if (err) return callback(err);
return _this2.assignCosRights(grantee_data, coses, callback);
});
});
}
}, {
key: 'addDelegatedAttributeToAccount',
value: function addDelegatedAttributeToAccount(account_id, callback) {
this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }, function (err, data) {
if (err) return callback(err);
return callback(null, data);
});
}
// This functions add the rights to the domain admin
......@@ -31783,8 +31788,10 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'assignCosRights',
value: function assignCosRights(grantee_data, coses, callback) {
var revoke = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];
var request_data = {};
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data);
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke);
request_data.batch = true;
request_data.callback = function (err, data) {
if (err) return callback(err);
......@@ -31795,34 +31802,25 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'buildCosesGrantsRequest',
value: function buildCosesGrantsRequest() {
var coses = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
var _this3 = this;
var coses = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
var grantee_data = arguments[1];
var revoke = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2];
var requests = [];
coses.forEach(function (c) {
var target_data = { type: 'cos', identifier: c };
var grants = _this3.buildCosGrantByAcl(target_data, grantee_data);
requests.push(grants);
});
return [].concat.apply([], requests);
}
// Return an array with all the rights
// needed 'assignCos', 'listCos', 'getCos'
}, {
key: 'buildCosGrantByAcl',
value: function buildCosGrantByAcl(target_data, grantee_data) {
var _this4 = this;
var grants = [];
['assignCos', 'listCos', 'getCos'].forEach(function (right) {
var request = _this4.api.grantRight(target_data, grantee_data, right);
grants.push(request);
var grant = null;
if (revoke) {
grant = _this3.api.revokeRight(target_data, grantee_data, 'assignCos');
} else {
grant = _this3.api.grantRight(target_data, grantee_data, 'assignCos');
}
requests.push(grant);
});
return grants;
return requests;
}
// TODO: Fix this fucking ugly code
......@@ -31842,11 +31840,11 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'getAdminsIdsFromGrants',
value: function getAdminsIdsFromGrants() {
var _this5 = this;
var _this4 = this;
var ids = [];
this.parseACL(this.attrs.zimbraACE).forEach(function (grantee) {
if (grantee.right === _this5.domainAdminRights) ids.push(grantee.id);
if (grantee.right === _this4.domainAdminRights) ids.push(grantee.id);
});
return ids;
}
......@@ -31905,11 +31903,16 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'removeAdmin',
value: function removeAdmin(account_id, callback) {
var _this5 = this;
var grantee_data = {
'type': 'usr',
'identifier': account_id
};
this.revokeRight(grantee_data, this.domainAdminRights, callback);
this.revokeRight(grantee_data, this.domainAdminRights, function (err, data) {
if (err) return callback(err);
_this5.assignCosRights(grantee_data, coses, callback, true);
});
}
}]);
return Domain;
......
{
"name": "zimbra-admin-api-js",
"version": "0.2.7",
"version": "0.2.8",
"main": "lib/zimbra-admin-api.js",
"dependencies": {
"crypto-browserify": "^3.11.0",
......
......@@ -13,24 +13,28 @@ class Domain extends Zimbra {
// TODO: Too ugly code
addAdmin(account_id, coses = [], callback) {
const request_data = {};
const grantee_data = { 'type': 'usr', 'identifier': account_id };
const modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' });
const grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights);
request_data.requests = [modifyAccountRequest, grantRightRequest];
request_data.batch = true;
request_data.callback = (err, data) => {
const grantee_data = { 'type': 'usr', 'identifier': account_id };
this.addDelegatedAttributeToAccount(account_id, (err,data) => {
if (err) return callback(err);
this.assignCosRights(grantee_data, coses, callback);
};
this.api.performRequest(request_data);
this.grantRight(grantee_data, this.domainAdminRights, (err, data) => {
if (err) return callback(err);
return this.assignCosRights(grantee_data, coses, callback);
});
});
}
addDelegatedAttributeToAccount(account_id, callback) {
this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }, (err, data) => {
if (err) return callback(err);
return callback(null, data);
});
}
// This functions add the rights to the domain admin
// to be able to change the accounts cos
assignCosRights(grantee_data, coses, callback) {
assignCosRights(grantee_data, coses, callback, revoke = false) {
const request_data = {};
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data);
request_data.requests = this.buildCosesGrantsRequest(coses, grantee_data, revoke);
request_data.batch = true;
request_data.callback = (err, data) => {
if (err) return callback(err);
......@@ -39,25 +43,19 @@ class Domain extends Zimbra {
this.api.performRequest(request_data);
}
buildCosesGrantsRequest(coses = [], grantee_data) {
buildCosesGrantsRequest(coses = [], grantee_data, revoke = false) {
const requests = [];
coses.forEach((c) => {
const target_data = { type: 'cos', identifier: c };
const grants = this.buildCosGrantByAcl(target_data, grantee_data);
requests.push(grants);
});
return [].concat.apply([], requests);
}
// Return an array with all the rights
// needed 'assignCos', 'listCos', 'getCos'
buildCosGrantByAcl(target_data, grantee_data) {
const grants = [];
['assignCos', 'listCos', 'getCos'].forEach((right) => {
const request = this.api.grantRight(target_data, grantee_data, right);
grants.push(request);
let grant = null;
if (revoke) {
grant = this.api.revokeRight(target_data, grantee_data, 'assignCos');
} else {
grant = this.api.grantRight(target_data, grantee_data, 'assignCos');
}
requests.push(grant);
});
return grants;
return requests;
}
// TODO: Fix this fucking ugly code
......@@ -130,7 +128,10 @@ class Domain extends Zimbra {
'type': 'usr',
'identifier': account_id
};
this.revokeRight(grantee_data, this.domainAdminRights, callback);
this.revokeRight(grantee_data, this.domainAdminRights, (err, data) => {
if (err) return callback(err);
this.assignCosRights(grantee_data, coses, callback, true);
});
}
}
......
......@@ -523,9 +523,9 @@
it('addAdmin should add Admin', function(done){
let api = new ZimbraAdminApi(auth_data);
let domain_admin = 'domain_admin@customer.dev';
let domain_admin = Date.now() + '@customer.dev';
let resource_name = Date.now() + '.dev';
api.getAccount(domain_admin, function(err, account){
api.createAccount(domain_admin, '12dda.222', {}, function(err, account){
api.createDomain(resource_name, {}, function(err, data){
if (err) console.error(err);
let domain = data;
......
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