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