Skip to content

Commit

Permalink
Accept only one approval per run
Browse files Browse the repository at this point in the history
This change includes:
* fix for multiple approvals that overwrite the approver in the Events
* get the run only once
  • Loading branch information
peregrineshahin authored and ppigazzini committed Aug 18, 2023
1 parent 2fbba41 commit f8c9921
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
19 changes: 12 additions & 7 deletions server/fishtest/rundb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,15 +1316,20 @@ def stop_run(self, run_id):

def approve_run(self, run_id, approver):
run = self.get_run(run_id)
if run is None:
return None, "Run not found!"
# Can't self approve
if run["args"]["username"] == approver:
return False

run["approved"] = True
run["approver"] = approver
self.buffer(run, True)
self.task_time = 0
return True
return None, "Self approval is disabled!"
# Only one approval per run
if not run["approved"]:
run["approved"] = True
run["approver"] = approver
self.buffer(run, True)
self.task_time = 0
return run, "Run approved"
else:
return None, "Run already approved!"

def purge_run(self, run, p=0.001, res=7.0, iters=1):
# Only purge finished runs
Expand Down
15 changes: 6 additions & 9 deletions server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1079,16 +1079,13 @@ def tests_approve(request):
return HTTPFound(location=request.route_url("login"))
username = request.authenticated_userid
run_id = request.POST["run-id"]
if request.rundb.approve_run(run_id, username):
run = request.rundb.get_run(run_id)
update_nets(request, run)
request.actiondb.approve_run(
username=username,
run=run,
)
cached_flash(request, "Approved run")
run, message = request.rundb.approve_run(run_id, username)
if run is None:
request.session.flash(message, "error")
else:
request.session.flash("Unable to approve run!", "error")
update_nets(request, run)
request.actiondb.approve_run(username=username, run=run)
cached_flash(request, message)
return HTTPFound(location=request.route_url("tests"))


Expand Down

0 comments on commit f8c9921

Please sign in to comment.