mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-09 22:47:36 +01:00
Fix crash when collection.author is None
This commit is contained in:
parent
18e8a11d00
commit
379337ad60
@ -241,12 +241,14 @@ def delete(author, name):
|
|||||||
def toggle_package(collection: Collection, package: Package):
|
def toggle_package(collection: Collection, package: Package):
|
||||||
severity = AuditSeverity.NORMAL if collection.author == current_user else AuditSeverity.EDITOR
|
severity = AuditSeverity.NORMAL if collection.author == current_user else AuditSeverity.EDITOR
|
||||||
|
|
||||||
|
author = User.query.get(collection.author_id) if collection.author is None else collection.author
|
||||||
|
|
||||||
if package in collection.packages:
|
if package in collection.packages:
|
||||||
CollectionPackage.query \
|
CollectionPackage.query \
|
||||||
.filter(CollectionPackage.collection == collection, CollectionPackage.package == package) \
|
.filter(CollectionPackage.collection == collection, CollectionPackage.package == package) \
|
||||||
.delete(synchronize_session=False)
|
.delete(synchronize_session=False)
|
||||||
add_audit_log(severity, current_user,
|
add_audit_log(severity, current_user,
|
||||||
f"Removed {package.get_id()} from collection {collection.author.username}/{collection.name}",
|
f"Removed {package.get_id()} from collection {author.username}/{collection.name}",
|
||||||
collection.get_url("collections.view"), None)
|
collection.get_url("collections.view"), None)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return False
|
return False
|
||||||
@ -257,7 +259,7 @@ def toggle_package(collection: Collection, package: Package):
|
|||||||
link.order = len(collection.items)
|
link.order = len(collection.items)
|
||||||
db.session.add(link)
|
db.session.add(link)
|
||||||
add_audit_log(severity, current_user,
|
add_audit_log(severity, current_user,
|
||||||
f"Added {package.get_id()} to collection {collection.author.username}/{collection.name}",
|
f"Added {package.get_id()} to collection {author.username}/{collection.name}",
|
||||||
collection.get_url("collections.view"), None)
|
collection.get_url("collections.view"), None)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user