diff --git a/LDlink/LDlink.py b/LDlink/LDlink.py index 9571b629..03e1f8a3 100755 --- a/LDlink/LDlink.py +++ b/LDlink/LDlink.py @@ -32,7 +32,7 @@ from LDassoc import calculate_assoc from SNPclip import calculate_clip from SNPchip import calculate_chip, get_platform_request -from RegisterAPI import register_user, checkToken, checkBlocked, checkLocked, toggleLocked, logAccess, emailJustification, blockUser, unblockUser, getToken, getStats, unlockUser, unlockAllUsers, getLockedUsers, getBlockedUsers +from RegisterAPI import register_user, checkToken, checkBlocked, checkLocked, toggleLocked, logAccess, emailJustification, blockUser, unblockUser, getToken, getStats, setUserLock, unlockAllUsers, getLockedUsers, getBlockedUsers from werkzeug.utils import secure_filename from werkzeug.debug import DebuggedApplication @@ -236,12 +236,13 @@ def unblock_user(): return sendJSON(out_json) # Web route to unlock user's API token -@app.route('/LDlinkRestWeb/apiaccess/unlock_user', methods=['GET']) +@app.route('/LDlinkRestWeb/apiaccess/set_user_lock', methods=['GET']) @requires_admin_token -def unlock_user(): +def set_user_lock(): print("Execute api unlock user") email = request.args.get('email', False) - out_json = unlockUser(email) + lockValue = request.args.get('locked', False) + out_json = setUserLock(email, lockValue) return sendJSON(out_json) # Web route to unlock all users API tokens diff --git a/LDlink/RegisterAPI.py b/LDlink/RegisterAPI.py index 343c31ee..23295832 100644 --- a/LDlink/RegisterAPI.py +++ b/LDlink/RegisterAPI.py @@ -238,7 +238,7 @@ def unblockUser(email): return out_json # sets locked attribute of user to 0=false -def unlockUser(email): +def setUserLock(email, lockValue): with open('config.yml', 'r') as f: config = yaml.load(f) env = config['env'] @@ -248,7 +248,7 @@ def unlockUser(email): mongo_port = config['database']['mongo_port'] out_json = { - "message": "Email user (" + email + ")'s token access has been unlocked." + "message": "Email user (" + email + ")'s token access lock has been set to " + lockValue } if env == 'local': mongo_host = api_mongo_addr @@ -257,14 +257,8 @@ def unlockUser(email): client = MongoClient('mongodb://' + mongo_username + ':' + mongo_password + '@' + mongo_host + '/LDLink', mongo_port) db = client["LDLink"] users = db.api_users - record = users.find_one({"email": email}) + users.find_one_and_update({"email": email}, { "$set": {"locked": lockValue}}) - if record["locked"] == -1: - out_json = { - "message": "Email user (" + email + ") has concurrent access." - } - else: - users.find_one_and_update({"email": email}, { "$set": {"locked": 0}}) return out_json # sets locked attribute of all users to 0=false