Skip to content
Snippets Groups Projects
Commit 48258c24 authored by Jonathan Weth's avatar Jonathan Weth :keyboard: Committed by magicfelix
Browse files

Fix notifications query with dummy persons

parent 2385a348
No related branches found
No related tags found
1 merge request!1254Resolve "GraphQL error "DummyPerson needs a primary key""
Pipeline #134055 failed
......@@ -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
-------------------
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment