From b61fa5d7e05a19794ff9957bdf78052294041d12 Mon Sep 17 00:00:00 2001 From: Claire Lozano Date: Fri, 23 Mar 2018 14:34:26 +0100 Subject: [PATCH 1/4] transfer - add rest transfer --- lib/api.js | 1 + lib/api.transfer.js | 118 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 lib/api.transfer.js diff --git a/lib/api.js b/lib/api.js index 5b54831..def1ef4 100644 --- a/lib/api.js +++ b/lib/api.js @@ -46,6 +46,7 @@ module.exports.Previews = require('./api.previews'); module.exports.Search = require('./api.search'); module.exports.Telemetry = require('./api.telemetry'); module.exports.Tenants = require('./api.tenants'); +module.exports.Transfer = require('./api.transfer'); module.exports.UI = require('./api.ui'); module.exports.User = require('./api.user'); module.exports.Uservoice = require('./api.uservoice'); diff --git a/lib/api.transfer.js b/lib/api.transfer.js new file mode 100644 index 0000000..c7470dc --- /dev/null +++ b/lib/api.transfer.js @@ -0,0 +1,118 @@ +/*! + * Copyright 2017 Apereo Foundation (AF) Licensed under the + * Educational Community License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may + * obtain a copy of the License at + * + * http://opensource.org/licenses/ECL-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +var RestUtil = require('./util'); + + +//////////////////// +// TRANSFER // +//////////////////// + +/** + * Create a transfer. + * + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalEmail The user email + * @param {String} targetEmail The new email + * @param {String} originalUserId The id of the user who create the transfer + * @param {Function} callback Standard callback function + * @param {Object} callback.err An error that occurred, if any + * @param {Transfer} callback.transfer The transfer that was created + */ +var createTransfer = module.exports.createTransfer = function(RestContext, originalUserId, originalEmail, targetEmail, callback) { + var params = { + 'originalUserId': originalUserId, + 'originalEmail': originalEmail, + 'targetEmail': targetEmail + }; + + RestUtil.RestRequest(RestContext, '/api/transfer/create', 'post', params, function(err, transfer) { + if (err) { + return callback(err); + } + return callback(null, transfer); + }); +}; + +/** + * Get a transfer by Id. + * + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalUserId The id of the user who created the transfer + * @param {Function} callback Standard callback function + * @param {Object} callback.err An error that occurred, if any + * @param {Transfer} callback.transfer The transfer that was created + */ +var getTransferById = module.exports.getTransferById = function(RestContext, originalUserId, callback) { + RestUtil.RestRequest(RestContext, '/api/transfer/getTransferById/'+ RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) { + if (err) { + return callback(err); + } + return callback(null, transfer); + }); +}; + +/** + * Make a transfer. + * + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalEmail The user email + * @param {String} code The generated code + * @param {String} targetEmail The new email + * @param {String} targetUserId The id new user + * @param {Function} callback Standard callback function + * @param {Object} callback.err An error that occurred, if any + * @param {Transfer} callback.transfer The transfer that was created + */ +var makeTransfer = module.exports.makeTransfer = function(RestContext, originalEmail, code, targetEmail, targetUserId, callback) { + var params = { + 'originalEmail': originalEmail, + 'code': code, + 'targetEmail': targetEmail, + 'targetUserId': targetUserId + }; + + RestUtil.RestRequest(RestContext, '/api/transfer/makeTransfer', 'post', params, function(err, managers) { + if (err) { + return callback(err); + } + return callback(null, managers); + }); +}; + +/** + * Delete a transfer. + * + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalEmail The user email + * @param {String} code The generated code + * @param {String} originalUserId The id user + * @param {Function} callback Standard callback function + * @param {Object} callback.err An error that occurred, if any + * @param {Transfer} callback.transfer The transfer that was created + */ +var deleteTransfer = module.exports.deleteTransfer = function(RestContext, originalEmail, code, originalUserId, callback) { + var params = { + 'originalEmail': originalEmail, + 'code': code, + 'originalUserId': originalUserId + }; + + RestUtil.RestRequest(RestContext, '/api/transfer/deleteTransfer', 'POST', params, function(err) { + if (err) { + } + return callback(null); + }); +}; From 89f787fcec2c124d1d7a306ceea4ed21a9490713 Mon Sep 17 00:00:00 2001 From: Claire Lozano Date: Wed, 18 Apr 2018 10:04:36 +0200 Subject: [PATCH 2/4] Route ok --- lib/api.transfer.js | 63 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/lib/api.transfer.js b/lib/api.transfer.js index c7470dc..30c3128 100644 --- a/lib/api.transfer.js +++ b/lib/api.transfer.js @@ -15,30 +15,32 @@ var RestUtil = require('./util'); +var TransferConstants = require('oae-transfer/lib/constants').TransferConstants; + //////////////////// // TRANSFER // //////////////////// /** - * Create a transfer. + * Initiate a transfer. * - * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. - * @param {String} originalEmail The user email - * @param {String} targetEmail The new email - * @param {String} originalUserId The id of the user who create the transfer + * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalEmail The email of the account from which the data will be transferred + * @param {String} targetEmail The email of the account to which the data will be transferred + * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any * @param {Transfer} callback.transfer The transfer that was created */ -var createTransfer = module.exports.createTransfer = function(RestContext, originalUserId, originalEmail, targetEmail, callback) { +var initiateTransfer = module.exports.initiateTransfer = function(RestContext, originalUserId, originalEmail, targetEmail, callback) { var params = { 'originalUserId': originalUserId, 'originalEmail': originalEmail, 'targetEmail': targetEmail }; - RestUtil.RestRequest(RestContext, '/api/transfer/create', 'post', params, function(err, transfer) { + RestUtil.RestRequest(RestContext, '/api/transfer', 'post', params, function(err, transfer) { if (err) { return callback(err); } @@ -49,14 +51,14 @@ var createTransfer = module.exports.createTransfer = function(RestContext, origi /** * Get a transfer by Id. * - * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. - * @param {String} originalUserId The id of the user who created the transfer + * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any * @param {Transfer} callback.transfer The transfer that was created */ var getTransferById = module.exports.getTransferById = function(RestContext, originalUserId, callback) { - RestUtil.RestRequest(RestContext, '/api/transfer/getTransferById/'+ RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) { + RestUtil.RestRequest(RestContext, '/api/transfer/' + RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) { if (err) { return callback(err); } @@ -65,26 +67,26 @@ var getTransferById = module.exports.getTransferById = function(RestContext, ori }; /** - * Make a transfer. + * Complete a transfer. * - * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. - * @param {String} originalEmail The user email - * @param {String} code The generated code - * @param {String} targetEmail The new email - * @param {String} targetUserId The id new user + * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalEmail The email of the account from which the data will be transferred + * @param {String} code The code used by the user to secure the transfer + * @param {String} targetEmail The email of the account to which the data will be transferred + * @param {String} targetUserId The identifier of the account to which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any * @param {Transfer} callback.transfer The transfer that was created */ -var makeTransfer = module.exports.makeTransfer = function(RestContext, originalEmail, code, targetEmail, targetUserId, callback) { +var completeTransfer = module.exports.completeTransfer = function(RestContext, originalEmail, code, targetEmail, targetUserId, callback) { var params = { 'originalEmail': originalEmail, 'code': code, 'targetEmail': targetEmail, - 'targetUserId': targetUserId + 'status': TransferConstants.status.COMPLETED }; - RestUtil.RestRequest(RestContext, '/api/transfer/makeTransfer', 'post', params, function(err, managers) { + RestUtil.RestRequest(RestContext, '/api/transfer/' + targetUserId, 'put', params, function(err, managers) { if (err) { return callback(err); } @@ -93,26 +95,27 @@ var makeTransfer = module.exports.makeTransfer = function(RestContext, originalE }; /** - * Delete a transfer. + * Cancel a transfer. * - * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. - * @param {String} originalEmail The user email - * @param {String} code The generated code - * @param {String} originalUserId The id user + * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {String} originalEmail The email of the account from which the data will be transferred + * @param {String} code The code used by the user to secure the transfer + * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any - * @param {Transfer} callback.transfer The transfer that was created */ -var deleteTransfer = module.exports.deleteTransfer = function(RestContext, originalEmail, code, originalUserId, callback) { +var cancelTransfer = module.exports.cancelTransfer = function(RestContext, originalEmail, code, originalUserId, callback) { var params = { 'originalEmail': originalEmail, 'code': code, - 'originalUserId': originalUserId + 'originalUserId': originalUserId, + 'status': TransferConstants.status.CANCELED }; - - RestUtil.RestRequest(RestContext, '/api/transfer/deleteTransfer', 'POST', params, function(err) { + + RestUtil.RestRequest(RestContext, '/api/transfer/' + originalUserId, 'put', params, function(err) { if (err) { + return callback(err); } - return callback(null); + return callback(); }); }; From 5e117d40ad679ede11d78cb52a77761ee750db87 Mon Sep 17 00:00:00 2001 From: Claire Lozano Date: Fri, 20 Jul 2018 09:58:50 +0200 Subject: [PATCH 3/4] transfer - {transfer} -> {Object} --- lib/api.transfer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/api.transfer.js b/lib/api.transfer.js index 30c3128..f818d69 100644 --- a/lib/api.transfer.js +++ b/lib/api.transfer.js @@ -31,7 +31,7 @@ var TransferConstants = require('oae-transfer/lib/constants').TransferConstants; * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any - * @param {Transfer} callback.transfer The transfer that was created + * @param {Object} callback.transfer The transfer that was created */ var initiateTransfer = module.exports.initiateTransfer = function(RestContext, originalUserId, originalEmail, targetEmail, callback) { var params = { @@ -55,7 +55,7 @@ var initiateTransfer = module.exports.initiateTransfer = function(RestContext, o * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any - * @param {Transfer} callback.transfer The transfer that was created + * @param {Object} callback.transfer The transfer that was created */ var getTransferById = module.exports.getTransferById = function(RestContext, originalUserId, callback) { RestUtil.RestRequest(RestContext, '/api/transfer/' + RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) { @@ -76,7 +76,7 @@ var getTransferById = module.exports.getTransferById = function(RestContext, ori * @param {String} targetUserId The identifier of the account to which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any - * @param {Transfer} callback.transfer The transfer that was created + * @param {Object} callback.transfer The transfer that was created */ var completeTransfer = module.exports.completeTransfer = function(RestContext, originalEmail, code, targetEmail, targetUserId, callback) { var params = { From 8b47f2662fd48864b4ecbeea5a0248f072b0b984 Mon Sep 17 00:00:00 2001 From: Claire Lozano Date: Fri, 20 Jul 2018 12:01:50 +0200 Subject: [PATCH 4/4] transfer - comments --- lib/api.transfer.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/api.transfer.js b/lib/api.transfer.js index f818d69..4725a6a 100644 --- a/lib/api.transfer.js +++ b/lib/api.transfer.js @@ -25,22 +25,22 @@ var TransferConstants = require('oae-transfer/lib/constants').TransferConstants; /** * Initiate a transfer. * - * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. * @param {String} originalEmail The email of the account from which the data will be transferred * @param {String} targetEmail The email of the account to which the data will be transferred * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any - * @param {Object} callback.transfer The transfer that was created + * @param {Object} callback.transfer The transfer that was created */ -var initiateTransfer = module.exports.initiateTransfer = function(RestContext, originalUserId, originalEmail, targetEmail, callback) { +var initiateTransfer = module.exports.initiateTransfer = function(restCtx, originalUserId, originalEmail, targetEmail, callback) { var params = { 'originalUserId': originalUserId, 'originalEmail': originalEmail, 'targetEmail': targetEmail }; - RestUtil.RestRequest(RestContext, '/api/transfer', 'post', params, function(err, transfer) { + RestUtil.RestRequest(restCtx, '/api/transfer', 'post', params, function(err, transfer) { if (err) { return callback(err); } @@ -51,14 +51,14 @@ var initiateTransfer = module.exports.initiateTransfer = function(RestContext, o /** * Get a transfer by Id. * - * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any - * @param {Object} callback.transfer The transfer that was created + * @param {Object} callback.transfer The transfer that was created */ -var getTransferById = module.exports.getTransferById = function(RestContext, originalUserId, callback) { - RestUtil.RestRequest(RestContext, '/api/transfer/' + RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) { +var getTransferById = module.exports.getTransferById = function(restCtx, originalUserId, callback) { + RestUtil.RestRequest(restCtx, '/api/transfer/' + RestUtil.encodeURIComponent(originalUserId), 'get', {'originalUserId' : originalUserId} , function(err, transfer) { if (err) { return callback(err); } @@ -69,16 +69,16 @@ var getTransferById = module.exports.getTransferById = function(RestContext, ori /** * Complete a transfer. * - * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. * @param {String} originalEmail The email of the account from which the data will be transferred * @param {String} code The code used by the user to secure the transfer * @param {String} targetEmail The email of the account to which the data will be transferred * @param {String} targetUserId The identifier of the account to which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any - * @param {Object} callback.transfer The transfer that was created + * @param {Object} callback.transfer The transfer that was created */ -var completeTransfer = module.exports.completeTransfer = function(RestContext, originalEmail, code, targetEmail, targetUserId, callback) { +var completeTransfer = module.exports.completeTransfer = function(restCtx, originalEmail, code, targetEmail, targetUserId, callback) { var params = { 'originalEmail': originalEmail, 'code': code, @@ -86,7 +86,7 @@ var completeTransfer = module.exports.completeTransfer = function(RestContext, o 'status': TransferConstants.status.COMPLETED }; - RestUtil.RestRequest(RestContext, '/api/transfer/' + targetUserId, 'put', params, function(err, managers) { + RestUtil.RestRequest(restCtx, '/api/transfer/' + targetUserId, 'put', params, function(err, managers) { if (err) { return callback(err); } @@ -97,14 +97,14 @@ var completeTransfer = module.exports.completeTransfer = function(RestContext, o /** * Cancel a transfer. * - * @param {RestContext} RestContext Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. + * @param {RestContext} restCtx Standard REST Context object that contains the current tenant URL and the current user credentials. In order for this to work, a global admin rest context will need to passed in. * @param {String} originalEmail The email of the account from which the data will be transferred * @param {String} code The code used by the user to secure the transfer * @param {String} originalUserId The account identifier from which the data will be transferred * @param {Function} callback Standard callback function * @param {Object} callback.err An error that occurred, if any */ -var cancelTransfer = module.exports.cancelTransfer = function(RestContext, originalEmail, code, originalUserId, callback) { +var cancelTransfer = module.exports.cancelTransfer = function(restCtx, originalEmail, code, originalUserId, callback) { var params = { 'originalEmail': originalEmail, 'code': code, @@ -112,7 +112,7 @@ var cancelTransfer = module.exports.cancelTransfer = function(RestContext, origi 'status': TransferConstants.status.CANCELED }; - RestUtil.RestRequest(RestContext, '/api/transfer/' + originalUserId, 'put', params, function(err) { + RestUtil.RestRequest(restCtx, '/api/transfer/' + originalUserId, 'put', params, function(err) { if (err) { return callback(err); }