Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #697 from OkunaOrg/feature/subscribe-to-post-notif…
Browse files Browse the repository at this point in the history
…ications

Feature/subscribe to post notifications
  • Loading branch information
lifenautjoe authored May 5, 2020
2 parents 09cc5eb + 98458f9 commit 7cb94cf
Show file tree
Hide file tree
Showing 44 changed files with 3,179 additions and 360 deletions.
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ name = "pypi"
[dev-packages]
polib = "*"
pytz = "*"
colorlog = "*"

[packages]
django = "==2.2.12"
python-dotenv = "*"
djangorestframework = "*"
sentry-sdk = "==0.10.2"
mysqlclient = "*"
pillow = "*"
django-nose = "*"
nose = "*"
Expand Down Expand Up @@ -55,6 +55,8 @@ shutilwhich = "*"
halo = "*"
watchdog = "*"
spectra = "*"
mysqlclient = "*"
colorlog = "*"

[pipenv]
allow_prereleases = true
18 changes: 17 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions openbook/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@
from openbook_notifications.views import Notifications, NotificationItem, ReadNotifications, ReadNotification, \
UnreadNotificationsCount
from openbook_posts.views.post.views import PostItem, PostOpen, PostClose, MutePost, UnmutePost, TranslatePost, \
PostPreviewLinkData, SearchPostParticipants, GetPostParticipants, PublishPost, PostStatus
PostPreviewLinkData, SearchPostParticipants, GetPostParticipants, PublishPost, PostStatus, \
PostNotificationsSubscriptionSettings
from openbook_posts.views.post_comment.post_comment_reaction.views import PostCommentReactionItem
from openbook_posts.views.post_comment.post_comment_reactions.views import PostCommentReactions, \
PostCommentReactionsEmojiCount
from openbook_posts.views.post_comment.post_comment_replies.views import PostCommentReplies
from openbook_posts.views.post_comment.views import PostCommentItem, MutePostComment, UnmutePostComment, \
TranslatePostComment
TranslatePostComment, PostCommentNotificationsSubscriptionSettings
from openbook_posts.views.post_comments.views import PostComments, PostCommentsDisable, PostCommentsEnable
from openbook_posts.views.post_media.views import PostMedia
from openbook_posts.views.post_reaction.views import PostReactionItem
Expand Down Expand Up @@ -159,6 +160,8 @@
post_notifications_patterns = [
path('mute/', MutePost.as_view(), name='mute-post'),
path('unmute/', UnmutePost.as_view(), name='unmute-post'),
path('subscribe/', PostNotificationsSubscriptionSettings.as_view(),
name='post-notifications-subscription-settings'),
]

