Commit a48fc7d0 authored by Patricio Bruna's avatar Patricio Bruna

Add admin to domain now requires coses

parent 372bd05e
...@@ -430,9 +430,11 @@ domain.checkMxRecord(callback); ...@@ -430,9 +430,11 @@ domain.checkMxRecord(callback);
### Add / Remove Admin ### Add / Remove Admin
To add or remove a `Domain Admin` you **must** use the `account.id`. To add or remove a `Domain Admin` you **must** use the `account.id`.
You should also specify the `coses` the `Domain Admin` can assign to the accounts of his domains.
```javascript ```javascript
domain.addAdmin(account.id, callback); const coses = ['default', 'test', 'professional'];
domain.addAdmin(account.id, coses, callback);
// {} if Success // {} if Success
domain.removeAdmin(account.id, callback); domain.removeAdmin(account.id, callback);
......
...@@ -30739,7 +30739,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -30739,7 +30739,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = { module.exports = {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.2.5", "version": "0.2.6",
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
...@@ -31758,12 +31758,17 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31758,12 +31758,17 @@ return /******/ (function(modules) { // webpackBootstrap
(0, _createClass3.default)(Domain, [{ (0, _createClass3.default)(Domain, [{
key: 'addAdmin', key: 'addAdmin',
value: function addAdmin(account_id, callback) { value: function addAdmin(account_id) {
var coses = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
var callback = arguments[2];
var request_data = {}; var request_data = {};
var grantee_data = { 'type': 'usr', 'identifier': account_id }; var grantee_data = { 'type': 'usr', 'identifier': account_id };
var modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }); var modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' });
var grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights); var grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights);
var cosesRights = this.buildCosesGrantsRequest(coses, grantee_data);
request_data.requests = [modifyAccountRequest, grantRightRequest]; request_data.requests = [modifyAccountRequest, grantRightRequest];
request_data.requests = request_data.requests.concat(cosesRights);
request_data.batch = true; request_data.batch = true;
request_data.callback = function (err, data) { request_data.callback = function (err, data) {
if (err) return callback(err); if (err) return callback(err);
...@@ -31771,6 +31776,38 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31771,6 +31776,38 @@ return /******/ (function(modules) { // webpackBootstrap
}; };
this.api.performRequest(request_data); this.api.performRequest(request_data);
} }
}, {
key: 'buildCosesGrantsRequest',
value: function buildCosesGrantsRequest() {
var _this2 = this;
var coses = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
var grantee_data = arguments[1];
var requests = [];
coses.forEach(function (c) {
var target_data = { type: 'cos', identifier: c };
var grants = _this2.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 _this3 = this;
var grants = [];
['assignCos', 'listCos', 'getCos'].forEach(function (right) {
var request = _this3.api.grantRight(target_data, grantee_data, right);
grants.push(request);
});
return grants;
}
// TODO: Fix this fucking ugly code // TODO: Fix this fucking ugly code
...@@ -31789,11 +31826,11 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -31789,11 +31826,11 @@ return /******/ (function(modules) { // webpackBootstrap
}, { }, {
key: 'getAdminsIdsFromGrants', key: 'getAdminsIdsFromGrants',
value: function getAdminsIdsFromGrants() { value: function getAdminsIdsFromGrants() {
var _this2 = this; var _this4 = this;
var ids = []; var ids = [];
this.parseACL(this.attrs.zimbraACE).forEach(function (grantee) { this.parseACL(this.attrs.zimbraACE).forEach(function (grantee) {
if (grantee.right === _this2.domainAdminRights) ids.push(grantee.id); if (grantee.right === _this4.domainAdminRights) ids.push(grantee.id);
}); });
return ids; return ids;
} }
......
{ {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.2.5", "version": "0.2.6",
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
"crypto-browserify": "^3.11.0", "crypto-browserify": "^3.11.0",
......
...@@ -12,12 +12,14 @@ class Domain extends Zimbra { ...@@ -12,12 +12,14 @@ class Domain extends Zimbra {
} }
// TODO: Too ugly code // TODO: Too ugly code
addAdmin(account_id, callback) { addAdmin(account_id, coses = [], callback) {
const request_data = {}; const request_data = {};
const grantee_data = { 'type': 'usr', 'identifier': account_id }; const grantee_data = { 'type': 'usr', 'identifier': account_id };
const modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' }); const modifyAccountRequest = this.api.modifyAccount(account_id, { zimbraIsDelegatedAdminAccount: 'TRUE' });
const grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights); const grantRightRequest = this.grantRight(grantee_data, this.domainAdminRights);
const cosesRights = this.buildCosesGrantsRequest(coses, grantee_data);
request_data.requests = [modifyAccountRequest, grantRightRequest]; request_data.requests = [modifyAccountRequest, grantRightRequest];
request_data.requests = request_data.requests.concat(cosesRights);
request_data.batch = true; request_data.batch = true;
request_data.callback = function(err, data) { request_data.callback = function(err, data) {
if (err) return callback(err); if (err) return callback(err);
...@@ -26,6 +28,27 @@ class Domain extends Zimbra { ...@@ -26,6 +28,27 @@ class Domain extends Zimbra {
this.api.performRequest(request_data); this.api.performRequest(request_data);
} }
buildCosesGrantsRequest(coses = [], grantee_data) {
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);
});
return grants;
}
// TODO: Fix this fucking ugly code // TODO: Fix this fucking ugly code
getAdmins(callback) { getAdmins(callback) {
const that = this; const that = this;
......
...@@ -528,7 +528,8 @@ ...@@ -528,7 +528,8 @@
api.createDomain(resource_name, {}, function(err, data){ api.createDomain(resource_name, {}, function(err, data){
if (err) console.error(err); if (err) console.error(err);
let domain = data; let domain = data;
domain.addAdmin(account.id, function(e, d){ const coses = ['basic', 'premium'];
domain.addAdmin(account.id, coses, function(e, d){
if (e) return console.error(e); if (e) return console.error(e);
expect(err).to.be.null; expect(err).to.be.null;
domain.getACLs(function(e, d){ domain.getACLs(function(e, d){
...@@ -546,7 +547,7 @@ ...@@ -546,7 +547,7 @@
let domain_admin = 'domain_admin@customer.dev'; let domain_admin = 'domain_admin@customer.dev';
let resource_name = Date.now() + '.dev'; let resource_name = Date.now() + '.dev';
api.createDomain(resource_name, {}, function(err, domain){ api.createDomain(resource_name, {}, function(err, domain){
domain.addAdmin(domain_admin, function(e, d){ domain.addAdmin(domain_admin, [], function(e, d){
domain.removeAdmin(domain_admin, function(e, d){ domain.removeAdmin(domain_admin, function(e, d){
domain.getACLs(function(e, d){ domain.getACLs(function(e, d){
if (e) return console.error(e); if (e) return console.error(e);
......
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