Commit 623f2f19 authored by Patricio Bruna's avatar Patricio Bruna

Array attributes working now

parent 00b65399
......@@ -12611,11 +12611,19 @@ return /******/ (function(modules) { // webpackBootstrap
}, {
key: 'attributesToArray',
value: function attributesToArray(attributes) {
var _this = this;
if ($.isEmptyObject(attributes)) return [];
var result = [];
var map = new _map2.default((0, _entries2.default)(attributes));
map.forEach(function (key, value) {
result.push({ 'n': value, '_content': key });
if (_this.checkIfArray(key)) {
key.forEach(function (e) {
result.push({ 'n': value, '_content': e });
});
} else {
result.push({ 'n': value, '_content': key });
}
});
return result;
}
......@@ -12654,6 +12662,15 @@ return /******/ (function(modules) { // webpackBootstrap
var class_name = this.resourceToClass(resource.toLowerCase());
return new class_name(object, client);
}
}, {
key: 'checkIfArray',
value: function checkIfArray(object) {
var result = false;
if (Object.prototype.toString.call(object) === '[object Array]') {
result = true;
}
return result;
}
// This return a string or array of objects
// useful for Zimbra functions that works with both
This diff is collapsed.
{
"name": "zimbra-admin-api-js",
"version": "0.0.19",
"version": "0.0.20",
"private": true,
"main": "lib/zimbra-admin-api.js",
"dependencies": {
......
......@@ -32,7 +32,13 @@ export default class Dictionary {
const result = [];
const map = new Map(Object.entries(attributes));
map.forEach((key, value) => {
result.push({ 'n': value, '_content': key });
if (this.checkIfArray(key)) {
key.forEach((e) => {
result.push({ 'n': value, '_content': e });
});
} else {
result.push({ 'n': value, '_content': key });
}
});
return result;
}
......@@ -43,7 +49,7 @@ export default class Dictionary {
'type': target_data.type,
'by': this.byIdOrName(target_data.identifier),
'_content': target_data.identifier
}
};
if (grantee_data) grantee =
{
'type': grantee_data.type,
......@@ -69,6 +75,14 @@ export default class Dictionary {
return new class_name(object, client);
}
checkIfArray(object) {
let result = false;
if( Object.prototype.toString.call(object) === '[object Array]' ) {
result = true;
}
return result;
}
// This return a string or array of objects
// useful for Zimbra functions that works with both
convertToZimbraArray (object) {
......
......@@ -172,6 +172,21 @@
});
});
it('Should create Account with an array attributes', function(done){
let account_name = Date.now() + '@big.com';
let account_password = Date.now();
let account_attributes = { 'sn': 'Bruna', 'givenName': 'Patricio' };
account_attributes.amavisBlacklistSender = ['1.com', '2.com', '3.com'];
let api = new ZimbraAdminApi(auth_data);
api.createAccount(account_name, account_password, account_attributes, function(err, data){
if (err) return console.log(err);
expect(data.attrs.sn).to.equal('Bruna');
expect(data.attrs.givenName).to.equal('Patricio');
console.log(data);
done();
});
});
it('should modify Account attributes', function(done){
let api = new ZimbraAdminApi(auth_data);
let description = Date.now().toString();
......
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