Fix unapproved packages appearing in collections

This commit is contained in:
rubenwardy
2023-08-16 01:00:51 +01:00
parent f470357a42
commit ea2f1f4f6f
5 changed files with 21 additions and 8 deletions

View File

@@ -645,14 +645,17 @@ class Package(db.Model):
return None
def check_perm(self, user, perm):
if not user.is_authenticated:
return False
if type(perm) == str:
perm = Permission[perm]
elif type(perm) != Permission:
raise Exception("Unknown permission given to Package.check_perm()")
if perm == Permission.VIEW_PACKAGE:
return self.state == PackageState.APPROVED or self.check_perm(user, Permission.EDIT_PACKAGE)
if not user.is_authenticated:
return False
is_owner = user == self.author
is_maintainer = is_owner or user.rank.at_least(UserRank.EDITOR) or user in self.maintainers
is_approver = user.rank.at_least(UserRank.APPROVER)

View File

@@ -59,6 +59,7 @@ class UserRank(enum.Enum):
class Permission(enum.Enum):
VIEW_PACKAGE = "VIEW_PACKAGE"
EDIT_PACKAGE = "EDIT_PACKAGE"
DELETE_PACKAGE = "DELETE_PACKAGE"
CHANGE_AUTHOR = "CHANGE_AUTHOR"