fix(fastapi): utilize auto_{orphan,deletion}_age

Didn't get this in when the initial request port went down;
here it is.

Auto-accept orphan requests when the package has been out of
date for longer than auto_orphan_age.

Auto-accept deletion requests by the package's maintainer
if the package has been uploaded within auto_deletion_age
seconds ago.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-11-18 21:15:57 -08:00
parent a348cdaac3
commit 7f981b9ed7
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
3 changed files with 109 additions and 33 deletions

View file

@ -0,0 +1,34 @@
from typing import Any, Dict
from aurweb import db, models
from aurweb.exceptions import ValidationError
def request(pkgbase: models.PackageBase,
type: str, comments: str, merge_into: str,
context: Dict[str, Any]) -> None:
if not comments:
raise ValidationError(["The comment field must not be empty."])
if type == "merge":
# Perform merge-related checks.
if not merge_into:
# TODO: This error needs to be translated.
raise ValidationError(
['The "Merge into" field must not be empty.'])
target = db.query(models.PackageBase).filter(
models.PackageBase.Name == merge_into
).first()
if not target:
# TODO: This error needs to be translated.
raise ValidationError([
"The package base you want to merge into does not exist."
])
db.refresh(target)
if target.ID == pkgbase.ID:
# TODO: This error needs to be translated.
raise ValidationError([
"You cannot merge a package base into itself."
])