post_comment_reactions_patterns = [
Expand All @@ -169,6 +172,8 @@
post_comment_notifications_patterns = [
path('mute/', MutePostComment.as_view(), name='mute-post-comment'),
path('unmute/', UnmutePostComment.as_view(), name='unmute-post-comment'),
path('subscribe/', PostCommentNotificationsSubscriptionSettings.as_view(),
name='post-comment-notifications-subscription-settings'),
]

post_comment_patterns = [
Expand Down
59 changes: 58 additions & 1 deletion openbook_auth/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from openbook_common.utils.model_loaders import get_post_model, get_community_model, get_post_comment_model, \
get_language_model, get_user_model, get_emoji_group_model, get_post_reaction_model, get_user_invite_model, \
get_community_notifications_subscription_model, get_user_notifications_subscription_model
get_community_notifications_subscription_model, get_user_notifications_subscription_model, \
get_post_notifications_subscription_model, get_post_comment_notifications_subscription_model

from openbook_common import checkers as common_checkers

Expand Down Expand Up @@ -342,6 +343,51 @@ def check_can_disable_new_post_notifications_for_community(user, community):
)


def check_can_disable_post_notifications_subscription_for_post(user, post):
if not user.can_see_post(post=post):
raise ValidationError(
_('You do not have permissions to view this post.'),
)

PostNotificationsSubscription = get_post_notifications_subscription_model()
post_notifications_enabled = \
PostNotificationsSubscription.is_user_with_username_subscribed_to_comment_notifications_for_post_with_id(
username=user.username, post_id=post.pk)

if not post_notifications_enabled:
raise ValidationError(
_('Post notifications are not enabled'),
)


def check_can_create_or_update_post_notifications_subscription_for_post(user, post):
if not user.can_see_post(post=post):
raise ValidationError(
_('You do not have permissions to view this post.'),
)


def check_can_update_reaction_notifications_for_post(user, post):
if not user.id == post.creator.id:
raise ValidationError(
_('Only the post creator can modify reaction notifications'),
)


def check_can_update_comment_reaction_notifications_for_post(user, post):
if not user.has_commented_post_with_id(post_id=post.pk):
raise ValidationError(
_('Only users with comments can modify comment reaction notifications'),
)


def check_can_create_or_update_notifications_subscription_for_post_comment(user, post_comment):
if not user.can_see_post_comment(post_comment=post_comment):
raise ValidationError(
_('You do not have permissions to view this post comment.'),
)


def check_can_get_community_with_name_members(user, community_name):
check_is_not_banned_from_community_with_name(user=user, community_name=community_name)

Expand Down Expand Up @@ -725,6 +771,11 @@ def check_has_device_with_uuid(user, device_uuid):


def check_can_mute_post(user, post):
PostNotificationsSubscription = get_post_notifications_subscription_model()
if not PostNotificationsSubscription.objects.filter(post=post, subscriber=user).exists():
raise ValidationError(
_('You aren\'t receiving notifications for this post'),
)
if user.has_muted_post_with_id(post_id=post.pk):
raise ValidationError(
_('Post already muted'),
Expand All @@ -745,6 +796,12 @@ def check_has_muted_post_with_id(user, post_id):


def check_can_mute_post_comment(user, post_comment):
PostCommentNotificationsSubscription = get_post_comment_notifications_subscription_model()
if not PostCommentNotificationsSubscription.objects.filter(post_comment=post_comment, subscriber=user).exists():
raise ValidationError(
_('You aren\'t receiving notifications for this post comment'),
)

if user.has_muted_post_comment_with_id(post_comment_id=post_comment.pk):
raise ValidationError(
_('Post comment already muted'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.5 on 2020-02-26 14:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('openbook_auth', '0051_auto_20191209_1338'),
]

operations = [
migrations.AddField(
model_name='usernotificationssettings',
name='post_subscription_comment_notifications',
field=models.BooleanField(default=True, verbose_name='post subscription comment notifications'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.10 on 2020-04-14 17:38

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('openbook_auth', '0052_usernotificationssettings_post_subscription_comment_notifications'),
]

operations = [
migrations.RemoveField(
model_name='usernotificationssettings',
name='post_subscription_comment_notifications',
),
]
42 changes: 42 additions & 0 deletions openbook_auth/migrations/0054_auto_20200422_1232.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 2.2.12 on 2020-04-22 10:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('openbook_auth', '0053_remove_usernotificationssettings_post_subscription_comment_notifications'),
]

operations = [
migrations.RemoveField(
model_name='usernotificationssettings',
name='post_comment_notifications',
),
migrations.RemoveField(
model_name='usernotificationssettings',
name='post_comment_reaction_notifications',
),
migrations.RemoveField(
model_name='usernotificationssettings',
name='post_comment_reply_notifications',
),
migrations.RemoveField(
model_name='usernotificationssettings',
name='post_comment_user_mention_notifications',
),
migrations.RemoveField(
model_name='usernotificationssettings',
name='post_reaction_notifications',
),
migrations.RemoveField(
model_name='usernotificationssettings',
name='post_user_mention_notifications',
),
migrations.AddField(
model_name='usernotificationssettings',
name='post_notifications',
field=models.BooleanField(default=True, verbose_name='post notifications'),
),
]
Loading

0 comments on commit 7cb94cf

Please sign in to comment.