Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of the module "Transfer" #51

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
121 changes: 121 additions & 0 deletions lib/api.transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*!
* 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');

var TransferConstants = require('oae-transfer/lib/constants').TransferConstants;


////////////////////
// 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 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
*/
var initiateTransfer = module.exports.initiateTransfer = function(restCtx, originalUserId, originalEmail, targetEmail, callback) {
var params = {
'originalUserId': originalUserId,
'originalEmail': originalEmail,
'targetEmail': targetEmail
};

RestUtil.RestRequest(restCtx, '/api/transfer', '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 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
*/
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);
}
return callback(null, 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 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
*/
var completeTransfer = module.exports.completeTransfer = function(restCtx, originalEmail, code, targetEmail, targetUserId, callback) {
var params = {
'originalEmail': originalEmail,
'code': code,
'targetEmail': targetEmail,
'status': TransferConstants.status.COMPLETED
};

RestUtil.RestRequest(restCtx, '/api/transfer/' + targetUserId, 'put', params, function(err, managers) {
if (err) {
return callback(err);
}
return callback(null, managers);
});
};

/**
* 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 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(restCtx, originalEmail, code, originalUserId, callback) {
var params = {
'originalEmail': originalEmail,
'code': code,
'originalUserId': originalUserId,
'status': TransferConstants.status.CANCELED
};

RestUtil.RestRequest(restCtx, '/api/transfer/' + originalUserId, 'put', params, function(err) {
if (err) {
return callback(err);
}
return callback();
});
};