Commit 458a4bf5 authored by Patricio Bruna's avatar Patricio Bruna

Added getGrant(), Grant Class, and refactor test

parent bc6eb4cb
...@@ -131,6 +131,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -131,6 +131,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.parseRemoveResponse = this.parseRemoveResponse.bind(this); this.parseRemoveResponse = this.parseRemoveResponse.bind(this);
this.parseCountAccountResponse = this.parseCountAccountResponse.bind(this); this.parseCountAccountResponse = this.parseCountAccountResponse.bind(this);
this.parseSearchResponse = this.parseSearchResponse.bind(this); this.parseSearchResponse = this.parseSearchResponse.bind(this);
this.parseGrantsResponse = this.parseGrantsResponse.bind(this);
this.dictionary = new _dictionary2.default(); this.dictionary = new _dictionary2.default();
} }
...@@ -225,6 +226,13 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -225,6 +226,13 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
return callback(null, result); return callback(null, result);
} }
}, {
key: 'parseGrantsResponse',
value: function parseGrantsResponse(data, request_data, callback) {
var result = {};
var response_object = data.get().GetGrantsResponse;
callback(null, response_object);
}
}, { }, {
key: 'parseResponse', key: 'parseResponse',
value: function parseResponse(data, request_data, callback) { value: function parseResponse(data, request_data, callback) {
...@@ -268,7 +276,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -268,7 +276,7 @@ return /******/ (function(modules) { // webpackBootstrap
var response_name = that.dictionary.resourceResponseName(resource); var response_name = that.dictionary.resourceResponseName(resource);
var response_object = data.get()[request_data.response_name][response_name]; var response_object = data.get()[request_data.response_name][response_name];
var response_array = []; var response_array = [];
response_object.forEach(function (r) { if (response_object) response_object.forEach(function (r) {
var element = that.dictionary.classFactory(resource, r, that); var element = that.dictionary.classFactory(resource, r, that);
response_array.push(element); response_array.push(element);
}); });
...@@ -448,25 +456,36 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -448,25 +456,36 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.parse_response = this.parseAllResponse; request_data.parse_response = this.parseAllResponse;
this.performRequest(request_data); this.performRequest(request_data);
} }
// Returns all grants on the specified target entry, or all grants granted to the specified grantee entry.
// target_data and grantee_data are both objects like:
// {
// type: (account|cos|dl|domain),
// identifier: (name or zimbraId)
// }
}, { }, {
key: 'getGrants', key: 'getGrants',
value: function getGrants(target_data, grantee_data, callback) { value: function getGrants(target_data, grantee_data, callback) {
var request_data = {}; var request_data = {};
var resource = 'Grant';
request_data.params = this.requestParams(); request_data.params = this.requestParams();
request_data.request_name = 'GetGrants'; request_data.request_name = 'Get' + resource + 's';
request_data.response_name = 'GetGrantsResponse'; request_data.response_name = 'Get' + resource + 'sResponse';
request_data.params.name = request_data.request_name + 'Request'; request_data.params.name = request_data.request_name + 'Request';
request_data.callback = callback; request_data.callback = callback;
request_data.parse_response = this.parseGetGrantsResponse; request_data.resource = resource;
request_data.params.params.target = { request_data.parse_response = this.parseAllResponse;
if (target_data) request_data.params.params.target = {
'type': target_data.type, 'type': target_data.type,
'by': this.dictionary.byIdOrName(target_data.identifier), 'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier '_content': target_data.identifier
}; };
request_data.params.params.grantee = { if (grantee_data) request_data.params.params.grantee = {
'type': target_data.type, 'type': grantee_data.type,
'by': this.dictionary.byIdOrName(target_data.identifier), 'by': this.dictionary.byIdOrName(grantee_data.identifier),
'_content': target_data.identifier 'all': 1,
'_content': grantee_data.identifier
}; };
this.performRequest(request_data); this.performRequest(request_data);
} }
...@@ -12207,12 +12226,19 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -12207,12 +12226,19 @@ return /******/ (function(modules) { // webpackBootstrap
var _cos2 = _interopRequireDefault(_cos); var _cos2 = _interopRequireDefault(_cos);
var _grant = __webpack_require__(283);
var _grant2 = _interopRequireDefault(_grant);
var _distribution_list = __webpack_require__(117); var _distribution_list = __webpack_require__(117);
var _distribution_list2 = _interopRequireDefault(_distribution_list); var _distribution_list2 = _interopRequireDefault(_distribution_list);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Copyright (c) 2016 ZBox, Spa. All Rights Reserved.
// See LICENSE.txt for license information.
var Dictionary = function () { var Dictionary = function () {
function Dictionary() { function Dictionary() {
(0, _classCallCheck3.default)(this, Dictionary); (0, _classCallCheck3.default)(this, Dictionary);
...@@ -12284,6 +12310,14 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -12284,6 +12310,14 @@ return /******/ (function(modules) { // webpackBootstrap
class_name: _account2.default, class_name: _account2.default,
response_name: 'account' response_name: 'account'
}, },
alias: {
response_name: 'alias',
class_name: _alias2.default
},
cos: {
class_name: _cos2.default,
response_name: 'cos'
},
distributionlist: { distributionlist: {
class_name: _distribution_list2.default, class_name: _distribution_list2.default,
response_name: 'dl' response_name: 'dl'
...@@ -12292,21 +12326,15 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -12292,21 +12326,15 @@ return /******/ (function(modules) { // webpackBootstrap
class_name: _distribution_list2.default, class_name: _distribution_list2.default,
response_name: 'dl' response_name: 'dl'
}, },
alias: { grant: {
response_name: 'alias', class_name: _grant2.default,
class_name: _alias2.default response_name: 'grant'
},
cos: {
class_name: _cos2.default,
response_name: 'cos'
} }
}; };
} }
}]); }]);
return Dictionary; return Dictionary;
}(); // Copyright (c) 2016 ZBox, Spa. All Rights Reserved. }();
// See LICENSE.txt for license information.
exports.default = Dictionary; exports.default = Dictionary;
...@@ -13068,7 +13096,11 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13068,7 +13096,11 @@ return /******/ (function(modules) { // webpackBootstrap
function Domain(domain_obj, zimbra_api_client) { function Domain(domain_obj, zimbra_api_client) {
(0, _classCallCheck3.default)(this, Domain); (0, _classCallCheck3.default)(this, Domain);
return (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Domain).call(this, domain_obj, zimbra_api_client));
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(Domain).call(this, domain_obj, zimbra_api_client));
_this.domainAdminRights = 'domainAdminRights';
return _this;
} }
(0, _createClass3.default)(Domain, [{ (0, _createClass3.default)(Domain, [{
...@@ -40110,6 +40142,35 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -40110,6 +40142,35 @@ return /******/ (function(modules) { // webpackBootstrap
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(139).Buffer)) /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(139).Buffer))
/***/ },
/* 283 */
/***/ function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _classCallCheck2 = __webpack_require__(68);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// Copyright (c) 2016 ZBox, Spa. All Rights Reserved.
// See LICENSE.txt for license information.
var Grant = function Grant(grant) {
(0, _classCallCheck3.default)(this, Grant);
this.grantee = grant.grantee[0];
this.target = grant.target[0];
this.right = grant.right[0];
};
exports.default = Grant;
/***/ } /***/ }
/******/ ]) /******/ ])
}); });
This diff is collapsed.
...@@ -37,6 +37,7 @@ export default class ZimbraAdminApi { ...@@ -37,6 +37,7 @@ export default class ZimbraAdminApi {
this.parseRemoveResponse = this.parseRemoveResponse.bind(this); this.parseRemoveResponse = this.parseRemoveResponse.bind(this);
this.parseCountAccountResponse = this.parseCountAccountResponse.bind(this); this.parseCountAccountResponse = this.parseCountAccountResponse.bind(this);
this.parseSearchResponse = this.parseSearchResponse.bind(this); this.parseSearchResponse = this.parseSearchResponse.bind(this);
this.parseGrantsResponse = this.parseGrantsResponse.bind(this);
this.dictionary = new Dictionary(); this.dictionary = new Dictionary();
} }
...@@ -127,11 +128,17 @@ export default class ZimbraAdminApi { ...@@ -127,11 +128,17 @@ export default class ZimbraAdminApi {
result[cos.name] = { result[cos.name] = {
used: parseInt(cos._content), used: parseInt(cos._content),
id: cos.id id: cos.id
} };
}); });
return callback(null, result); return callback(null, result);
} }
parseGrantsResponse(data, request_data, callback) {
const result = {};
const response_object = data.get().GetGrantsResponse;
callback(null, response_object);
}
parseResponse(data, request_data, callback) { parseResponse(data, request_data, callback) {
const resource = request_data.resource.toLowerCase(); const resource = request_data.resource.toLowerCase();
const that = this; const that = this;
...@@ -170,7 +177,7 @@ export default class ZimbraAdminApi { ...@@ -170,7 +177,7 @@ export default class ZimbraAdminApi {
const response_name = that.dictionary.resourceResponseName(resource); const response_name = that.dictionary.resourceResponseName(resource);
const response_object = data.get()[request_data.response_name][response_name]; const response_object = data.get()[request_data.response_name][response_name];
const response_array = []; const response_array = [];
response_object.forEach((r) => { if (response_object) response_object.forEach((r) => {
let element = that.dictionary.classFactory(resource, r, that); let element = that.dictionary.classFactory(resource, r, that);
response_array.push(element); response_array.push(element);
}); });
...@@ -326,23 +333,33 @@ export default class ZimbraAdminApi { ...@@ -326,23 +333,33 @@ export default class ZimbraAdminApi {
this.performRequest(request_data); this.performRequest(request_data);
} }
// Returns all grants on the specified target entry, or all grants granted to the specified grantee entry.
// target_data and grantee_data are both objects like:
// {
// type: (account|cos|dl|domain),
// identifier: (name or zimbraId)
// }
getGrants(target_data, grantee_data, callback) { getGrants(target_data, grantee_data, callback) {
const request_data = { }; const request_data = { };
const resource = 'Grant';
request_data.params = this.requestParams(); request_data.params = this.requestParams();
request_data.request_name = 'GetGrants'; request_data.request_name = `Get${resource}s`;
request_data.response_name = 'GetGrantsResponse'; request_data.response_name = `Get${resource}sResponse`;
request_data.params.name = `${request_data.request_name}Request`; request_data.params.name = `${request_data.request_name}Request`;
request_data.callback = callback; request_data.callback = callback;
request_data.parse_response = this.parseGetGrantsResponse; request_data.resource = resource;
request_data.params.params.target = { request_data.parse_response = this.parseAllResponse;
if (target_data) request_data.params.params.target = {
'type': target_data.type, 'type': target_data.type,
'by': this.dictionary.byIdOrName(target_data.identifier), 'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier '_content': target_data.identifier
}; };
request_data.params.params.grantee = { if (grantee_data) request_data.params.params.grantee = {
'type': target_data.type, 'type': grantee_data.type,
'by': this.dictionary.byIdOrName(target_data.identifier), 'by': this.dictionary.byIdOrName(grantee_data.identifier),
'_content': target_data.identifier 'all': 1,
'_content': grantee_data.identifier
}; };
this.performRequest(request_data); this.performRequest(request_data);
} }
......
...@@ -5,6 +5,7 @@ import Domain from './../zimbra/domain.js'; ...@@ -5,6 +5,7 @@ import Domain from './../zimbra/domain.js';
import Account from './../zimbra/account.js'; import Account from './../zimbra/account.js';
import Alias from './../zimbra/alias.js'; import Alias from './../zimbra/alias.js';
import Cos from './../zimbra/cos.js'; import Cos from './../zimbra/cos.js';
import Grant from './../zimbra/grant.js';
import DistributionList from './../zimbra/distribution_list.js'; import DistributionList from './../zimbra/distribution_list.js';
export default class Dictionary { export default class Dictionary {
...@@ -64,6 +65,14 @@ export default class Dictionary { ...@@ -64,6 +65,14 @@ export default class Dictionary {
class_name: Account, class_name: Account,
response_name: 'account' response_name: 'account'
}, },
alias: {
response_name: 'alias',
class_name: Alias,
},
cos: {
class_name: Cos,
response_name: 'cos'
},
distributionlist: { distributionlist: {
class_name: DistributionList, class_name: DistributionList,
response_name: 'dl' response_name: 'dl'
...@@ -72,15 +81,10 @@ export default class Dictionary { ...@@ -72,15 +81,10 @@ export default class Dictionary {
class_name: DistributionList, class_name: DistributionList,
response_name: 'dl' response_name: 'dl'
}, },
alias: { grant: {
response_name: 'alias', class_name: Grant,
class_name: Alias, response_name: 'grant'
},
cos: {
class_name: Cos,
response_name: 'cos'
} }
}; };
} }
......
...@@ -6,6 +6,7 @@ import Zimbra from './zimbra.js'; ...@@ -6,6 +6,7 @@ import Zimbra from './zimbra.js';
export default class Domain extends Zimbra { export default class Domain extends Zimbra {
constructor(domain_obj, zimbra_api_client) { constructor(domain_obj, zimbra_api_client) {
super(domain_obj, zimbra_api_client); super(domain_obj, zimbra_api_client);
this.domainAdminRights = 'domainAdminRights';
} }
countAccounts(callback) { countAccounts(callback) {
......
// Copyright (c) 2016 ZBox, Spa. All Rights Reserved.
// See LICENSE.txt for license information.
export default class Grant {
constructor(grant) {
this.grantee = grant.grantee[0];
this.target = grant.target[0];
this.right = grant.right[0];
}
}
This diff is collapsed.
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