Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications: show them based on permissions #11117

Merged
merged 5 commits into from Feb 19, 2024

Conversation

humitos
Copy link
Member

@humitos humitos commented Feb 14, 2024

Expand .for_user() to accept resource= parameter and return only the notifications attached to that resource only if the user has permissions over it. Otherwise, return an empty queryset.

Closes #11082
Closes #11113

Expand `.for_user()` to accept `resource=` parameter and return only the
notifications attached to that resource only if the user has permissions over
it. Otherwise, return an empty queryset.

Closes #11082
Related #11113
Comment on lines +70 to +73
context["notifications"] = Notification.objects.for_user(
self.request.user,
resource=org,
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does something like org.notifications.for_user(...) not work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it works, but we still need to pass resource=org anyways, right? Otherwise, we would need to add more complexity in the underlying .for_user() queryset method I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when using the manager that way, you don't need to pass resource, since the queryset will be filtered already.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a solid change 👍

considering permissions (e.g. does not return any notification if the ``user``
doesn't have admin permissions on the ``resource``).

If ``resource="all"``, it returns the following notifications:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if resource is None? If it just returns none(), it should probably be a required field, or default to all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it returns an empty queryset. I don't remember why I made this decision 🤔 (maybe because I was already sick 🙃 ), but I think it makes more sense to make it a required argument, yeah.

@humitos humitos merged commit e875fdb into main Feb 19, 2024
4 of 5 checks passed
@humitos humitos deleted the humitos/show-notifications-based-on-user-permissions branch February 19, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notifications: filter out cancelled and dismissed from templates
4 participants