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
9835cecb
Commit
9835cecb
authored
Apr 28, 2016
by
Patricio Bruna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Every function now works with BatchRequest
parent
d7e9b763
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
180 additions
and
241 deletions
+180
-241
README.md
README.md
+13
-0
zimbra-admin-api.js
lib/zimbra-admin-api.js
+79
-93
zimbra-admin-api.js.map
lib/zimbra-admin-api.js.map
+1
-1
index.js
src/index.js
+57
-62
domain.js
src/zimbra/domain.js
+21
-25
zimbra.js
src/zimbra/zimbra.js
+6
-4
test.js
test/js/spec/test.js
+3
-56
No files found.
README.md
View file @
9835cecb
...
...
@@ -163,6 +163,19 @@ zimbraApi.getAllAccounts(callback, query_object);
```
## Batch Request Functions
With
`BatchRequest`
you can ask Zimbra to run multiple requests in just one call, and get
the result in just one answer.
Every function here works for
`BatchRequest`
if you do not pass a
`callback`
. For example:
```
javascript
var
allAccounts
=
zimbraApi
.
getAllAccounts
();
var
allDomains
=
zimbraApi
.
getAllDomains
();
zimbraApi
.
makeBatchRequest
([
allAccounts
,
allDomains
],
callback
);
// Object {SearchDirectoryResponse: Array[2], _jsns: "urn:zimbra"}
// SearchDirectoryResponse[0].account, SearchDirectoryResponse[1].domain
```
### Count Accounts for several Domains
Pass an array of domains ids or names and you get back an array of
`countAccounts`
responses
...
...
lib/zimbra-admin-api.js
View file @
9835cecb
This diff is collapsed.
Click to expand it.
lib/zimbra-admin-api.js.map
View file @
9835cecb
This diff is collapsed.
Click to expand it.
src/index.js
View file @
9835cecb
This diff is collapsed.
Click to expand it.
src/zimbra/domain.js
View file @
9835cecb
...
...
@@ -13,47 +13,33 @@ export default class Domain extends Zimbra {
addAdmin
(
account_id
,
callback
)
{
const
request_data
=
{};
const
grantee_data
=
{
'type'
:
'usr'
,
'identifier'
:
account_id
};
let
modifyAccountRequest
=
this
.
api
.
modifyAccount
(
account_id
,
{
zimbraIsDelegatedAdminAccount
:
'TRUE'
},
callback
,
true
);
const
grantRightRequest
=
this
.
grantRight
(
grantee_data
,
this
.
domainAdminRights
,
callback
,
true
);
const
modifyAccountRequest
=
this
.
api
.
modifyAccount
(
account_id
,
{
zimbraIsDelegatedAdminAccount
:
'TRUE'
}
);
const
grantRightRequest
=
this
.
grantRight
(
grantee_data
,
this
.
domainAdminRights
);
request_data
.
requests
=
[
modifyAccountRequest
,
grantRightRequest
];
request_data
.
batch
=
true
;
request_data
.
callback
=
function
(
err
,
data
)
{
if
(
err
)
return
callback
(
err
);
callback
(
null
,
data
.
GrantRightResponse
);
};
this
.
api
.
performRequest
(
request_data
,
true
);
this
.
api
.
performRequest
(
request_data
);
}
// TODO: Fix this fucking ugly code
getAdmins
(
callback
)
{
const
that
=
this
;
this
.
getAdminsIdsFromGrants
(
function
(
e
,
d
){
if
(
e
)
return
callback
(
e
);
if
(
d
.
length
<
1
)
return
callback
(
null
,
[]);
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
);
return
callback
(
null
,
[]);
},
{
query
:
query
});
});
const
admins_ids
=
this
.
getAdminsIdsFromGrants
();
const
query
=
this
.
makeAdminIdsQuery
(
admins_ids
);
return
this
.
api
.
getAllAccounts
(
callback
,
{
query
:
query
});
}
// Return the ZimbraId if the grantee have the domainAdminRights right
// Grant.right_name() == domainAdminRights
getAdminsIdsFromGrants
(
callback
)
{
getAdminsIdsFromGrants
()
{
const
ids
=
[];
this
.
getACLs
(
function
(
err
,
data
){
if
(
err
)
return
callback
(
err
);
data
.
forEach
((
grant
)
=>
{
if
(
grant
.
isDomainAdminGrant
())
ids
.
push
(
grant
.
granteeId
);
});
return
callback
(
null
,
ids
);
this
.
parseACL
(
this
.
attrs
.
zimbraACE
).
forEach
((
grantee
)
=>
{
if
(
grantee
.
right
===
this
.
domainAdminRights
)
ids
.
push
(
grantee
.
id
);
});
return
ids
;
}
getAllDistributionLists
(
callback
)
{
...
...
@@ -76,6 +62,16 @@ export default class Domain extends Zimbra {
});
}
makeAdminIdsQuery
(
ids
)
{
let
query
=
"(|"
;
ids
.
forEach
((
id
)
=>
{
const
zimbra_id
=
`(zimbraId=
${
id
}
)`
;
query
+=
zimbra_id
;
});
query
+=
")"
;
return
query
;
}
maxAccountsByCos
()
{
const
results
=
{};
if
(
typeof
this
.
attrs
.
zimbraDomainCOSMaxAccounts
===
'undefined'
)
return
null
;
...
...
src/zimbra/zimbra.js
View file @
9835cecb
...
...
@@ -34,10 +34,12 @@ export default class Zimbra {
parseACL
(
acls
)
{
const
elements
=
[].
concat
.
apply
([],
[
acls
]);
const
grantees
=
{};
elements
.
forEach
((
el
)
=>
{
grantee_data
=
el
.
split
(
/ /
);
grantees
[
grantee_data
[
0
]]
=
{
type
:
grantee_data
[
1
],
right
:
grantee_data
[
2
]};
const
grantees
=
[];
// Filter to remove undefined
// http://stackoverflow.com/questions/28607451/removing-undefined-values-from-array
elements
.
filter
(
Boolean
).
forEach
((
el
)
=>
{
const
grantee_data
=
el
.
split
(
/ /
);
grantees
.
push
({
id
:
grantee_data
[
0
],
type
:
grantee_data
[
1
],
right
:
grantee_data
[
2
]});
});
return
grantees
;
}
...
...
test/js/spec/test.js
View file @
9835cecb
...
...
@@ -8,63 +8,9 @@
'password'
:
'12345678'
};
function
loadFixture
(
fixtureName
)
{
var
req
=
new
XMLHttpRequest
();
req
.
open
(
'GET'
,
'fixtures/'
+
fixtureName
+
'.json'
,
false
);
req
.
send
(
null
);
if
(
req
.
status
===
200
)
{
return
JSON
.
parse
(
req
.
responseText
);
}
else
{
return
null
;
}
}
describe
(
'Basic tests'
,
function
()
{
this
.
timeout
(
5000
);
it
(
'should return error object when timeout'
,
function
()
{
let
api
=
new
ZimbraAdminApi
({
'url'
:
'http://localhost'
,
'user'
:
'user'
,
'password'
:
'pass'
});
api
.
login
(
null
,
function
(
err
){
let
error
=
api
.
handleError
(
err
);
expect
(
error
.
constructor
.
name
).
to
.
equal
(
'Error'
);
expect
(
error
.
title
).
to
.
equal
(
'timeout'
);
});
});
it
(
'return error if wrong validation'
,
function
(
done
)
{
var
auth_data2
=
JSON
.
parse
(
JSON
.
stringify
(
auth_data
));
auth_data2
.
password
=
'abc'
;
let
api
=
new
ZimbraAdminApi
(
auth_data2
);
let
callback
=
function
(
err
,
response
)
{
let
error
=
api
.
handleError
(
err
);
expect
(
error
.
constructor
.
name
).
to
.
equal
(
'Error'
);
expect
(
error
.
extra
.
code
).
to
.
equal
(
'account.AUTH_FAILED'
);
done
();
};
api
.
login
(
callback
);
});
it
(
'return token if ok validation'
,
function
(
done
)
{
let
api
=
new
ZimbraAdminApi
(
auth_data
);
let
callback
=
function
(
err
,
response
)
{
if
(
err
)
return
console
.
error
(
err
);
expect
(
api
.
client
.
token
).
to
.
exist
;
done
();
};
api
.
login
(
callback
);
});
it
(
'should delete the password after authentication'
,
function
(
done
)
{
let
api
=
new
ZimbraAdminApi
(
auth_data
);
let
callback
=
function
(
err
,
response
)
{
expect
(
api
.
secret
).
not
.
to
.
exist
;
expect
(
api
.
password
).
not
.
to
.
exist
;
done
();
}
api
.
login
(
callback
);
});
it
(
'should get all domains'
,
function
(
done
)
{
let
api
=
new
ZimbraAdminApi
(
auth_data
);
...
...
@@ -471,8 +417,9 @@
if
(
err
)
console
.
error
(
err
);
let
domain
=
data
;
domain
.
getAdmins
(
function
(
e
,
d
){
expect
(
d
.
length
).
to
.
be
.
above
(
1
);
expect
(
d
[
0
].
constructor
.
name
).
to
.
be
.
equal
(
'Account'
);
if
(
e
)
return
console
.
error
(
e
);
expect
(
d
.
account
.
length
).
to
.
be
.
above
(
1
);
expect
(
d
.
account
[
0
].
constructor
.
name
).
to
.
be
.
equal
(
'Account'
);
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