Skip to content

Commit fe1af22

Browse files
Fix bug with report creation
1 parent 1f1567e commit fe1af22

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

app/deployments/routes.py

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -91,51 +91,14 @@ def showdeployments():
9191
return render_template("deployments.html", deployments=deployments)
9292

9393

94-
def update_deployments():
95-
issuer = app.settings.iam_url
96-
if not issuer.endswith("/"):
97-
issuer += "/"
98-
99-
subject = session["userid"]
100-
101-
# retrieve deployments from orchestrator
102-
access_token = iam.token["access_token"]
103-
deployments_from_orchestrator = []
104-
try:
105-
deployments_from_orchestrator = app.orchestrator.get_deployments(
106-
access_token, created_by="{}@{}".format(subject, issuer)
107-
)
108-
except Exception as e:
109-
flash("Error retrieving deployment list: \n" + str(e), "warning")
110-
111-
update_deployments_status(deployments_from_orchestrator, subject)
112-
113-
114-
def update_deployments_status(deployments_from_orchestrator, subject):
115-
if not deployments_from_orchestrator:
116-
return
117-
118-
iids = dbhelpers.updatedeploymentsstatus(deployments_from_orchestrator, subject)["iids"]
119-
120-
# retrieve deployments from DB
121-
deployments = dbhelpers.cvdeployments(dbhelpers.get_user_deployments(subject))
122-
for dep in deployments:
123-
newremote = dep.remote
124-
if dep.uuid not in iids:
125-
if dep.remote == 1:
126-
newremote = 0
127-
else:
128-
if dep.remote == 0:
129-
newremote = 1
130-
if dep.remote != newremote:
131-
dbhelpers.update_deployment(dep.uuid, dict(remote=newremote))
132-
133-
13494
@deployments_bp.route("/overview")
13595
@auth.authorized_with_valid_token
13696
def showdeploymentsoverview():
13797
# refresh deployment list
138-
update_deployments()
98+
try:
99+
dbhelpers.update_deployments(session["userid"])
100+
except Exception as e:
101+
flash("Error retrieving deployment list: \n" + str(e), "warning")
139102

140103
deps = dbhelpers.get_user_deployments(session["userid"])
141104
# Initialize dictionaries for status, projects, and providers
@@ -239,7 +202,8 @@ def preprocess_outputs(outputs, stoutputs, inputs):
239202
@auth.authorized_with_valid_token
240203
def depoutput(depid=None):
241204
"""
242-
A function to render the details of a deployment, including inputs, outputs, and structured outputs.
205+
A function to render the details of a deployment, including inputs, outputs,
206+
and structured outputs.
243207
Parameters:
244208
- depid: str, the ID of the deployment
245209
Returns:

app/home/routes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ def home():
357357

358358

359359
@home_bp.route("/portfolio")
360+
@auth.authorized_with_valid_token
360361
def portfolio():
361362
"""
362363
A route function for the "/portfolio" endpoint.
@@ -366,6 +367,11 @@ def portfolio():
366367
and renders the portfolio template with the retrieved data.
367368
If the user is not logged in, it redirects to the login page.
368369
"""
370+
try:
371+
dbhelpers.update_deployments(session["userid"])
372+
except Exception as e:
373+
flash("Error retrieving deployment list: \n" + str(e), "warning")
374+
369375
deps = dbhelpers.get_user_deployments(session["userid"])
370376
statuses = {}
371377
for dep in deps:

app/lib/dbhelpers.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def updatedeploymentsstatus(deployments, userid):
9696
result = {}
9797
deps = []
9898
iids = []
99-
# uuid = ''
10099

101100
# update deployments status in database
102101
for dep_json in deployments:
@@ -268,6 +267,42 @@ def cvdeployment(d):
268267
return deployment
269268

270269

270+
def update_deployments(subject):
271+
issuer = app.settings.iam_url
272+
if not issuer.endswith("/"):
273+
issuer += "/"
274+
275+
# retrieve deployments from orchestrator
276+
access_token = iam.token["access_token"]
277+
deployments_from_orchestrator = []
278+
279+
deployments_from_orchestrator = app.orchestrator.get_deployments(
280+
access_token, created_by="{}@{}".format(subject, issuer)
281+
)
282+
283+
update_deployments_status(deployments_from_orchestrator, subject)
284+
285+
286+
def update_deployments_status(deployments_from_orchestrator, subject):
287+
if not deployments_from_orchestrator:
288+
return
289+
290+
iids = updatedeploymentsstatus(deployments_from_orchestrator, subject)["iids"]
291+
292+
# retrieve deployments from DB
293+
deployments = cvdeployments(get_user_deployments(subject))
294+
for dep in deployments:
295+
newremote = dep.remote
296+
if dep.uuid not in iids:
297+
if dep.remote == 1:
298+
newremote = 0
299+
else:
300+
if dep.remote == 0:
301+
newremote = 1
302+
if dep.remote != newremote:
303+
update_deployment(dep.uuid, dict(remote=newremote))
304+
305+
271306
def get_services(visibility, groups=[]):
272307
services = []
273308
if visibility == "public":

0 commit comments

Comments
 (0)