-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathapi.transfer.js
More file actions
121 lines (110 loc) · 5.78 KB
/
api.transfer.js
File metadata and controls
121 lines (110 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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();
});
};