Skip to content

Commit

Permalink
Check for migrated user
Browse files Browse the repository at this point in the history
  • Loading branch information
dyakhnov committed Mar 18, 2021
1 parent 5d2c2f7 commit 47f0c12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mydata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import subprocess
import sys

__version__ = "0.9.5"
__version__ = "0.9.6"


if hasattr(sys, "frozen"):
Expand Down
25 changes: 19 additions & 6 deletions mydata/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,28 @@ def GetUserByUsername(username):
response = requests.get(url=url, headers=SETTINGS.defaultHeaders)
response.raise_for_status()
userRecordsJson = response.json()
numUserRecordsFound = userRecordsJson['meta']['total_count']

if numUserRecordsFound == 0:
raise DoesNotExist(
message="User \"%s\" was not found in MyTardis" % username,
response=response)
if userRecordsJson["meta"]["total_count"] == 0:
"""
Let's check if user has been migrated from LDAP to AAF
"""
url = "%s/api/v1/mydata_user/?username=%s" \
% (SETTINGS.general.myTardisUrl, username)
try:
rsp = requests.get(url=url, headers=SETTINGS.defaultHeaders)
data = rsp.json()
userFound = data["success"]
except:
userFound = False
if userFound:
return UserModel.GetUserByUsername(data["username"])
else:
raise DoesNotExist(
message="User \"%s\" was not found in MyTardis" % username,
response=response)
logger.debug("Found user record for username '" + username + "'.")
return UserModel(username=username,
userRecordJson=userRecordsJson['objects'][0])
userRecordJson=userRecordsJson["objects"][0])

@staticmethod
def GetUserByEmail(email):
Expand Down

0 comments on commit 47f0c12

Please sign in to comment.