Skip to content

Commit

Permalink
Add PWA functionality to app and notifications capabilities
Browse files Browse the repository at this point in the history
Owners can set their notification preference.
Notifications are sent when video encoding is complete.

Co-authored-by: Éloi Rivard <[email protected]>
Co-authored-by: Loan Robert <[email protected]>
  • Loading branch information
azmeuk and LoanR committed Sep 5, 2023
1 parent 65a56ba commit e7b4421
Show file tree
Hide file tree
Showing 40 changed files with 514 additions and 11 deletions.
7 changes: 7 additions & 0 deletions dockerfile-dev-with-volumes/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ MIGRATION_MODULES = {'flatpages': 'pod.db_migrations'}
# pour avoir le maximum de log sur la console
LOGGING = {}
# PUSH NOTIFICATIONS
# Les clés VAPID peuvent être générées avec https://web-push-codelab.glitch.me/
WEBPUSH_SETTINGS = {
"VAPID_PUBLIC_KEY": "",
"VAPID_PRIVATE_KEY": "",
"VAPID_ADMIN_EMAIL": "[email protected]"
}
----

== Commandes
Expand Down
9 changes: 9 additions & 0 deletions pod/authentication/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ class Meta(object):
fields = []


class SetNotificationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(SetNotificationForm, self).__init__(*args, **kwargs)

class Meta(object):
model = Owner
fields = ["accepts_notifications"]


User = get_user_model()


Expand Down
6 changes: 6 additions & 0 deletions pod/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ class Owner(models.Model):
)
accessgroups = models.ManyToManyField("authentication.AccessGroup", blank=True)
sites = models.ManyToManyField(Site)
accepts_notifications = models.BooleanField(
verbose_name=_("Accept notifications"),
default=None,
null=True,
help_text=_("Get push notifications from your devices."),
)

class Meta:
verbose_name = _("Owner")
Expand Down
Binary file modified pod/locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
34 changes: 33 additions & 1 deletion pod/locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-01 09:54+0000\n"
"POT-Creation-Date: 2023-09-04 12:50+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: Pod Team [email protected]\n"
Expand Down Expand Up @@ -100,6 +100,14 @@ msgstr "Commentaire"
msgid "Picture"
msgstr "Image"

#: pod/authentication/models.py
msgid "Accept notifications"
msgstr "Accepter les notifications"

#: pod/authentication/models.py
msgid "Get push notifications from your devices."
msgstr "Recevez des notifications push sur vos appareils"

#: pod/authentication/models.py pod/live/models.py pod/meeting/models.py
#: pod/podfile/models.py pod/video/admin.py pod/video/models.py
#: pod/video_search/templates/search/search.html
Expand Down Expand Up @@ -4727,6 +4735,10 @@ msgstr "Mes fichiers"
msgid "Claim a record"
msgstr "Revendiquer un enregistrement"

#: pod/main/templates/navbar.html pod/progressive_web_app/templates/debug.html
msgid "Notifications settings"
msgstr "Paramètres de notification"

#: pod/main/templates/navbar.html
msgid "Log out"
msgstr "Déconnexion"
Expand Down Expand Up @@ -6199,6 +6211,26 @@ msgstr "Vous ne pouvez pas voir ce dossier."
msgid "You cannot edit this file."
msgstr "Vous ne pouvez pas éditer ce fichier."

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Get application notifications"
msgstr "Recevez les notifications de l'application"

#: pod/progressive_web_app/templates/notification_toast.html
msgid ""
"Get notified for specific events (when one of your video "
"encoding is completed)."
msgstr ""
"Recevez des notifications pour des événements spécifiques (lorsque "
"l'encodage d'une de vos vidéos est terminé)"

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Allow"
msgstr "Autoriser"

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Deny on all devices"
msgstr "Refuser sur tous les appareils"

#: pod/recorder/admin.py
msgid "Delete selected Recording file treatments + source files"
msgstr ""
Expand Down
Binary file modified pod/locale/fr/LC_MESSAGES/djangojs.mo
Binary file not shown.
18 changes: 17 additions & 1 deletion pod/locale/fr/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Esup-Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-01 09:54+0000\n"
"POT-Creation-Date: 2023-09-04 13:15+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -550,6 +550,18 @@ msgstr "Ce dossier est vide"
msgid "Channel"
msgstr "Chaîne"

