Last active
December 20, 2015 02:29
-
-
Save oevans/6056813 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Also plan to add a function transferAllItemsBatch which will read in a CSV file of username pairs. | |
| def transferAllItems(self, userFrom, userTo): | |
| ''' | |
| REQUIRES ADMIN ACCESS | |
| Transfer ownership of all items in userFrom's account to userTo's account, keeping same folder names. | |
| Note, does not check for existing folders in userTo's account. | |
| ''' | |
| # userFrom is the account where the content currently resides | |
| # userTo is the account where the content will be transferred | |
| ## question: do I need the numbers next to the params, request, etc. variables? | |
| #request User Content for userFrom (contains items in root and all folders) | |
| parameters = urllib.urlencode({'token': self.user.token, 'f': 'json'}) | |
| request = self.user.portalUrl + '/sharing/rest/content/users/' + userFrom + '?' + parameters | |
| userContent = json.loads(urllib.urlopen(request).read()) | |
| #create folders from userFrom's account in userTo's account | |
| for folder in userContent['folders']: | |
| parameters2 = urllib.urlencode({'title' : folder['title'], 'token': self.user.token, 'f': 'json'} | |
| request2 = self.user.portalUrl + 'sharing/rest/content/users/' + userTo + '/createFolder?' + parameters2 | |
| response2 = urllib.urlopen(request2).read() | |
| #change ownership of items in root folder | |
| for item in userContent['items']: | |
| # NEED TO CHECK HOW TO REFERENCE ROOT FOLDER | |
| parameters3 = urllib.urlencode({'targetUsername' : userTo, 'title' : '\\', 'token': self.user.token, 'f': 'json'} | |
| request3 = self.user.portalUrl + 'sharing/rest/content/users/' + fromUser + '/items/' + item['id'] + '/reassign?' + parameters3 | |
| response3 = urllib.urlopen(request3).read() | |
| #change ownership of items in subfolders (loop) | |
| for folder in userContent['folders']: | |
| #request content in current folder | |
| parameters4 = urllib.urlencode({'id' : folder['id'], 'token': self.user.token, 'f': 'json'} | |
| request4 = self.user.portalUrl + 'sharing/rest/content/users/' + userFrom + '?' + parameters4 | |
| folderContent = urllib.urlopen(request4).read() | |
| #change ownership of items in current folder to userTo and put in correct folder | |
| for item in folderContent['items']: | |
| parameters5 = urllib.urlencode({'targetUsername' : userTo, 'targetFoldername' : folder['title'], 'token': self.user.token, 'f': 'json'} | |
| request5 = self.user.portalUrl + 'sharing/rest/content/users/' + userFrom + '/items/' + item['id'] + '/reassign?' + parameters5 | |
| response5 = urllib.urlopen(request5).read() | |
| return ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment