Commit ea26237e authored by Patricio Bruna's avatar Patricio Bruna

Added account.viewMailPath()

parent 98521286
......@@ -355,6 +355,15 @@ account.removeAccountAlias(alias, callback);
// Empty {} if everything goes Ok
```
### View Mail Path
This return an `URL PATH` to access the account Webmail as an administrator.
The first parameter is the `lifetime` of the Token in seconds.
```javascript
account.viewMailPath(3600, callback);
// /service/preauth?authtoken=0_8c671f3146....&isredirect=1&adminPreAuth=1
```
### Cos Name
The account only has the Id of the Cos, `zimbraCOSId`, but not the name. To get the name you call `zimbraCosName` on the Account:
......
......@@ -354,6 +354,21 @@ return /******/ (function(modules) { // webpackBootstrap
return this.performRequest(request_data);
}
// Return a token for access an account
// {authToken: _TOKEN_, lifetime: _miliseconds_ }
}, {
key: 'delegateAuth',
value: function delegateAuth(account_id, lifetime_seconds, callback) {
var lifetime = lifetime_seconds || 3600;
var request_data = this.buildRequestData('DelegateAuth', callback);
var account = { by: this.dictionary.byIdOrName(account_id), _content: account_id };
request_data.params.params.account = account;
request_data.params.params.duration = lifetime.toString();
request_data.parse_response = _response_parser2.default.delegateAuthResponse;
return this.performRequest(request_data);
}
// Enable Archiving for an Account
// options = {create: (0|1), name: 'archive_account_name', cos: _cos_id, password:}
// Docs: https://files.zimbra.com/docs/soap_api/8.6.0/api-reference/zimbraAdmin/EnableArchive.html
......@@ -13914,6 +13929,16 @@ return /******/ (function(modules) { // webpackBootstrap
value: function addAccountAlias(alias, callback) {
this.api.addAccountAlias(this.id, alias, callback);
}
}, {
key: 'viewMailPath',
value: function viewMailPath(lifetime_seconds, callback) {
this.api.delegateAuth(this.id, lifetime_seconds, function (err, data) {
if (err) return callback(e);
var token = data.authToken;
var path = '/service/preauth?authtoken=' + token + '&isredirect=1&adminPreAuth=1';
return callback(null, path);
});
}
}, {
key: 'cosName',
value: function cosName(callback) {
......@@ -42857,6 +42882,16 @@ return /******/ (function(modules) { // webpackBootstrap
var result = ResponseParser.dictionary().cosesToCountAccountObject(coses);
return callback(null, result);
}
}, {
key: 'delegateAuthResponse',
value: function delegateAuthResponse(data, _, callback) {
var response_object = data.get().DelegateAuthResponse;
var result = {
authToken: response_object.authToken[0]._content,
lifetime: response_object.lifetime
};
return callback(null, result);
}
// For requests that returns empty Object when Success
......@@ -42988,7 +43023,7 @@ return /******/ (function(modules) { // webpackBootstrap
module.exports = {
"name": "zimbra-admin-api-js",
"version": "0.0.26",
"version": "0.0.27",
"private": true,
"main": "lib/zimbra-admin-api.js",
"dependencies": {
This diff is collapsed.
{
"name": "zimbra-admin-api-js",
"version": "0.0.26",
"version": "0.0.27",
"private": true,
"main": "lib/zimbra-admin-api.js",
"dependencies": {
......
......@@ -230,6 +230,18 @@ export default class ZimbraAdminApi {
return this.performRequest(request_data);
}
// Return a token for access an account
// {authToken: _TOKEN_, lifetime: _miliseconds_ }
delegateAuth(account_id, lifetime_seconds, callback) {
const lifetime = lifetime_seconds || 3600;
const request_data = this.buildRequestData('DelegateAuth', callback);
const account = { by: this.dictionary.byIdOrName(account_id), _content: account_id };
request_data.params.params.account = account;
request_data.params.params.duration = lifetime.toString();
request_data.parse_response = ResponseParser.delegateAuthResponse;
return this.performRequest(request_data);
}
// Enable Archiving for an Account
// options = {create: (0|1), name: 'archive_account_name', cos: _cos_id, password:}
// Docs: https://files.zimbra.com/docs/soap_api/8.6.0/api-reference/zimbraAdmin/EnableArchive.html
......
......@@ -33,6 +33,15 @@ export default class ResponseParser {
return callback(null, result);
}
static delegateAuthResponse(data, _, callback) {
const response_object = data.get().DelegateAuthResponse;
const result = {
authToken: response_object.authToken[0]._content,
lifetime: response_object.lifetime
};
return callback(null, result);
}
// For requests that returns empty Object when Success
static emptyResponse(data, request_data, callback){
const response_object = data.get()[request_data.response_name];
......
......@@ -13,6 +13,15 @@ export default class Account extends Zimbra {
this.api.addAccountAlias(this.id, alias, callback);
}
viewMailPath(lifetime_seconds, callback) {
this.api.delegateAuth(this.id, lifetime_seconds, function(err, data){
if (err) return callback(e);
const token = data.authToken;
const path = `/service/preauth?authtoken=${token}&isredirect=1&adminPreAuth=1`
return callback(null, path);
});
}
cosName(callback) {
if (this.attrs.zimbraCOSId) {
this.api.getCos(this.attrs.zimbraCOSId, function(e,d){
......
......@@ -12,6 +12,16 @@
this.timeout(5000);
it('should return the Delegated Token', function(done){
let api = new ZimbraAdminApi(auth_data);
api.delegateAuth('admin', 3672, function(err, data) {
if (err) console.error(err);
expect(data.authToken).to.exist;
expect(data.lifetime).to.equal(3672000);
done();
});
});
it('should get all domains', function(done) {
let api = new ZimbraAdminApi(auth_data);
api.getAllDomains(function(err, data){
......@@ -324,6 +334,18 @@
});
});
it('Should return the viewMailPath', function(done){
let api = new ZimbraAdminApi(auth_data);
api.getAccount('admin@zboxapp.dev', function(err, account){
if (err) return console.error(err);
account.viewMailPath(null, function(err, data){
if (err) return console.log(err);
expect(data).to.match(/adminPreAuth=1$/);
done();
});
});
});
});
......
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