Fix unapproved packages appearing in collections
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user