Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BITMAKER-2971: Add actions notifications to estela (#188)
Related: #142 * Add Notification model * Add notification message and notification handler * Add notification views * Show a brief preview on the header notification icon * Add inbox notifications page * Add seen field for every user notification * Fix case when a superuser tried to add itself to a project * When clicking a notification, mark it as seen --------- Co-authored-by: José Galdos Chávez <jgaldoschavez@gmail.com> Co-authored-by: Raymond Negron <raymond1242@Raymonds-MacBook-Air.local> Co-authored-by: mgonnav <mateo@emegona.com>
- Loading branch information
1 parent
e153738
commit 2da9074
Showing
43 changed files
with
1,735 additions
and
362 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,60 @@ | ||
from rest_framework import serializers | ||
|
||
from api.serializers.project import ProjectDetailSerializer, UserDetailSerializer | ||
from core.models import Notification, UserNotification | ||
|
||
|
||
class NotificationSerializer(serializers.ModelSerializer): | ||
user = UserDetailSerializer( | ||
required=True, help_text="User who performed the action." | ||
) | ||
project = ProjectDetailSerializer( | ||
required=True, help_text="Project where the action was performed." | ||
) | ||
|
||
class Meta: | ||
model = Notification | ||
fields = ("nid", "message", "user", "project") | ||
|
||
|
||
class UserNotificationSerializer(serializers.ModelSerializer): | ||
id = serializers.IntegerField( | ||
required=True, help_text="Unique user notification ID." | ||
) | ||
notification = NotificationSerializer( | ||
required=True, help_text="Notification to which the user is subscribed." | ||
) | ||
|
||
class Meta: | ||
model = UserNotification | ||
fields = ("id", "notification", "seen", "created") | ||
|
||
def to_representation(self, instance): | ||
ret = super().to_representation(instance) | ||
user = instance.notification.user | ||
|
||
is_superuser = user.is_superuser or user.is_staff | ||
user_in_project = instance.notification.project.users.filter(id=user.id) | ||
if is_superuser and not user_in_project: | ||
ret["notification"]["user"]["username"] = "Bitmaker Cloud Admin" | ||
else: | ||
ret["notification"]["user"][ | ||
"username" | ||
] = user.username | ||
return ret | ||
|
||
|
||
class UserNotificationUpdateSerializer(serializers.ModelSerializer): | ||
seen = serializers.BooleanField( | ||
required=False, | ||
help_text="Whether the user has seen the notification.", | ||
) | ||
|
||
class Meta: | ||
model = UserNotification | ||
fields = ("id", "seen") | ||
|
||
def update(self, instance, validated_data): | ||
instance.seen = validated_data.get("seen", instance.seen) | ||
instance.save() | ||
return instance |
This file contains 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 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 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 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 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.