Skip to content

Commit

Permalink
Log idp on login. Start on handling rename of package involved in col…
Browse files Browse the repository at this point in the history
…laboration.
  • Loading branch information
jon-ide committed Jul 3, 2024
1 parent d591f29 commit 0980916
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 4 additions & 1 deletion webapp/auth/user_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Helper functions for accessing data regarding the current user.
"""

from datetime import datetime
import json
import os
import os.path
Expand Down Expand Up @@ -111,7 +112,7 @@ def get_user_document_list(current_user_directory_only=True):
return packageids


def initialize_user_data(cname, uid, auth_token):
def initialize_user_data(cname, idp, uid, auth_token):
user_folder_name = get_user_folder_name(current_user_directory_only=True)
user_uploads_folder_name = get_user_uploads_folder_name()
if not os.path.exists(Config.USER_DATA_DIR):
Expand All @@ -125,7 +126,9 @@ def initialize_user_data(cname, uid, auth_token):
os.mkdir(user_uploads_folder_name)
user_properties = get_user_properties()
user_properties['cname'] = cname
user_properties['idp'] = idp
user_properties['uid'] = uid
user_properties['datetime'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
user_properties['auth_token'] = auth_token
save_user_properties(user_properties)

Expand Down
13 changes: 3 additions & 10 deletions webapp/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def login():
session_id = cname + "*" + pasta_token.uid
user = User(session_id)
login_user(user)
initialize_user_data(cname, pasta_token.uid, auth_token)
initialize_user_data(cname, 'LDAP', pasta_token.uid, auth_token)
log_usage(actions['LOGIN'], cname, 'LDAP', current_user.get_user_login())
next_page = request.args.get('next')
if not next_page or urlparse(next_page).netloc != '':
Expand All @@ -112,20 +112,13 @@ def login():
# log_info(f"cname: {cname}")
if auth_token is not None and cname is not None:
pasta_token = PastaToken(auth_token)
username = ''
# decoded_bytes = base64.b64decode(auth_token)
# decoded_str = decoded_bytes.decode("utf-8")
# try:
# username = decoded_str.split("-")[0].split('*')[0]
# except:
# username = ''
uid = pasta_token.uid
log_info(f"uid: {uid}")
session_id = cname + "*" + uid
user = User(session_id)
login_user(user)
initialize_user_data(cname, pasta_token.uid, auth_token)
log_usage(actions['LOGIN'], cname, idp, username, current_user.get_user_login())
initialize_user_data(cname, idp, uid, auth_token)
log_usage(actions['LOGIN'], cname, idp, uid, current_user.get_user_login())
next_page = request.args.get('next')
if not next_page or urlparse(next_page).netloc != '':
current_document = get_active_document()
Expand Down
4 changes: 4 additions & 0 deletions webapp/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,10 @@ def move_files(from_package, to_package):
eml_node = load_eml(filename=new_document)
fixup_distribution_urls(eml_node)
save_both_formats(filename=new_document, eml_node=eml_node)
# Rename the package in the collaborations database. It is assumed that if we got here, we've already
# established that the current user is the owner of the document.
user_login = current_user.get_user_org()
# collaborations.rename_package(user_login, current_document, new_document)
# Delete the old package
user_data.delete_package(current_document)

Expand Down
10 changes: 10 additions & 0 deletions webapp/views/collaborations/collaborations.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ def _add_lock(package_id, locked_by, session=None):
return lock


def rename_package(owner_login, old_package_name, new_package_name, session=None):
"""
Rename a package by updating the package name in the package record.
"""
with db_session(session) as session:
package = get_package(owner_login, old_package_name, session)
if package:
package.package_name = new_package_name


def remove_package(owner_login, package_name, session=None):
"""
To be called when a package is deleted. Removes all records associated with the package.
Expand Down

0 comments on commit 0980916

Please sign in to comment.