mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-01-12 01:09:53 +01:00
Merge pull request #6 from mediacms-io/feat-notifications
provide notifications on commenting
This commit is contained in:
commit
3e2ff1e22d
@ -24,7 +24,7 @@ class IsUserOrManager(permissions.BasePermission):
|
|||||||
if is_mediacms_manager(request.user):
|
if is_mediacms_manager(request.user):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return obj == request.user
|
return obj.user == request.user
|
||||||
|
|
||||||
|
|
||||||
class IsUserOrEditor(permissions.BasePermission):
|
class IsUserOrEditor(permissions.BasePermission):
|
||||||
@ -41,7 +41,7 @@ class IsUserOrEditor(permissions.BasePermission):
|
|||||||
if is_mediacms_editor(request.user):
|
if is_mediacms_editor(request.user):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return obj == request.user
|
return obj.user == request.user
|
||||||
|
|
||||||
|
|
||||||
def user_allowed_to_upload(request):
|
def user_allowed_to_upload(request):
|
||||||
|
@ -173,7 +173,8 @@ MINIMUM_RESOLUTIONS_TO_ENCODE = [240, 360]
|
|||||||
USERS_NOTIFICATIONS = {
|
USERS_NOTIFICATIONS = {
|
||||||
"MEDIA_ADDED": True, # in use
|
"MEDIA_ADDED": True, # in use
|
||||||
"MEDIA_ENCODED": False, # not implemented
|
"MEDIA_ENCODED": False, # not implemented
|
||||||
"MEDIA_REPORTED": False, # not implemented
|
"MEDIA_REPORTED": True, # in use
|
||||||
|
"COMMENT_ADDED": True, # in use
|
||||||
}
|
}
|
||||||
|
|
||||||
ADMINS_NOTIFICATIONS = {
|
ADMINS_NOTIFICATIONS = {
|
||||||
|
@ -149,22 +149,32 @@ def notify_users(friendly_token=None, action=None, extra=None):
|
|||||||
media_url = settings.SSL_FRONTEND_HOST + media.get_absolute_url()
|
media_url = settings.SSL_FRONTEND_HOST + media.get_absolute_url()
|
||||||
|
|
||||||
if action == "media_reported" and media:
|
if action == "media_reported" and media:
|
||||||
if settings.ADMINS_NOTIFICATIONS.get("MEDIA_REPORTED", False):
|
msg = """
|
||||||
title = "[{}] - Media was reported".format(settings.PORTAL_NAME)
|
|
||||||
msg = """
|
|
||||||
Media %s was reported.
|
Media %s was reported.
|
||||||
Reason: %s\n
|
Reason: %s\n
|
||||||
Total times this media has been reported: %s
|
Total times this media has been reported: %s\n
|
||||||
""" % (
|
Media becomes private if it gets reported %s times\n
|
||||||
media_url,
|
""" % (
|
||||||
extra,
|
media_url,
|
||||||
media.reported_times,
|
extra,
|
||||||
)
|
media.reported_times,
|
||||||
|
settings.REPORTED_TIMES_THRESHOLD,
|
||||||
|
)
|
||||||
|
|
||||||
|
if settings.ADMINS_NOTIFICATIONS.get("MEDIA_REPORTED", False):
|
||||||
|
title = "[{}] - Media was reported".format(settings.PORTAL_NAME)
|
||||||
d = {}
|
d = {}
|
||||||
d["title"] = title
|
d["title"] = title
|
||||||
d["msg"] = msg
|
d["msg"] = msg
|
||||||
d["to"] = settings.ADMIN_EMAIL_LIST
|
d["to"] = settings.ADMIN_EMAIL_LIST
|
||||||
notify_items.append(d)
|
notify_items.append(d)
|
||||||
|
if settings.USERS_NOTIFICATIONS.get("MEDIA_REPORTED", False):
|
||||||
|
title = "[{}] - Media was reported".format(settings.PORTAL_NAME)
|
||||||
|
d = {}
|
||||||
|
d["title"] = title
|
||||||
|
d["msg"] = msg
|
||||||
|
d["to"] = [media.user.email]
|
||||||
|
notify_items.append(d)
|
||||||
|
|
||||||
if action == "media_added" and media:
|
if action == "media_added" and media:
|
||||||
if settings.ADMINS_NOTIFICATIONS.get("MEDIA_ADDED", False):
|
if settings.ADMINS_NOTIFICATIONS.get("MEDIA_ADDED", False):
|
||||||
@ -194,6 +204,16 @@ URL: %s
|
|||||||
d["to"] = [media.user.email]
|
d["to"] = [media.user.email]
|
||||||
notify_items.append(d)
|
notify_items.append(d)
|
||||||
|
|
||||||
|
if action == "comment_added" and media:
|
||||||
|
if settings.USERS_NOTIFICATIONS.get("COMMENT_ADDED", False):
|
||||||
|
d = {}
|
||||||
|
title = f"[{settings.PORTAL_NAME}] - Comment was added"
|
||||||
|
msg = f"A comment was added on media {media_url}\n"
|
||||||
|
d["title"] = title
|
||||||
|
d["msg"] = msg
|
||||||
|
d["to"] = [media.user.username]
|
||||||
|
notify_items.append(d)
|
||||||
|
|
||||||
for item in notify_items:
|
for item in notify_items:
|
||||||
email = EmailMessage(
|
email = EmailMessage(
|
||||||
item["title"], item["msg"], settings.DEFAULT_FROM_EMAIL, item["to"]
|
item["title"], item["msg"], settings.DEFAULT_FROM_EMAIL, item["to"]
|
||||||
|
@ -1712,3 +1712,11 @@ def encoding_file_delete(sender, instance, **kwargs):
|
|||||||
instance.media.post_encode_actions(encoding=instance, action="delete")
|
instance.media.post_encode_actions(encoding=instance, action="delete")
|
||||||
# delete local chunks, and remote chunks + media file. Only when the
|
# delete local chunks, and remote chunks + media file. Only when the
|
||||||
# last encoding of a media is complete
|
# last encoding of a media is complete
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=Comment)
|
||||||
|
def comment_save(sender, instance, created, **kwargs):
|
||||||
|
if created:
|
||||||
|
notify_users(
|
||||||
|
friendly_token=instance.media.friendly_token, action="comment_added"
|
||||||
|
)
|
||||||
|
@ -1112,7 +1112,7 @@ class CommentDetail(APIView):
|
|||||||
Delete comment (DELETE)
|
Delete comment (DELETE)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
permission_classes = (permissions.IsAuthenticatedOrReadOnly, IsUserOrEditor)
|
permission_classes = (IsAuthorizedToAdd,)
|
||||||
parser_classes = (JSONParser, MultiPartParser, FormParser, FileUploadParser)
|
parser_classes = (JSONParser, MultiPartParser, FormParser, FileUploadParser)
|
||||||
|
|
||||||
def get_object(self, friendly_token):
|
def get_object(self, friendly_token):
|
||||||
|
Loading…
Reference in New Issue
Block a user