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
b82a9d11
Commit
b82a9d11
authored
Apr 25, 2016
by
Patricio Bruna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get Owners for DLs
parent
1ada2a0b
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
166 additions
and
3 deletions
+166
-3
README.md
README.md
+10
-0
zimbra-admin-api.js
lib/zimbra-admin-api.js
+74
-0
zimbra-admin-api.js.map
lib/zimbra-admin-api.js.map
+1
-1
index.js
src/index.js
+29
-0
distribution_list.js
src/zimbra/distribution_list.js
+22
-0
grant.js
src/zimbra/grant.js
+5
-0
zimbra.js
src/zimbra/zimbra.js
+10
-0
test.js
test/js/spec/test.js
+15
-2
No files found.
README.md
View file @
b82a9d11
...
@@ -386,3 +386,13 @@ dl.removeMembers('new_member@example.com', callback);
...
@@ -386,3 +386,13 @@ dl.removeMembers('new_member@example.com', callback);
dl
.
removeMembers
([
'1@example.com'
,
'2@example.com'
],
callback
);
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
```
```
### Get Owners
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**
.
```
javascript
dl
.
getOwners
(
callback
);
// Array of Objects
// {name: 'email_address', id: 'ZimbraId', type: 'usr|grp'}
```
lib/zimbra-admin-api.js
View file @
b82a9d11
...
@@ -359,6 +359,38 @@ return /******/ (function(modules) { // webpackBootstrap
...
@@ -359,6 +359,38 @@ return /******/ (function(modules) { // webpackBootstrap
this.performRequest(request_data);
this.performRequest(request_data);
}
}
// Grant a right on a target to an individual or group grantee.
// target_data and grantee_data are both objects like:
// {
// type: (account|cos|dl|domain),
// identifier: (name or zimbraId)
// }
}, {
key: 'grantRight',
value: function grantRight(target_data, grantee_data, right_name, callback) {
var request_data = {};
request_data.params = this.requestParams();
request_data.request_name = 'GrantRight';
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;
if (target_data) request_data.params.params.target = {
'type': target_data.type,
'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 };
this.performRequest(request_data);
}
// Specific functions
// Specific functions
}, {
}, {
...
@@ -13593,6 +13625,17 @@ return /******/ (function(modules) { // webpackBootstrap
...
@@ -13593,6 +13625,17 @@ return /******/ (function(modules) { // webpackBootstrap
});
});
return attrs;
return attrs;
}
}
}, {
key: "parseACL",
value: function parseACL(acls) {
var elements = [].concat.apply([], [acls]);
var grantees = {};
elements.forEach(function (el) {
grantee_data = el.split(/ /);
grantees[grantee_data[0]] = { type: grantee_data[1], right: grantee_data[2] };
});
return grantees;
}
}]);
}]);
return Zimbra;
return Zimbra;
}();
}();
...
@@ -13805,6 +13848,12 @@ return /******/ (function(modules) { // webpackBootstrap
...
@@ -13805,6 +13848,12 @@ return /******/ (function(modules) { // webpackBootstrap
if (this.rightName === 'domainAdminRights') return true;
if (this.rightName === 'domainAdminRights') return true;
return false;
return false;
}
}
}, {
key: 'isDistributionListOwnerGrant',
value: function isDistributionListOwnerGrant() {
if (this.rightName === 'sendToDistList') return true;
return false;
}
}]);
}]);
return Grant;
return Grant;
}();
}();
...
@@ -13867,6 +13916,31 @@ return /******/ (function(modules) { // webpackBootstrap
...
@@ -13867,6 +13916,31 @@ 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);
}
}
// return the ID of the owner
}, {
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);
});
}
}, {
}, {
key: 'parseMembers',
key: 'parseMembers',
value: function parseMembers(obj) {
value: function parseMembers(obj) {
lib/zimbra-admin-api.js.map
View file @
b82a9d11
This diff is collapsed.
Click to expand it.
src/index.js
View file @
b82a9d11
...
@@ -254,6 +254,35 @@ export default class ZimbraAdminApi {
...
@@ -254,6 +254,35 @@ export default class ZimbraAdminApi {
this
.
performRequest
(
request_data
);
this
.
performRequest
(
request_data
);
}
}
// Grant a right on a target to an individual or group grantee.
// target_data and grantee_data are both objects like:
// {
// type: (account|cos|dl|domain),
// identifier: (name or zimbraId)
// }
grantRight
(
target_data
,
grantee_data
,
right_name
,
callback
)
{
const
request_data
=
{
};
request_data
.
params
=
this
.
requestParams
();
request_data
.
request_name
=
'GrantRight'
;
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
;
if
(
target_data
)
request_data
.
params
.
params
.
target
=
{
'type'
:
target_data
.
type
,
'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
};
this
.
performRequest
(
request_data
);
}
// Specific functions
// Specific functions
addAccountAlias
(
account_id
,
alias
,
callback
)
{
addAccountAlias
(
account_id
,
alias
,
callback
)
{
...
...
src/zimbra/distribution_list.js
View file @
b82a9d11
...
@@ -14,6 +14,28 @@ export default class DistributionList extends Zimbra {
...
@@ -14,6 +14,28 @@ export default class DistributionList extends Zimbra {
this
.
api
.
addDistributionListMember
(
this
.
id
,
members
,
callback
);
this
.
api
.
addDistributionListMember
(
this
.
id
,
members
,
callback
);
}
}
// 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
);
});
}
parseMembers
(
obj
)
{
parseMembers
(
obj
)
{
let
members
=
[];
let
members
=
[];
if
(
obj
.
dlm
)
{
if
(
obj
.
dlm
)
{
...
...
src/zimbra/grant.js
View file @
b82a9d11
...
@@ -15,4 +15,9 @@ export default class Grant {
...
@@ -15,4 +15,9 @@ export default class Grant {
return
false
;
return
false
;
}
}
isDistributionListOwnerGrant
()
{
if
(
this
.
rightName
===
'sendToDistList'
)
return
true
;
return
false
;
}
}
}
src/zimbra/zimbra.js
View file @
b82a9d11
...
@@ -23,4 +23,14 @@ export default class Zimbra {
...
@@ -23,4 +23,14 @@ export default class Zimbra {
return
attrs
;
return
attrs
;
}
}
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
]};
});
return
grantees
;
}
}
}
test/js/spec/test.js
View file @
b82a9d11
...
@@ -541,6 +541,20 @@
...
@@ -541,6 +541,20 @@
});
});
});
});
it
(
'dl.getOwners should return the DL owners'
,
function
(
done
)
{
let
api
=
new
ZimbraAdminApi
(
auth_data
);
api
.
getDistributionList
(
'restringida@customer.dev'
,
function
(
err
,
data
){
if
(
err
)
console
.
log
(
err
);
const
dl
=
data
;
dl
.
getOwners
(
function
(
err
,
data
){
if
(
err
)
console
.
log
(
err
);
console
.
log
(
data
);
expect
(
data
[
0
].
type
).
to
.
be
.
exist
;
done
();
});
});
});
});
});
describe
(
'Grants tests'
,
function
()
{
describe
(
'Grants tests'
,
function
()
{
...
@@ -560,6 +574,7 @@
...
@@ -560,6 +574,7 @@
let
target_data
=
{
type
:
'domain'
,
identifier
:
'customer.dev'
};
let
target_data
=
{
type
:
'domain'
,
identifier
:
'customer.dev'
};
api
.
getGrants
(
target_data
,
null
,
function
(
err
,
data
){
api
.
getGrants
(
target_data
,
null
,
function
(
err
,
data
){
if
(
err
)
console
.
log
(
err
);
if
(
err
)
console
.
log
(
err
);
console
.
log
(
data
);
expect
(
data
[
0
].
constructor
.
name
).
to
.
equal
(
'Grant'
);
expect
(
data
[
0
].
constructor
.
name
).
to
.
equal
(
'Grant'
);
expect
(
data
[
0
].
right
.
_content
).
to
.
equal
(
"domainAdminRights"
);
expect
(
data
[
0
].
right
.
_content
).
to
.
equal
(
"domainAdminRights"
);
done
();
done
();
...
@@ -575,8 +590,6 @@
...
@@ -575,8 +590,6 @@
done
();
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