Skip to content

Commit

Permalink
Add unique release name check
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Oct 28, 2024
1 parent 2ff11de commit a5ac4f3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/logic/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from app.utils import AuditSeverity, add_audit_log, nonempty_or_none, normalize_line_endings


def check_can_create_release(user: User, package: Package):
def check_can_create_release(user: User, package: Package, name: str):
if not package.check_perm(user, Permission.MAKE_RELEASE):
raise LogicError(403, lazy_gettext("You don't have permission to make releases"))

Expand All @@ -37,10 +37,13 @@ def check_can_create_release(user: User, package: Package):
if count >= 5:
raise LogicError(429, lazy_gettext("You've created too many releases for this package in the last 5 minutes, please wait before trying again"))

if PackageRelease.query.filter_by(package_id=package.id, name=name).count() > 0:
raise LogicError(403, lazy_gettext("A release with this name already exists"))


def do_create_vcs_release(user: User, package: Package, name: str, title: Optional[str], release_notes: Optional[str], ref: str,
min_v: MinetestRelease = None, max_v: MinetestRelease = None, reason: str = None):
check_can_create_release(user, package)
check_can_create_release(user, package, name)

rel = PackageRelease()
rel.package = package
Expand Down Expand Up @@ -69,7 +72,7 @@ def do_create_vcs_release(user: User, package: Package, name: str, title: Option
def do_create_zip_release(user: User, package: Package, name: str, title: Optional[str], release_notes: Optional[str], file,
min_v: MinetestRelease = None, max_v: MinetestRelease = None, reason: str = None,
commit_hash: str = None):
check_can_create_release(user, package)
check_can_create_release(user, package, name)

if commit_hash:
commit_hash = commit_hash.lower()
Expand Down

0 comments on commit a5ac4f3

Please sign in to comment.