Skip to content

Commit

Permalink
Fix foreign key linkage for deployment user's username
Browse files Browse the repository at this point in the history
  • Loading branch information
benjwadams committed Jan 6, 2025
1 parent c07b39b commit fec1f21
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion glider_dac/templates/deployment_registration.txt
Original file line number Diff line number Diff line change
@@ -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) }}
Expand Down
2 changes: 1 addition & 1 deletion glider_dac/tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions glider_dac/views/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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))

Expand Down Expand Up @@ -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?

Expand Down

0 comments on commit fec1f21

Please sign in to comment.