Commit 25c76025 authored by Patricio Bruna's avatar Patricio Bruna

Domains: Add/Remove Admins - DLs: Add/Remove Owners

parent 8a64acef
...@@ -351,6 +351,15 @@ domain.countAccounts(callback); ...@@ -351,6 +351,15 @@ domain.countAccounts(callback);
If the `Domain` is empty, no 'Accounts', the result will be a `{}`. If the `Domain` is empty, no 'Accounts', the result will be a `{}`.
### Add / Remove Admin
```javascript
domain.addAdmin('new_member@example.com', callback);
// {} if Success
domain.removeAdmin('new_member@example.com', callback);
// {} if Success
```
### Domain Admins ### Domain Admins
Return an Array of the Domain Admins `Accounts`. Return an Array of the Domain Admins `Accounts`.
...@@ -387,6 +396,16 @@ dl.removeMembers(['1@example.com', '2@example.com'], callback); ...@@ -387,6 +396,16 @@ dl.removeMembers(['1@example.com', '2@example.com'], callback);
// Return Error if any of the emails isn't a member // Return Error if any of the emails isn't a member
``` ```
### Add / Remove Owner
```javascript
dl.addOwner('new_member@example.com', callback);
// {} if Success
dl.removeOwner('new_member@example.com', callback);
// {} if Success
```
### Get Owners ### Get Owners
Owners are the Zimbra emails addresses that are allowed to send emails to the `DL`. Owners are the Zimbra emails addresses that are allowed to send emails to the `DL`.
If a `DL` has at least one `Owener` is a **Private DL**. If a `DL` has at least one `Owener` is a **Private DL**.
......
...@@ -11,15 +11,15 @@ ...@@ -11,15 +11,15 @@
## DistributionList ## DistributionList
* [ ] Listas privadas * [X] Listas privadas
* [ ] Toda su gestion * [X] Toda su gestion
## Domains ## Domains
* [ ] Add y remove Admins * [X] Add y remove Admins
* [ ] Devolver Tipo de renovación * [X] Devolver Tipo de renovación
* [ ] Devolver Empresa (esto entiendo necesitamos otro API) * [X] Devolver Empresa (esto entiendo necesitamos otro API)
* [X] Devolver casillas segun el tipo de plan, cantidad asignadas y cantidad utilizadas para un dominio * [X] Devolver casillas segun el tipo de plan, cantidad asignadas y cantidad utilizadas para un dominio
* [X] Limite de casillas * [X] Limite de casillas
* [X] Devolver Fecha de la proxima renovación * [X] Devolver Fecha de la proxima renovación
......
...@@ -71,6 +71,10 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -71,6 +71,10 @@ return /******/ (function(modules) { // webpackBootstrap
var _typeof3 = _interopRequireDefault(_typeof2); var _typeof3 = _interopRequireDefault(_typeof2);
var _slicedToArray2 = __webpack_require__(285);
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _classCallCheck2 = __webpack_require__(68); var _classCallCheck2 = __webpack_require__(68);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
...@@ -370,23 +374,22 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -370,23 +374,22 @@ return /******/ (function(modules) { // webpackBootstrap
key: 'grantRight', key: 'grantRight',
value: function grantRight(target_data, grantee_data, right_name, callback) { value: function grantRight(target_data, grantee_data, right_name, callback) {
var request_data = {}; var request_data = {};
var _dictionary$buildTarg = this.dictionary.buildTargetGrantee(target_data, grantee_data);
var _dictionary$buildTarg2 = (0, _slicedToArray3.default)(_dictionary$buildTarg, 2);
var target = _dictionary$buildTarg2[0];
var grantee = _dictionary$buildTarg2[1];
request_data.params = this.requestParams(); request_data.params = this.requestParams();
request_data.request_name = 'GrantRight'; request_data.request_name = 'GrantRight';
request_data.params.name = request_data.request_name + 'Request'; request_data.params.name = request_data.request_name + 'Request';
request_data.response_name = request_data.request_name + 'Response'; request_data.response_name = request_data.request_name + 'Response';
request_data.callback = callback; request_data.callback = callback;
request_data.parse_response = this.parseEmptyResponse; request_data.parse_response = this.parseEmptyResponse;
if (target_data) request_data.params.params.target = { request_data.params.params.grantee = grantee;
'type': target_data.type, request_data.params.params.target = target;
'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier
};
if (grantee_data) request_data.params.params.grantee = {
'type': grantee_data.type,
'by': this.dictionary.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
request_data.params.params.right = { '_content': right_name }; request_data.params.params.right = { '_content': right_name };
this.performRequest(request_data); this.performRequest(request_data);
} }
...@@ -536,6 +539,14 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -536,6 +539,14 @@ return /******/ (function(modules) { // webpackBootstrap
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 _dictionary$buildTarg3 = this.dictionary.buildTargetGrantee(target_data, grantee_data);
var _dictionary$buildTarg4 = (0, _slicedToArray3.default)(_dictionary$buildTarg3, 2);
var target = _dictionary$buildTarg4[0];
var grantee = _dictionary$buildTarg4[1];
var resource = 'Grant'; var resource = 'Grant';
request_data.params = this.requestParams(); request_data.params = this.requestParams();
request_data.request_name = 'Get' + resource + 's'; request_data.request_name = 'Get' + resource + 's';
...@@ -544,17 +555,8 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -544,17 +555,8 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.callback = callback; request_data.callback = callback;
request_data.resource = resource; request_data.resource = resource;
request_data.parse_response = this.parseAllResponse; request_data.parse_response = this.parseAllResponse;
if (target_data) request_data.params.params.target = { request_data.params.params.grantee = grantee;
'type': target_data.type, request_data.params.params.target = target;
'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier
};
if (grantee_data) request_data.params.params.grantee = {
'type': grantee_data.type,
'by': this.dictionary.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
this.performRequest(request_data); this.performRequest(request_data);
} }
...@@ -670,6 +672,29 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -670,6 +672,29 @@ return /******/ (function(modules) { // webpackBootstrap
request_data.params.params = { id: dl_id, dlm: this.dictionary.convertToZimbraArray(members) }; request_data.params.params = { id: dl_id, dlm: this.dictionary.convertToZimbraArray(members) };
this.performRequest(request_data); this.performRequest(request_data);
} }
}, {
key: 'revokeRight',
value: function revokeRight(target_data, grantee_data, right_name, callback) {
var request_data = {};
var _dictionary$buildTarg5 = this.dictionary.buildTargetGrantee(target_data, grantee_data);
var _dictionary$buildTarg6 = (0, _slicedToArray3.default)(_dictionary$buildTarg5, 2);
var target = _dictionary$buildTarg6[0];
var grantee = _dictionary$buildTarg6[1];
request_data.params = this.requestParams();
request_data.request_name = 'RevokeRight';
request_data.params.name = request_data.request_name + 'Request';
request_data.response_name = request_data.request_name + 'Response';
request_data.callback = callback;
request_data.parse_response = this.parseEmptyResponse;
request_data.params.params.grantee = grantee;
request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name };
this.performRequest(request_data);
}
// Search the Directory // Search the Directory
// search_object = { // search_object = {
...@@ -12432,6 +12457,35 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -12432,6 +12457,35 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
return result; return result;
} }
}, {
key: 'buildTargetGrantee',
value: function buildTargetGrantee(target_data, grantee_data) {
var target = null,
grantee = null;
if (target_data) target = {
'type': target_data.type,
'by': this.byIdOrName(target_data.identifier),
'_content': target_data.identifier
};
if (grantee_data) grantee = {
'type': grantee_data.type,
'by': this.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
return [target, grantee];
}
}, {
key: 'buildGranteeData',
value: function buildGranteeData(grantee_id, type) {
return {
'type': type,
'by': this.byIdOrName(grantee_id),
'all': 1,
'_content': grantee_id,
'identifier': grantee_id
};
}
}, { }, {
key: 'classFactory', key: 'classFactory',
value: function classFactory(resource, object, client) { value: function classFactory(resource, object, client) {
...@@ -13282,7 +13336,10 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13282,7 +13336,10 @@ 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, callback) {
var grantee_data = this.buildGranteeData(account_id, 'Account'); var grantee_data = {
'type': 'usr',
'identifier': account_id
};
this.grantRight(grantee_data, this.domainAdminRights, callback); this.grantRight(grantee_data, this.domainAdminRights, callback);
} }
...@@ -13360,6 +13417,15 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13360,6 +13417,15 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
return results; return results;
} }
}, {
key: 'removeAdmin',
value: function removeAdmin(account_id, callback) {
var grantee_data = {
'type': 'usr',
'identifier': account_id
};
this.revokeRight(grantee_data, this.domainAdminRights, callback);
}
}]); }]);
return Domain; return Domain;
}(_zimbra2.default); // Copyright (c) 2016 ZBox, Spa. All Rights Reserved. }(_zimbra2.default); // Copyright (c) 2016 ZBox, Spa. All Rights Reserved.
...@@ -13593,7 +13659,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13593,7 +13659,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
...@@ -13623,7 +13689,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13623,7 +13689,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) {
...@@ -13638,23 +13704,18 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13638,23 +13704,18 @@ return /******/ (function(modules) { // webpackBootstrap
return attrs; return attrs;
} }
}, { }, {
key: 'buildRighTargetData', key: "buildRighTargetData",
value: function buildRighTargetData() { value: function buildRighTargetData() {
var type = this.api.dictionary.classNameToZimbraType(this.constructor.name); var type = this.api.dictionary.classNameToZimbraType(this.constructor.name);
return { type: type, identifier: this.id }; return { type: type, identifier: this.id };
} }
}, { }, {
key: 'buildGranteeData', key: "buildGranteeData",
value: function buildGranteeData(object_id, type) { value: function buildGranteeData(grantee_id, type) {
return { return this.api.dictionary.buildGranteeData(grantee_id, type);
'type': type,
'by': this.api.dictionary.byIdOrName(object_id),
'all': 1,
'_content': object_id
};
} }
}, { }, {
key: 'parseACL', key: "parseACL",
value: function parseACL(acls) { value: function parseACL(acls) {
var elements = [].concat.apply([], [acls]); var elements = [].concat.apply([], [acls]);
var grantees = {}; var grantees = {};
...@@ -13668,7 +13729,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13668,7 +13729,7 @@ return /******/ (function(modules) { // webpackBootstrap
// return ACLS for the Object // return ACLS for the Object
}, { }, {
key: 'getACLs', key: "getACLs",
value: function getACLs(callback) { value: function getACLs(callback) {
if (this.grants) return callback(null, this.grants); if (this.grants) return callback(null, this.grants);
var that = this; var that = this;
...@@ -13679,10 +13740,15 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13679,10 +13740,15 @@ return /******/ (function(modules) { // webpackBootstrap
}); });
} }
}, { }, {
key: 'grantRight', key: "grantRight",
value: function grantRight(grantee_data, right_name, callback) { value: function grantRight(grantee_data, right_name, callback) {
this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback); this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback);
} }
}, {
key: "revokeRight",
value: function revokeRight(grantee_data, right_name, callback) {
this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
}
}]); }]);
return Zimbra; return Zimbra;
}(); }();
...@@ -13952,6 +14018,7 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13952,6 +14018,7 @@ return /******/ (function(modules) { // webpackBootstrap
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(DistributionList).call(this, dl_obj, zimbra_api_client)); var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(DistributionList).call(this, dl_obj, zimbra_api_client));
_this.members = _this.parseMembers(dl_obj); _this.members = _this.parseMembers(dl_obj);
_this.ownerRights = 'sendToDistList';
return _this; return _this;
} }
...@@ -13963,6 +14030,15 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -13963,6 +14030,15 @@ return /******/ (function(modules) { // webpackBootstrap
value: function addMembers(members, callback) { value: function addMembers(members, callback) {
this.api.addDistributionListMember(this.id, members, callback); this.api.addDistributionListMember(this.id, members, callback);
} }
}, {
key: 'addOwner',
value: function addOwner(account_id, callback) {
var grantee_data = {
'type': 'usr',
'identifier': account_id
};
this.grantRight(grantee_data, this.ownerRights, callback);
}
// return the ID of the owner // return the ID of the owner
...@@ -14010,6 +14086,15 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -14010,6 +14086,15 @@ return /******/ (function(modules) { // webpackBootstrap
value: function removeMembers(members, callback) { value: function removeMembers(members, callback) {
this.api.removeDistributionListMember(this.id, members, callback); this.api.removeDistributionListMember(this.id, members, callback);
} }
}, {
key: 'removeOwner',
value: function removeOwner(account_id, callback) {
var grantee_data = {
'type': 'usr',
'identifier': account_id
};
this.revokeRight(grantee_data, this.ownerRights, callback);
}
}]); }]);
return DistributionList; return DistributionList;
}(_zimbra2.default); // Copyright (c) 2016 ZBox, Spa. All Rights Reserved. }(_zimbra2.default); // Copyright (c) 2016 ZBox, Spa. All Rights Reserved.
...@@ -41045,6 +41130,151 @@ return /******/ (function(modules) { // webpackBootstrap ...@@ -41045,6 +41130,151 @@ return /******/ (function(modules) { // webpackBootstrap
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(145).Buffer)) /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(145).Buffer))
/***/ },
/* 285 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var $ = __webpack_require__(3);
var jQuery = __webpack_require__(3);
"use strict";
exports.__esModule = true;
var _isIterable2 = __webpack_require__(286);
var _isIterable3 = _interopRequireDefault(_isIterable2);
var _getIterator2 = __webpack_require__(289);
var _getIterator3 = _interopRequireDefault(_getIterator2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
exports.default = function () {
function sliceIterator(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = (0, _getIterator3.default)(arr), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
return function (arr, i) {
if (Array.isArray(arr)) {
return arr;
} else if ((0, _isIterable3.default)(Object(arr))) {
return sliceIterator(arr, i);
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
};
}();
/***/ },
/* 286 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var $ = __webpack_require__(3);
var jQuery = __webpack_require__(3);
module.exports = { "default": __webpack_require__(287), __esModule: true };
/***/ },
/* 287 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var $ = __webpack_require__(3);
var jQuery = __webpack_require__(3);
__webpack_require__(51);
__webpack_require__(7);
module.exports = __webpack_require__(288);
/***/ },
/* 288 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var $ = __webpack_require__(3);
var jQuery = __webpack_require__(3);
var classof = __webpack_require__(92)
, ITERATOR = __webpack_require__(48)('iterator')
, Iterators = __webpack_require__(30);
module.exports = __webpack_require__(15).isIterable = function(it){
var O = Object(it);
return O[ITERATOR] !== undefined
|| '@@iterator' in O
|| Iterators.hasOwnProperty(classof(O));
};
/***/ },
/* 289 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var $ = __webpack_require__(3);
var jQuery = __webpack_require__(3);
module.exports = { "default": __webpack_require__(290), __esModule: true };
/***/ },
/* 290 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var $ = __webpack_require__(3);
var jQuery = __webpack_require__(3);
__webpack_require__(51);
__webpack_require__(7);
module.exports = __webpack_require__(291);
/***/ },
/* 291 */
/***/ function(module, exports, __webpack_require__) {
/*** IMPORTS FROM imports-loader ***/
var $ = __webpack_require__(3);
var jQuery = __webpack_require__(3);
var anObject = __webpack_require__(20)
, get = __webpack_require__(91);
module.exports = __webpack_require__(15).getIterator = function(it){
var iterFn = get(it);
if(typeof iterFn != 'function')throw TypeError(it + ' is not iterable!');
return anObject(iterFn.call(it));
};
/***/ } /***/ }
/******/ ]) /******/ ])
}); });
This source diff could not be displayed because it is too large. You can view the blob instead.
{ {
"name": "zimbra-admin-api-js", "name": "zimbra-admin-api-js",
"version": "0.0.14", "version": "0.0.15",
"private": true, "private": true,
"main": "lib/zimbra-admin-api.js", "main": "lib/zimbra-admin-api.js",
"dependencies": { "dependencies": {
......
...@@ -262,23 +262,15 @@ export default class ZimbraAdminApi { ...@@ -262,23 +262,15 @@ export default class ZimbraAdminApi {
// } // }
grantRight(target_data, grantee_data, right_name, callback) { grantRight(target_data, grantee_data, right_name, callback) {
const request_data = { }; const request_data = { };
const [target, grantee] = this.dictionary.buildTargetGrantee(target_data, grantee_data);
request_data.params = this.requestParams(); request_data.params = this.requestParams();
request_data.request_name = 'GrantRight'; request_data.request_name = 'GrantRight';
request_data.params.name = `${request_data.request_name}Request`; request_data.params.name = `${request_data.request_name}Request`;
request_data.response_name = `${request_data.request_name}Response`; request_data.response_name = `${request_data.request_name}Response`;
request_data.callback = callback; request_data.callback = callback;
request_data.parse_response = this.parseEmptyResponse; request_data.parse_response = this.parseEmptyResponse;
if (target_data) request_data.params.params.target = { request_data.params.params.grantee = grantee;
'type': target_data.type, request_data.params.params.target = target;
'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier
};
if (grantee_data) request_data.params.params.grantee = {
'type': grantee_data.type,
'by': this.dictionary.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
request_data.params.params.right = { '_content': right_name }; request_data.params.params.right = { '_content': right_name };
this.performRequest(request_data); this.performRequest(request_data);
} }
...@@ -399,6 +391,7 @@ export default class ZimbraAdminApi { ...@@ -399,6 +391,7 @@ export default class ZimbraAdminApi {
// } // }
getGrants(target_data, grantee_data, callback) { getGrants(target_data, grantee_data, callback) {
const request_data = { }; const request_data = { };
const [target, grantee] = this.dictionary.buildTargetGrantee(target_data, grantee_data);
const resource = 'Grant'; const resource = 'Grant';
request_data.params = this.requestParams(); request_data.params = this.requestParams();
request_data.request_name = `Get${resource}s`; request_data.request_name = `Get${resource}s`;
...@@ -407,17 +400,8 @@ export default class ZimbraAdminApi { ...@@ -407,17 +400,8 @@ export default class ZimbraAdminApi {
request_data.callback = callback; request_data.callback = callback;
request_data.resource = resource; request_data.resource = resource;
request_data.parse_response = this.parseAllResponse; request_data.parse_response = this.parseAllResponse;
if (target_data) request_data.params.params.target = { request_data.params.params.grantee = grantee;
'type': target_data.type, request_data.params.params.target = target;
'by': this.dictionary.byIdOrName(target_data.identifier),
'_content': target_data.identifier
};
if (grantee_data) request_data.params.params.grantee = {
'type': grantee_data.type,
'by': this.dictionary.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
this.performRequest(request_data); this.performRequest(request_data);
} }
...@@ -507,6 +491,21 @@ export default class ZimbraAdminApi { ...@@ -507,6 +491,21 @@ export default class ZimbraAdminApi {
this.performRequest(request_data); this.performRequest(request_data);
} }
revokeRight(target_data, grantee_data, right_name, callback) {
const request_data = { };
const [target, grantee] = this.dictionary.buildTargetGrantee(target_data, grantee_data);
request_data.params = this.requestParams();
request_data.request_name = 'RevokeRight';
request_data.params.name = `${request_data.request_name}Request`;
request_data.response_name = `${request_data.request_name}Response`;
request_data.callback = callback;
request_data.parse_response = this.parseEmptyResponse;
request_data.params.params.grantee = grantee;
request_data.params.params.target = target;
request_data.params.params.right = { '_content': right_name };
this.performRequest(request_data);
}
// Search the Directory // Search the Directory
// search_object = { // search_object = {
// query: An LDAP query or null for everything, // query: An LDAP query or null for everything,
......
...@@ -37,6 +37,33 @@ export default class Dictionary { ...@@ -37,6 +37,33 @@ export default class Dictionary {
return result; return result;
} }
buildTargetGrantee(target_data, grantee_data) {
let target = null, grantee = null;
if (target_data) target = {
'type': target_data.type,
'by': this.byIdOrName(target_data.identifier),
'_content': target_data.identifier
}
if (grantee_data) grantee =
{
'type': grantee_data.type,
'by': this.byIdOrName(grantee_data.identifier),
'all': 1,
'_content': grantee_data.identifier
};
return([target, grantee]);
}
buildGranteeData(grantee_id, type) {
return {
'type': type,
'by': this.byIdOrName(grantee_id),
'all': 1,
'_content': grantee_id,
'identifier': grantee_id
};
}
classFactory (resource, object, client) { classFactory (resource, object, client) {
const class_name = this.resourceToClass(resource.toLowerCase()); const class_name = this.resourceToClass(resource.toLowerCase());
return new class_name(object, client); return new class_name(object, client);
......
...@@ -7,6 +7,7 @@ export default class DistributionList extends Zimbra { ...@@ -7,6 +7,7 @@ export default class DistributionList extends Zimbra {
constructor(dl_obj, zimbra_api_client) { constructor(dl_obj, zimbra_api_client) {
super(dl_obj, zimbra_api_client); super(dl_obj, zimbra_api_client);
this.members = this.parseMembers(dl_obj); this.members = this.parseMembers(dl_obj);
this.ownerRights = 'sendToDistList';
} }
// Add members to DL // Add members to DL
...@@ -14,6 +15,14 @@ export default class DistributionList extends Zimbra { ...@@ -14,6 +15,14 @@ export default class DistributionList extends Zimbra {
this.api.addDistributionListMember(this.id, members, callback); this.api.addDistributionListMember(this.id, members, callback);
} }
addOwner(account_id, callback) {
const grantee_data = {
'type': 'usr',
'identifier': account_id
}
this.grantRight(grantee_data, this.ownerRights, callback);
}
// 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);
...@@ -53,4 +62,13 @@ export default class DistributionList extends Zimbra { ...@@ -53,4 +62,13 @@ export default class DistributionList extends Zimbra {
this.api.removeDistributionListMember(this.id, members, callback); this.api.removeDistributionListMember(this.id, members, callback);
} }
removeOwner(account_id, callback) {
const grantee_data = {
'type': 'usr',
'identifier': account_id
}
this.revokeRight(grantee_data, this.ownerRights, callback);
}
} }
...@@ -10,7 +10,10 @@ export default class Domain extends Zimbra { ...@@ -10,7 +10,10 @@ export default class Domain extends Zimbra {
} }
addAdmin(account_id, callback) { addAdmin(account_id, callback) {
const grantee_data = this.buildGranteeData(account_id, 'Account'); const grantee_data = {
'type': 'usr',
'identifier': account_id
}
this.grantRight(grantee_data, this.domainAdminRights, callback); this.grantRight(grantee_data, this.domainAdminRights, callback);
} }
...@@ -80,4 +83,12 @@ export default class Domain extends Zimbra { ...@@ -80,4 +83,12 @@ export default class Domain extends Zimbra {
return results; return results;
} }
removeAdmin(account_id, callback) {
const grantee_data = {
'type': 'usr',
'identifier': account_id
}
this.revokeRight(grantee_data, this.domainAdminRights, callback);
}
} }
...@@ -28,13 +28,8 @@ export default class Zimbra { ...@@ -28,13 +28,8 @@ export default class Zimbra {
return { type: type, identifier: this.id }; return { type: type, identifier: this.id };
} }
buildGranteeData(object_id, type) { buildGranteeData(grantee_id, type) {
return { return this.api.dictionary.buildGranteeData(grantee_id, type);
'type': type,
'by': this.api.dictionary.byIdOrName(object_id),
'all': 1,
'_content': object_id
};
} }
parseACL(acls) { parseACL(acls) {
...@@ -62,4 +57,8 @@ export default class Zimbra { ...@@ -62,4 +57,8 @@ export default class Zimbra {
this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback); this.api.grantRight(this.buildRighTargetData(), grantee_data, right_name, callback);
} }
revokeRight(grantee_data, right_name, callback){
this.api.revokeRight(this.buildRighTargetData(), grantee_data, right_name, callback);
}
} }
...@@ -456,7 +456,41 @@ ...@@ -456,7 +456,41 @@
}); });
}); });
it('addAdmin should add Admin', function(done){
let api = new ZimbraAdminApi(auth_data);
let domain_admin = 'domain_admin@customer.dev';
let resource_name = Date.now() + '.dev';
api.createDomain(resource_name, {}, function(err, data){
if (err) console.error(err);
let domain = data;
domain.addAdmin(domain_admin, function(e, d){
if (e) return console.error(e);
expect(err).to.be.null;
domain.getACLs(function(e, d){
if (e) return console.error(e);
expect(d[0].grantee.name).to.be.equal(domain_admin);
done();
});
});
});
});
it('removeAdmin should remove the Admin', function(done){
let api = new ZimbraAdminApi(auth_data);
let domain_admin = 'domain_admin@customer.dev';
let resource_name = Date.now() + '.dev';
api.createDomain(resource_name, {}, function(err, domain){
domain.addAdmin(domain_admin, function(e, d){
domain.removeAdmin(domain_admin, function(e, d){
domain.getACLs(function(e, d){
if (e) return console.error(e);
expect(d.length).to.be.equal(0);
done();
});
});
});
});
});
}); });
...@@ -554,6 +588,40 @@ ...@@ -554,6 +588,40 @@
}); });
}); });
it('addOwner should add Owner', function(done){
let api = new ZimbraAdminApi(auth_data);
let owner_email = 'domain_admin@customer.dev';
let resource_name = Date.now() + '@customer.dev';
api.createDistributionList(resource_name, {}, function(err, dl){
dl.addOwner(owner_email, function(e, d){
if (e) return console.error(e);
expect(err).to.be.null;
dl.getACLs(function(e, d){
if (e) return console.error(e);
expect(d[0].grantee.name).to.be.equal(owner_email);
done();
});
});
});
});
it('removeOwner should remove the Owner', function(done){
let api = new ZimbraAdminApi(auth_data);
let owner_email = 'domain_admin@customer.dev';
let resource_name = Date.now() + '@customer.dev';
api.createDistributionList(resource_name, {}, function(err, dl){
dl.addOwner(owner_email, function(e, d){
dl.removeOwner(owner_email, function(e, d){
dl.getACLs(function(e, d){
if (e) return console.error(e);
expect(d.length).to.be.equal(0);
done();
});
});
});
});
});
}); });
describe('Grants tests', function() { describe('Grants tests', function() {
......
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