Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zimbra-admin-api-js
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Public
zimbra-admin-api-js
Commits
8a64acef
Commit
8a64acef
authored
Apr 25, 2016
by
Patricio Bruna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pumped version 0.0.14
parent
b82a9d11
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
136 additions
and
47 deletions
+136
-47
zimbra-admin-api.js
lib/zimbra-admin-api.js
+74
-24
zimbra-admin-api.js.map
lib/zimbra-admin-api.js.map
+1
-1
package.json
package.json
+1
-1
dictionary.js
src/utils/dictionary.js
+6
-0
distribution_list.js
src/zimbra/distribution_list.js
+17
-15
domain.js
src/zimbra/domain.js
+8
-4
zimbra.js
src/zimbra/zimbra.js
+29
-0
test.js
test/js/spec/test.js
+0
-2
No files found.
lib/zimbra-admin-api.js
View file @
8a64acef
...
...
@@ -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
lib/zimbra-admin-api.js.map
View file @
8a64acef
This diff is collapsed.
Click to expand it.
package.json
View file @
8a64acef
{
"name"
:
"zimbra-admin-api-js"
,
"version"
:
"0.0.1
3
"
,
"version"
:
"0.0.1
4
"
,
"private"
:
true
,
"main"
:
"lib/zimbra-admin-api.js"
,
"dependencies"
:
{
...
...
src/utils/dictionary.js
View file @
8a64acef
...
...
@@ -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
:
{
...
...
src/zimbra/distribution_list.js
View file @
8a64acef
...
...
@@ -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
);
...
...
src/zimbra/domain.js
View file @
8a64acef
...
...
@@ -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
);
...
...
src/zimbra/zimbra.js
View file @
8a64acef
...
...
@@ -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
);
}
}
test/js/spec/test.js
View file @
8a64acef
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment