Commit 8a64acef authored by Patricio Bruna's avatar Patricio Bruna

Pumped version 0.0.14

parent b82a9d11
...@@ -12467,6 +12467,13 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -12467,6 +12467,13 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
return result; return result;
} }
}, {
key: 'classNameToZimbraType',
value: function classNameToZimbraType(class_name) {
var obj = { 'Account': 'account', 'Domain': 'domain',
'Alias': 'alias', 'DistributionList': 'dl' };
return obj[class_name];
}
}, { }, {
key: 'ZimbraResources', key: 'ZimbraResources',
value: function ZimbraResources() { value: function ZimbraResources() {
...@@ -13272,10 +13279,16 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13272,10 +13279,16 @@ return /******/ (function(modules) { // webpackBootstrap
return _this; return _this;
} }
// TODO: Fix this fucking ugly code (0, _createClass3.default)(Domain, [{
key: 'addAdmin',
value: function addAdmin(account_id, callback) {
var grantee_data = this.buildGranteeData(account_id, 'Account');
this.grantRight(grantee_data, this.domainAdminRights, callback);
}
// TODO: Fix this fucking ugly code
(0, _createClass3.default)(Domain, [{ }, {
key: 'getAdmins', key: 'getAdmins',
value: function getAdmins(callback) { value: function getAdmins(callback) {
var that = this; var that = this;
...@@ -13303,10 +13316,9 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13303,10 +13316,9 @@ return /******/ (function(modules) { // webpackBootstrap
key: 'getAdminsIdsFromGrants', key: 'getAdminsIdsFromGrants',
value: function getAdminsIdsFromGrants(callback) { value: function getAdminsIdsFromGrants(callback) {
var ids = []; var ids = [];
var target_data = { type: 'domain', identifier: this.id }; this.getACLs(function (err, data) {
this.api.getGrants(target_data, null, function (error, data) { if (err) return callback(err);
if (error) return callback(error); data.forEach(function (grant) {
if (data.length > 0) data.forEach(function (grant) {
if (grant.isDomainAdminGrant()) ids.push(grant.granteeId); if (grant.isDomainAdminGrant()) ids.push(grant.granteeId);
}); });
return callback(null, ids); return callback(null, ids);
...@@ -13581,7 +13593,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13581,7 +13593,7 @@ return /******/ (function(modules) { // webpackBootstrap
/* 113 */ /* 113 */
/***/ function(module, exports, __webpack_require__) { /***/ function(module, exports, __webpack_require__) {
"use strict"; 'use strict';
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
...@@ -13611,7 +13623,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13611,7 +13623,7 @@ return /******/ (function(modules) { // webpackBootstrap
} }
(0, _createClass3.default)(Zimbra, [{ (0, _createClass3.default)(Zimbra, [{
key: "buildAttrsMap", key: 'buildAttrsMap',
value: function buildAttrsMap(obj_ary) { value: function buildAttrsMap(obj_ary) {
var attrs = {}; var attrs = {};
obj_ary.forEach(function (r) { obj_ary.forEach(function (r) {
...@@ -13626,7 +13638,23 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13626,7 +13638,23 @@ return /******/ (function(modules) { // webpackBootstrap
return attrs; return attrs;
} }
}, { }, {
key: "parseACL", key: 'buildRighTargetData',
value: function buildRighTargetData() {
var type = this.api.dictionary.classNameToZimbraType(this.constructor.name);
return { type: type, identifier: this.id };
}
}, {
key: 'buildGranteeData',
value: function buildGranteeData(object_id, type) {
return {
'type': type,
'by': this.api.dictionary.byIdOrName(object_id),
'all': 1,
'_content': object_id
};
}
}, {
key: 'parseACL',
value: function parseACL(acls) { value: function parseACL(acls) {
var elements = [].concat.apply([], [acls]); var elements = [].concat.apply([], [acls]);
var grantees = {}; var grantees = {};
...@@ -13636,6 +13664,25 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13636,6 +13664,25 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
return grantees; return grantees;
} }
// return ACLS for the Object
}, {
key: 'getACLs',
value: function getACLs(callback) {
if (this.grants) return callback(null, this.grants);
var that = this;
this.api.getGrants(this.buildRighTargetData(), null, function (err, data) {
if (err) return callback(err);
that.grants = data;
callback(null, data);
});
}
}, {
key: 'grantRight',
value: function grantRight(grantee_data, right_name, callback) {
this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback);
}
}]); }]);
return Zimbra; return Zimbra;
}(); }();
...@@ -13923,22 +13970,10 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13923,22 +13970,10 @@ return /******/ (function(modules) { // webpackBootstrap
key: 'getOwners', key: 'getOwners',
value: function getOwners(callback) { value: function getOwners(callback) {
if (this.owners) return callback(null, this.owners); if (this.owners) return callback(null, this.owners);
var owners = [];
var target_data = { type: 'dl', identifier: this.id };
var that = this; var that = this;
this.api.getGrants(target_data, null, function (error, data) { this.getACLs(function (err, data) {
if (error) return callback(error); if (err) return callback(err);
if (data.length > 0) data.forEach(function (grant) { return callback(null, that.parseOwnerACLs(data));
if (grant.isDistributionListOwnerGrant()) {
owners.push({
name: grant.grantee.name,
id: grant.granteeId,
type: grant.grantee.type
});
}
});
that.owners = owners;
return callback(null, owners);
}); });
} }
}, { }, {
...@@ -13952,6 +13987,21 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13952,6 +13987,21 @@ return /******/ (function(modules) { // webpackBootstrap
} }
return members; return members;
} }
}, {
key: 'parseOwnerACLs',
value: function parseOwnerACLs(data) {
var owners = [];
data.forEach(function (grant) {
if (grant.isDistributionListOwnerGrant()) {
owners.push({
name: grant.grantee.name,
id: grant.granteeId,
type: grant.grantee.type
});
}
});
return owners;
}
// Remove members from DL // Remove members from DL
This diff is collapsed.
{ {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.0.13", "version": "0.0.14",
"private": true, "private": true,
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
......
...@@ -66,6 +66,12 @@ export default class Dictionary { ...@@ -66,6 +66,12 @@ export default class Dictionary {
return result; return result;
} }
classNameToZimbraType(class_name) {
const obj = { 'Account': 'account', 'Domain': 'domain',
'Alias': 'alias', 'DistributionList': 'dl'};
return obj[class_name];
}
ZimbraResources() { ZimbraResources() {
return { return {
domain: { domain: {
......
...@@ -17,22 +17,10 @@ export default class DistributionList extends Zimbra { ...@@ -17,22 +17,10 @@ export default class DistributionList extends Zimbra {
// return the ID of the owner // return the ID of the owner
getOwners(callback) { getOwners(callback) {
if (this.owners) return callback(null, this.owners); if (this.owners) return callback(null, this.owners);
const owners = [];
const target_data = { type: 'dl', identifier: this.id };
const that = this; const that = this;
this.api.getGrants(target_data, null, function(error, data){ this.getACLs(function(err, data){
if (error) return callback(error); if (err) return callback(err);
if (data.length > 0) data.forEach((grant) => { return callback(null, that.parseOwnerACLs(data));
if (grant.isDistributionListOwnerGrant()) {
owners.push({
name: grant.grantee.name,
id: grant.granteeId,
type: grant.grantee.type
});
}
});
that.owners = owners;
return callback(null, owners);
}); });
} }
...@@ -46,6 +34,20 @@ export default class DistributionList extends Zimbra { ...@@ -46,6 +34,20 @@ export default class DistributionList extends Zimbra {
return members; return members;
} }
parseOwnerACLs(data) {
const owners = [];
data.forEach((grant) => {
if (grant.isDistributionListOwnerGrant()) {
owners.push({
name: grant.grantee.name,
id: grant.granteeId,
type: grant.grantee.type
});
}
});
return owners;
}
// Remove members from DL // Remove members from DL
removeMembers(members, callback) { removeMembers(members, callback) {
this.api.removeDistributionListMember(this.id, members, callback); this.api.removeDistributionListMember(this.id, members, callback);
......
...@@ -9,6 +9,11 @@ export default class Domain extends Zimbra { ...@@ -9,6 +9,11 @@ export default class Domain extends Zimbra {
this.domainAdminRights = 'domainAdminRights'; this.domainAdminRights = 'domainAdminRights';
} }
addAdmin(account_id, callback) {
const grantee_data = this.buildGranteeData(account_id, 'Account');
this.grantRight(grantee_data, this.domainAdminRights, callback);
}
// TODO: Fix this fucking ugly code // TODO: Fix this fucking ugly code
getAdmins(callback) { getAdmins(callback) {
const that = this; const that = this;
...@@ -33,10 +38,9 @@ export default class Domain extends Zimbra { ...@@ -33,10 +38,9 @@ export default class Domain extends Zimbra {
// Grant.right_name() == domainAdminRights // Grant.right_name() == domainAdminRights
getAdminsIdsFromGrants(callback) { getAdminsIdsFromGrants(callback) {
const ids = []; const ids = [];
const target_data = { type: 'domain', identifier: this.id }; this.getACLs(function(err, data){
this.api.getGrants(target_data, null, function(error, data){ if (err) return callback(err);
if (error) return callback(error); data.forEach((grant) => {
if (data.length > 0) data.forEach((grant) => {
if (grant.isDomainAdminGrant()) ids.push(grant.granteeId); if (grant.isDomainAdminGrant()) ids.push(grant.granteeId);
}); });
return callback(null, ids); return callback(null, ids);
......
...@@ -23,6 +23,20 @@ export default class Zimbra { ...@@ -23,6 +23,20 @@ export default class Zimbra {
return attrs; return attrs;
} }
buildRighTargetData() {
const type = this.api.dictionary.classNameToZimbraType(this.constructor.name);
return { type: type, identifier: this.id };
}
buildGranteeData(object_id, type) {
return {
'type': type,
'by': this.api.dictionary.byIdOrName(object_id),
'all': 1,
'_content': object_id
};
}
parseACL(acls) { parseACL(acls) {
const elements = [].concat.apply([], [acls]); const elements = [].concat.apply([], [acls]);
const grantees = {}; const grantees = {};
...@@ -33,4 +47,19 @@ export default class Zimbra { ...@@ -33,4 +47,19 @@ export default class Zimbra {
return grantees; return grantees;
} }
// return ACLS for the Object
getACLs(callback) {
if (this.grants) return callback(null, this.grants);
const that = this;
this.api.getGrants(this.buildRighTargetData(), null, function(err, data){
if (err) return callback(err);
that.grants = data;
callback(null, data);
});
}
grantRight(grantee_data, right_name, callback){
this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback);
}
} }
...@@ -548,7 +548,6 @@ ...@@ -548,7 +548,6 @@
const dl = data; const dl = data;
dl.getOwners(function(err, data){ dl.getOwners(function(err, data){
if (err) console.log(err); if (err) console.log(err);
console.log(data);
expect(data[0].type).to.be.exist; expect(data[0].type).to.be.exist;
done(); done();
}); });
...@@ -574,7 +573,6 @@ ...@@ -574,7 +573,6 @@
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();
......
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