#: pod/progressive_web_app/static/js/notification-toast.js
msgid ""
"Don't forget to allow notifications from this website in your browser's "
"settings!"
msgstr ""
"N'oubliez pas d'autoriser les notifications provenant de ce site web dans "
"votre navigateur !"

#: pod/progressive_web_app/static/js/notification-toast.js
msgid "Error during unsubscription..."
msgstr "Erreur durant la désinscription..."

#: pod/video/static/js/ajax-display-channels.js
msgid "No channels found"
msgstr "Aucun chaîne trouvée"
Expand Down Expand Up @@ -757,6 +769,10 @@ msgstr "Créer catégorie"
msgid "Select the general type of the video."
msgstr "Sélectionnez le type général de vidéo."

#: pod/video/static/js/video_edit.js
msgid "Get notified when the video encoding is finished."
msgstr "Recevez une notification lorsque l'encodage de la vidéo est terminé."

#: pod/video/static/js/video_stats_view.js
msgid "Title"
msgstr "Titre"
Expand Down
32 changes: 31 additions & 1 deletion pod/locale/nl/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-01 09:54+0000\n"
"POT-Creation-Date: 2023-09-04 12:50+0000\n"
"PO-Revision-Date: 2023-06-08 14:37+0200\n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -100,6 +100,14 @@ msgstr ""
msgid "Picture"
msgstr ""

#: pod/authentication/models.py
msgid "Accept notifications"
msgstr ""

#: pod/authentication/models.py
msgid "Get push notifications from your devices."
msgstr ""

#: pod/authentication/models.py pod/live/models.py pod/meeting/models.py
#: pod/podfile/models.py pod/video/admin.py pod/video/models.py
#: pod/video_search/templates/search/search.html
Expand Down Expand Up @@ -4481,6 +4489,10 @@ msgstr ""
msgid "Claim a record"
msgstr ""

#: pod/main/templates/navbar.html pod/progressive_web_app/templates/debug.html
msgid "Notifications settings"
msgstr ""

#: pod/main/templates/navbar.html
msgid "Log out"
msgstr "Uitloggen"
Expand Down Expand Up @@ -5858,6 +5870,24 @@ msgstr ""
msgid "You cannot edit this file."
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Get application notifications"
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid ""
"Get notified for specific events (when one of your video "
"encoding is completed)."
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Allow"
msgstr ""

#: pod/progressive_web_app/templates/notification_toast.html
msgid "Deny on all devices"
msgstr ""

#: pod/recorder/admin.py
msgid "Delete selected Recording file treatments + source files"
msgstr ""
Expand Down
16 changes: 15 additions & 1 deletion pod/locale/nl/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Esup-Pod\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-01 09:54+0000\n"
"POT-Creation-Date: 2023-09-04 13:15+0000\n"
"PO-Revision-Date: 2023-02-08 15:22+0100\n"
"Last-Translator: obado <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -521,6 +521,16 @@ msgstr ""
msgid "This folder is empty"
msgstr ""

#: pod/progressive_web_app/static/js/notification-toast.js
msgid ""
"Don't forget to allow notifications from this website in your browser's "
"settings!"
msgstr ""

#: pod/progressive_web_app/static/js/notification-toast.js
msgid "Error during unsubscription..."
msgstr ""

#: pod/video/static/js/ajax-display-channels.js
msgid "Channel"
msgstr ""
Expand Down Expand Up @@ -731,6 +741,10 @@ msgstr ""
msgid "Select the general type of the video."
msgstr ""

#: pod/video/static/js/video_edit.js
msgid "Get notified when the video encoding is finished."
msgstr ""

#: pod/video/static/js/video_stats_view.js
msgid "Title"
msgstr "Titel"
Expand Down
24 changes: 23 additions & 1 deletion pod/main/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,28 @@
"fr": "Configuration application podfile"
}
},
"progressive_web_app": {
"description": {},
"settings": {
"WEBPUSH_SETTINGS": {
"default_value": "```python\n{\n 'VAPID_PUBLIC_KEY': '',\n 'VAPID_PRIVATE_KEY': '',\n 'VAPID_ADMIN_EMAIL': '[email protected]'\n}\n```",
"description": {
"en": [
""
],
"fr": [
"Les clés VAPID sont nécessaires à la lib [django-webpush](https://github.com/safwanrahman/django-webpush). Elles peuvent être générées avec [https://web-push-codelab.glitch.me/]()"
]
},
"pod_version_end": "",
"pod_version_init": ""
}
},
"title": {
"en": "",
"fr": "Configuration application progressive_web_app"
}
},
"recorder": {
"description": {},
"settings": {
Expand Down Expand Up @@ -4965,4 +4987,4 @@
}
}
}
]
]
6 changes: 6 additions & 0 deletions pod/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,9 @@
VIDEO_RECENT_VIEWCOUNT = 180

