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
0a7d584a
Commit
0a7d584a
authored
Apr 21, 2016
by
Patricio Bruna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return Domain Admins
parent
458a4bf5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
142 additions
and
8 deletions
+142
-8
README.md
README.md
+10
-0
zimbra-admin-api.js
lib/zimbra-admin-api.js
+64
-7
zimbra-admin-api.js.map
lib/zimbra-admin-api.js.map
+1
-1
domain.js
src/zimbra/domain.js
+34
-0
grant.js
src/zimbra/grant.js
+8
-0
test.js
test/js/spec/test.js
+25
-0
No files found.
README.md
View file @
0a7d584a
...
@@ -316,3 +316,13 @@ domain.countAccounts(callback);
...
@@ -316,3 +316,13 @@ 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
`{}`
.
### Domain Admins
Return an Array of the Domain Admins
`Accounts`
.
```
javascript
// domain is a Domain, you got it from zimbraApi.getDomain....
domain
.
admins
(
callback
);
// [Account, Account]
```
lib/zimbra-admin-api.js
View file @
0a7d584a
...
@@ -13103,7 +13103,47 @@ return /******/ (function(modules) { // webpackBootstrap
...
@@ -13103,7 +13103,47 @@ return /******/ (function(modules) { // webpackBootstrap
return _this;
return _this;
}
}
// TODO: Fix this fucking ugly code
(0, _createClass3.default)(Domain, [{
(0, _createClass3.default)(Domain, [{
key: 'admins',
value: function admins(callback) {
var that = this;
this.getAdminsIdsFromGrants(function (e, d) {
if (e) return callback(e);
if (d.length < 1) return [];
var query = "(|";
d.forEach(function (id) {
var zimbra_id = '(zimbraId=' + id + ')';
query += zimbra_id;
});
query += ")";
that.api.getAllAccounts(function (e, d) {
if (e) return callback(e);
if (d.total > 0) return callback(null, d.account);
callback(null, []);
}, { query: query });
});
}
// Return the ZimbraId if the grantee have the domainAdminRights right
// Grant.right_name() == domainAdminRights
}, {
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) {
if (grant.isDomainAdminGrant()) ids.push(grant.granteeId);
});
return callback(null, ids);
});
}
}, {
key: 'countAccounts',
key: 'countAccounts',
value: function countAccounts(callback) {
value: function countAccounts(callback) {
var maxAccountsByCos = this.maxAccountsByCos();
var maxAccountsByCos = this.maxAccountsByCos();
...
@@ -40146,7 +40186,7 @@ return /******/ (function(modules) { // webpackBootstrap
...
@@ -40146,7 +40186,7 @@ return /******/ (function(modules) { // webpackBootstrap
/* 283 */
/* 283 */
/***/ 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
...
@@ -40156,19 +40196,36 @@ return /******/ (function(modules) { // webpackBootstrap
...
@@ -40156,19 +40196,36 @@ return /******/ (function(modules) { // webpackBootstrap
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = __webpack_require__(69);
var _createClass3 = _interopRequireDefault(_createClass2);
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.
// Copyright (c) 2016 ZBox, Spa. All Rights Reserved.
// See LICENSE.txt for license information.
// See LICENSE.txt for license information.
var Grant = function Grant(grant) {
var Grant = function () {
(0, _classCallCheck3.default)(this, Grant);
function Grant(grant) {
(0, _classCallCheck3.default)(this, Grant);
this.grantee = grant.grantee[0];
this.grantee = grant.grantee[0];
this.target = grant.target[0];
this.target = grant.target[0];
this.right = grant.right[0];
this.right = grant.right[0];
};
this.rightName = this.right._content;
this.granteeId = this.grantee.id;
}
(0, _createClass3.default)(Grant, [{
key: 'isDomainAdminGrant',
value: function isDomainAdminGrant() {
if (this.rightName === 'domainAdminRights') return true;
return false;
}
}]);
return Grant;
}();
exports.default = Grant;
exports.default = Grant;
/***/ }
/***/ }
lib/zimbra-admin-api.js.map
View file @
0a7d584a
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/zimbra/domain.js
View file @
0a7d584a
...
@@ -9,6 +9,40 @@ export default class Domain extends Zimbra {
...
@@ -9,6 +9,40 @@ export default class Domain extends Zimbra {
this
.
domainAdminRights
=
'domainAdminRights'
;
this
.
domainAdminRights
=
'domainAdminRights'
;
}
}
// TODO: Fix this fucking ugly code
admins
(
callback
)
{
const
that
=
this
;
this
.
getAdminsIdsFromGrants
(
function
(
e
,
d
){
if
(
e
)
return
callback
(
e
);
if
(
d
.
length
<
1
)
return
[];
let
query
=
"(|"
;
d
.
forEach
((
id
)
=>
{
const
zimbra_id
=
`(zimbraId=
${
id
}
)`
;
query
+=
zimbra_id
;
});
query
+=
")"
;
that
.
api
.
getAllAccounts
(
function
(
e
,
d
){
if
(
e
)
return
callback
(
e
);
if
(
d
.
total
>
0
)
return
callback
(
null
,
d
.
account
);
callback
(
null
,
[]);
},
{
query
:
query
});
});
}
// Return the ZimbraId if the grantee have the domainAdminRights right
// 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
)
=>
{
if
(
grant
.
isDomainAdminGrant
())
ids
.
push
(
grant
.
granteeId
);
});
return
callback
(
null
,
ids
);
});
}
countAccounts
(
callback
)
{
countAccounts
(
callback
)
{
const
maxAccountsByCos
=
this
.
maxAccountsByCos
();
const
maxAccountsByCos
=
this
.
maxAccountsByCos
();
this
.
api
.
countAccounts
(
this
.
id
,
function
(
e
,
d
){
this
.
api
.
countAccounts
(
this
.
id
,
function
(
e
,
d
){
...
...
src/zimbra/grant.js
View file @
0a7d584a
...
@@ -6,5 +6,13 @@ export default class Grant {
...
@@ -6,5 +6,13 @@ export default class Grant {
this
.
grantee
=
grant
.
grantee
[
0
];
this
.
grantee
=
grant
.
grantee
[
0
];
this
.
target
=
grant
.
target
[
0
];
this
.
target
=
grant
.
target
[
0
];
this
.
right
=
grant
.
right
[
0
];
this
.
right
=
grant
.
right
[
0
];
this
.
rightName
=
this
.
right
.
_content
;
this
.
granteeId
=
this
.
grantee
.
id
;
}
}
isDomainAdminGrant
()
{
if
(
this
.
rightName
===
'domainAdminRights'
)
return
true
;
return
false
;
}
}
}
test/js/spec/test.js
View file @
0a7d584a
...
@@ -340,6 +340,31 @@
...
@@ -340,6 +340,31 @@
});
});
});
});
it
(
'domain.admins() should return the domain admins'
,
function
(
done
){
let
api
=
new
ZimbraAdminApi
(
auth_data
);
api
.
getDomain
(
'customer.dev'
,
function
(
err
,
data
){
if
(
err
)
console
.
error
(
err
);
let
domain
=
data
;
domain
.
admins
(
function
(
e
,
d
){
expect
(
d
.
length
).
to
.
be
.
above
(
1
);
expect
(
d
[
0
].
constructor
.
name
).
to
.
be
.
equal
(
'Account'
);
done
();
});
});
});
it
(
'domain.admins() should return empty array if no admins'
,
function
(
done
){
let
api
=
new
ZimbraAdminApi
(
auth_data
);
api
.
getDomain
(
'zboxapp.dev'
,
function
(
err
,
data
){
if
(
err
)
console
.
error
(
err
);
let
domain
=
data
;
domain
.
admins
(
function
(
e
,
d
){
expect
(
d
.
length
).
to
.
be
.
empty
;
done
();
});
});
});
});
});
describe
(
'DistributionList tests'
,
function
()
{
describe
(
'DistributionList tests'
,
function
()
{
...
...
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