diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d514a864a7ae809ecc5e35a443d268bcc46c8905..72015c5dd4a26e316c4c9e4d6df4f645ff3ff39f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ Fixed * Progress page didn't work properly. * About page failed to load for apps with an unknown licence. +* Notification query failed on admin users without persons. `3.1`_ - 2022-05-30 ------------------- diff --git a/aleksis/core/schema/person.py b/aleksis/core/schema/person.py index 6eed201487348034b2d9b1cba616046b1794dbf2..bf2229545850b088409defde34ced90bc658f7c1 100644 --- a/aleksis/core/schema/person.py +++ b/aleksis/core/schema/person.py @@ -62,7 +62,7 @@ class PersonType(DjangoObjectType): secondary_image_url = graphene.String() notifications = graphene.List(NotificationType) - unread_notifications_count = graphene.Int() + unread_notifications_count = graphene.Int(required=False) is_dummy = graphene.Boolean() preferences = graphene.Field(PersonPreferencesType) @@ -150,7 +150,11 @@ class PersonType(DjangoObjectType): return root.user.id if root.user else None def resolve_unread_notifications_count(root, info, **kwargs): # noqa - return root.unread_notifications_count + if root.pk and has_person(info.context) and root == info.context.user.person: + return root.unread_notifications_count + elif root.pk: + return 0 + return None def resolve_photo(root, info, **kwargs): if info.context.user.has_perm("core.view_photo_rule", root): @@ -199,11 +203,11 @@ class PersonType(DjangoObjectType): return root.is_dummy if hasattr(root, "is_dummy") else False def resolve_notifications(root: Person, info, **kwargs): - if has_person(info.context.user) and info.context.user.person == root: + if root.pk and has_person(info.context) and root == info.context.user.person: return root.notifications.filter(send_at__lte=timezone.now()).order_by( "read", "-created" ) - raise PermissionDenied() + return [] def resolve_can_edit_person(root, info, **kwargs): # noqa return info.context.user.has_perm("core.edit_person_rule", root)