From fec1f21ca43408dd25348d8332dcf67082cf4111 Mon Sep 17 00:00:00 2001 From: Benjamin Adams Date: Mon, 6 Jan 2025 13:32:40 -0500 Subject: [PATCH] Fix foreign key linkage for deployment user's username --- glider_dac/templates/deployment_registration.txt | 2 +- glider_dac/tests/test_email.py | 2 +- glider_dac/views/deployment.py | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/glider_dac/templates/deployment_registration.txt b/glider_dac/templates/deployment_registration.txt index e9ba52a..0c3e8f6 100644 --- a/glider_dac/templates/deployment_registration.txt +++ b/glider_dac/templates/deployment_registration.txt @@ -1,4 +1,4 @@ -A new Glider Deployment ({{ deployment.username }} / {{ deployment.name }}) has been created. +A new Glider Deployment ({{ deployment.user.username }} / {{ deployment.name }}) has been created. DeploymentInfo: DEPLOYMENT URL: {{ url_for('deployment.show_deployment', username=username, deployment_name=deployment.name, _external=True) }} diff --git a/glider_dac/tests/test_email.py b/glider_dac/tests/test_email.py index 7d4fd23..d757bff 100644 --- a/glider_dac/tests/test_email.py +++ b/glider_dac/tests/test_email.py @@ -45,7 +45,7 @@ def client(): @patch("glider_dac.services.emails") def test_email_exception(client, deployment, caplog, monkeypatch): app = create_app() - username = deployment.username + username = deployment.user.username with app.app_context(): app.config["MAIL_ENABLED"] = True def smtp_error_raiser(message): diff --git a/glider_dac/views/deployment.py b/glider_dac/views/deployment.py index 5962169..c87386e 100644 --- a/glider_dac/views/deployment.py +++ b/glider_dac/views/deployment.py @@ -125,7 +125,7 @@ def show_deployment(deployment_name): current_user == deployment.user)): kwargs['editable'] = True if current_user.is_authenticated and (current_user.admin or - current_user.username == deployment.username): + current_user.username == deployment.user.username): kwargs['admin'] = True current_app.logger.info(deployment.dap) @@ -179,7 +179,7 @@ def new_deployment(username): # the deployment normally. deployment = Deployment() deployment.user = user - deployment.username = username + deployment.user.username = username deployment.deployment_dir = os.path.join(username, deployment_name) deployment.updated = datetime.utcnow() deployment.deployment_date = deployment_date @@ -191,7 +191,7 @@ def new_deployment(username): db.session.commit() deployment.sync() flash("Deployment created", 'success') - send_registration_email(deployment.username, deployment) + send_registration_email(deployment.user.username, deployment) # TODO: handle prior to creation #except DuplicateKeyError: except Exception as e: @@ -237,7 +237,7 @@ def new_delayed_mode_deployment(username, deployment_name): deployment = Deployment() deployment.name = rt_deployment.name + '-delayed' #deployment.user_id = user.user_id - deployment.username = username + deployment.user.username = username deployment.operator = rt_deployment.operator deployment.deployment_dir = os.path.join(username, deployment_name) deployment.wmo_id = rt_deployment.wmo_id @@ -249,7 +249,7 @@ def new_delayed_mode_deployment(username, deployment_name): db.session.add(deployment) db.session.commit() flash("Deployment created", 'success') - send_registration_email(deployment.username, deployment) + send_registration_email(deployment.user.username, deployment) return redirect(url_for('deployment.list_user_deployments', username=username)) @@ -289,7 +289,7 @@ def post_deployment_file(username, deployment_name): deployment = Deployment.query.filter_by(name=deployment_name).one_or_none() user = User.query.filter_by(username=username).one_or_none() - if not (deployment and user and deployment.username == user.username and + if not (deployment and user and deployment.user.username == user.username and (current_user.admin or current_user == user)): raise Exception("Unauthorized") # @TODO better response via ajax?