HONEYPOT_FIELD_NAME = "firstname"

WEBPUSH_SETTINGS = {
"VAPID_PUBLIC_KEY": "",
"VAPID_PRIVATE_KEY": "",
"VAPID_ADMIN_EMAIL": "[email protected]"
}
7 changes: 5 additions & 2 deletions pod/main/templates/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% load static i18n custom_tags %}
{% load pwa %}
{% load webpush_notifications %}
{% get_current_language as LANGUAGE_CODE %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE }}">
Expand Down Expand Up @@ -46,8 +48,9 @@
{% if request.GET.is_iframe %}
<link rel="stylesheet" href="{% static 'css/iframe.css' %}?ver={{VERSION}}" media="screen">
{% endif %}
{% progressive_web_app_meta %}
{% endspaceless %}

{% webpush_header %}
</head>

<body>
Expand Down Expand Up @@ -116,6 +119,7 @@ <h1 class="page_title">{{page_title|capfirst}}</h1>
{% endif %}
</div> <!-- fin div pod-grid-content -->
</main>
{% include "notification_toast.html" %}
</div> <!-- fin container -->
{% endblock content %}
{% if not request.GET.is_iframe %}
Expand Down Expand Up @@ -270,4 +274,3 @@ <h1 class="page_title">{{page_title|capfirst}}</h1>
</body>

</html>

5 changes: 5 additions & 0 deletions pod/main/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ <h5 id="pod-navbar__menuuserLabel">{% if user.get_full_name != '' %}{{ user.get_
<a class="nav-item nav-link" href="{% url 'bbb:live_list_meeting' %}"><i class="bi bi-lightning-charge pod-nav-link-icon mx-1" aria-hidden="true"></i>{% trans 'Perform a BigBlueButton live' %}</a>
{% endif %}
{% endif %}
<div class="nav-item">
<button class="nav-link" onclick="new bootstrap.Toast(document.querySelector('#notification-toast')).show()">
<i class="bi bi-bell pod-nav-link-icon mx-1"></i>{% trans 'Notifications settings' %}
</button>
</div>
{% comment %}
<a class="nav-item nav-link" href="#">Gestion de mon compte</a> {% endcomment %}
<hr class="dropdown-divider">
Expand Down
23 changes: 22 additions & 1 deletion pod/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from wsgiref.util import FileWrapper
from django.db.models import Q, Count
from pod.video.models import Video, remove_accents
from pod.authentication.forms import FrontOwnerForm
from pod.authentication.forms import FrontOwnerForm, SetNotificationForm
from django.db.models import Sum
import os
import mimetypes
Expand Down Expand Up @@ -395,3 +395,24 @@ def userpicture(request):
"userpicture/userpicture.html",
{"frontOwnerForm": frontOwnerForm},
)


@csrf_protect
@login_required(redirect_field_name="referrer")
def set_notifications(request):
"""Sets 'accepts_notifications' attribute on owner instance."""
setNotificationForm = SetNotificationForm(instance=request.user.owner)

if request.method == "POST":
setNotificationForm = SetNotificationForm(request.POST, instance=request.user.owner)
if setNotificationForm.is_valid():
setNotificationForm.save()
return JsonResponse({"success": True, "user_accepts_notifications": request.user.owner.accepts_notifications})
else:
messages.add_message(
request,
messages.ERROR,
_("One or more errors have been found in the form."),
)

return JsonResponse({"success": False})
Empty file.
6 changes: 6 additions & 0 deletions pod/progressive_web_app/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ProgressiveWebAppConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "pod.progressive_web_app"
Binary file added pod/progressive_web_app/static/img/icon_x1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x384.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pod/progressive_web_app/static/img/icon_x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e7b4421

Please sign in to comment.