-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closes #15621: User notifications #16800
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
Merged
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
865619b
Initial work on #15621
jeremystretch b0e37bc
Signal receiver should ignore models which don't support notifications
jeremystretch 896c174
Flesh out NotificationGroup functionality
jeremystretch a21d4fe
Add NotificationGroup filters for users & groups
jeremystretch 9c87571
Separate read & dimiss actions
jeremystretch 29675d6
Enable one-click dismissals from notifications list
jeremystretch 1c81183
Include total notification count in dropdown
jeremystretch 8065d7c
Drop 'kind' field from Notification model
jeremystretch 8c0693f
Register event types in the registry; add colors & icons
jeremystretch 71860ba
Enable event rules to target notification groups
jeremystretch c22b705
Define dynamic choices for Notification.event_name
jeremystretch f129738
Move event registration to core
jeremystretch ba11e97
Add more job events
jeremystretch 6bec89d
Misc cleanup
jeremystretch cbffc24
Misc cleanup
jeremystretch 9f6ccec
Correct absolute URLs for notifications & subscriptions
jeremystretch 2bc7b20
Optimize subscriber notifications
jeremystretch 1dd5d0a
Use core event types when queuing events
jeremystretch 744d3d8
Standardize queued event attribute to event_type; change content_type…
jeremystretch fa722fe
Rename Notification.event_name to event_type
jeremystretch 0d553ca
Restore NotificationGroupBulkEditView
jeremystretch fdbcd36
Add API tests
jeremystretch 623c012
Add view & filterset tests
jeremystretch f82de2b
Merge branch 'feature' into 15621-notifications
jeremystretch 1e57915
Add model documentation
jeremystretch 5131cc9
Fix tests
jeremystretch 4f0cc95
Update notification bell when notifications have been cleared
jeremystretch aa8a891
Ensure subscribe button appears only on relevant models
jeremystretch 854b745
Notifications/subscriptions cannot be ordered by object
jeremystretch b94cb88
Misc cleanup
jeremystretch 2f2e273
Add event icon & type to notifications table
jeremystretch bfd0fa4
Adjust icon sizing
jeremystretch 9fc0c83
Mute color of read notifications
jeremystretch 7856da4
Misc cleanup
jeremystretch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Notification | ||
|
||
A notification alerts a user that a specific action has taken place in NetBox, such as an object being modified or a background job completing. A notification may be generated via a user's [subscription](./subscription.md) to a particular object, or by an event rule targeting a [notification group](./notificationgroup.md) of which the user is a member. | ||
|
||
## Fields | ||
|
||
### User | ||
|
||
The recipient of the notification. | ||
|
||
### Object | ||
|
||
The object to which the notification relates. | ||
|
||
### Event Type | ||
|
||
The type of event indicated by the notification. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Notification Group | ||
|
||
A set of NetBox users and/or groups of users identified as recipients for certain [notifications](./notification.md). | ||
|
||
## Fields | ||
|
||
### Name | ||
|
||
The name of the notification group. | ||
|
||
### Users | ||
|
||
One or more users directly designated as members of the notification group. | ||
|
||
### Groups | ||
|
||
All users of any selected groups are considered as members of the notification group. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Subscription | ||
|
||
A record indicating that a user is to be notified of any changes to a particular NetBox object. A notification maps exactly one user to exactly one object. | ||
|
||
When an object to which a user is subscribed changes, a [notification](./notification.md) is generated for the user. | ||
|
||
## Fields | ||
|
||
### User | ||
|
||
The subscribed user. | ||
|
||
### Object | ||
|
||
The object to which the user is subscribed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.utils.translation import gettext as _ | ||
|
||
from netbox.events import * | ||
|
||
__all__ = ( | ||
'JOB_COMPLETED', | ||
'JOB_ERRORED', | ||
'JOB_FAILED', | ||
'JOB_STARTED', | ||
'OBJECT_CREATED', | ||
'OBJECT_DELETED', | ||
'OBJECT_UPDATED', | ||
) | ||
|
||
# Object events | ||
OBJECT_CREATED = 'object_created' | ||
OBJECT_UPDATED = 'object_updated' | ||
OBJECT_DELETED = 'object_deleted' | ||
|
||
# Job events | ||
JOB_STARTED = 'job_started' | ||
JOB_COMPLETED = 'job_completed' | ||
JOB_FAILED = 'job_failed' | ||
JOB_ERRORED = 'job_errored' | ||
|
||
# Register core events | ||
Event(name=OBJECT_CREATED, text=_('Object created')).register() | ||
Event(name=OBJECT_UPDATED, text=_('Object updated')).register() | ||
Event(name=OBJECT_DELETED, text=_('Object deleted')).register() | ||
Event(name=JOB_STARTED, text=_('Job started')).register() | ||
Event(name=JOB_COMPLETED, text=_('Job completed'), type=EVENT_TYPE_SUCCESS).register() | ||
Event(name=JOB_FAILED, text=_('Job failed'), type=EVENT_TYPE_WARNING).register() | ||
Event(name=JOB_ERRORED, text=_('Job errored'), type=EVENT_TYPE_DANGER).register() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from drf_spectacular.utils import extend_schema_field | ||
from rest_framework import serializers | ||
|
||
from core.models import ObjectType | ||
from extras.models import Notification, NotificationGroup, Subscription | ||
from netbox.api.fields import ContentTypeField, SerializedPKRelatedField | ||
from netbox.api.serializers import ValidatedModelSerializer | ||
from users.api.serializers_.users import GroupSerializer, UserSerializer | ||
from users.models import Group, User | ||
from utilities.api import get_serializer_for_model | ||
|
||
__all__ = ( | ||
'NotificationSerializer', | ||
'NotificationGroupSerializer', | ||
'SubscriptionSerializer', | ||
) | ||
|
||
|
||
class NotificationSerializer(ValidatedModelSerializer): | ||
object_type = ContentTypeField( | ||
queryset=ObjectType.objects.with_feature('notifications'), | ||
) | ||
object = serializers.SerializerMethodField(read_only=True) | ||
user = UserSerializer(nested=True) | ||
|
||
class Meta: | ||
model = Notification | ||
fields = [ | ||
'id', 'url', 'display', 'object_type', 'object_id', 'object', 'user', 'created', 'read', 'event_type', | ||
jeremystretch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
brief_fields = ('id', 'url', 'display', 'object_type', 'object_id', 'user', 'read', 'event_type') | ||
|
||
@extend_schema_field(serializers.JSONField(allow_null=True)) | ||
def get_object(self, instance): | ||
serializer = get_serializer_for_model(instance.object) | ||
context = {'request': self.context['request']} | ||
return serializer(instance.object, nested=True, context=context).data | ||
|
||
|
||
class NotificationGroupSerializer(ValidatedModelSerializer): | ||
groups = SerializedPKRelatedField( | ||
queryset=Group.objects.all(), | ||
serializer=GroupSerializer, | ||
nested=True, | ||
required=False, | ||
many=True | ||
) | ||
users = SerializedPKRelatedField( | ||
queryset=User.objects.all(), | ||
serializer=UserSerializer, | ||
nested=True, | ||
required=False, | ||
many=True | ||
) | ||
|
||
class Meta: | ||
model = NotificationGroup | ||
fields = [ | ||
'id', 'url', 'display', 'display_url', 'name', 'description', 'groups', 'users', | ||
] | ||
brief_fields = ('id', 'url', 'display', 'name', 'description') | ||
|
||
|
||
class SubscriptionSerializer(ValidatedModelSerializer): | ||
object_type = ContentTypeField( | ||
queryset=ObjectType.objects.with_feature('notifications'), | ||
) | ||
object = serializers.SerializerMethodField(read_only=True) | ||
user = UserSerializer(nested=True) | ||
|
||
class Meta: | ||
model = Subscription | ||
fields = [ | ||
'id', 'url', 'display', 'object_type', 'object_id', 'object', 'user', 'created', | ||
] | ||
brief_fields = ('id', 'url', 'display', 'object_type', 'object_id', 'user') | ||
|
||
@extend_schema_field(serializers.JSONField(allow_null=True)) | ||
def get_object(self, instance): | ||
serializer = get_serializer_for_model(instance.object) | ||
context = {'request': self.context['request']} | ||
return serializer(instance.object, nested=True, context=context).data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.