From dc06865b05e2ee826b0fc846c47b5fa34c183e23 Mon Sep 17 00:00:00 2001
From: Guillaume Gouin <guillaume.gouin@ametys.org>
Date: Tue, 24 Aug 2021 10:32:44 +0200
Subject: [PATCH] WORKSPACES-1127 Filter notification to only those concerning
 the user

Add support for an activity parameter in the user preference service
---
 main/skin-workspace-catalog/i18n/messages.xml |  7 ++
 .../i18n/messages_fr.xml                      |  7 ++
 .../workspaces-preferences/preferences.xsl    | 96 +++++++++++++++++++
 3 files changed, 110 insertions(+)

diff --git a/main/skin-workspace-catalog/i18n/messages.xml b/main/skin-workspace-catalog/i18n/messages.xml
index 809b85b..2e6bbf2 100644
--- a/main/skin-workspace-catalog/i18n/messages.xml
+++ b/main/skin-workspace-catalog/i18n/messages.xml
@@ -114,6 +114,9 @@
     
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_HEADER_TITLE">Mail notification</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_DISABLE_WIDGET_LABEL">Pause all notifications</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_SECTION_TITLE">Which activities do you want to be notified about?</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_WIDGET_LABEL_ALL">Every projects activities (new document, new wall content…)</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_WIDGET_LABEL_CONCERNING_ME">Activity concerning me</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_FREQUENCY_SECTION_TITLE">Notifications frequency</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_FREQUENCY_WIDGET_LABEL_EACH">Receive a mail <strong>for each new activity</strong></message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_FREQUENCY_WIDGET_LABEL_DAILY">Receive a <strong>daily</strong> summary</message>
@@ -123,14 +126,18 @@
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_PROJECTS_SECTION_HINT">Below is the list of project for which you have defined custom notifications settings. You can define specific settings for every project where you are member.</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ITEM_ACTION_EDIT">Edit</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ITEM_ACTION_DELETE">Delete</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_ALL">Every project activities (new document, new wall content…)</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_CONCERNING_ME">Activity concerning me</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_PROJECTS_SECTION_NEW_PREFERENCES_ACTION_LABEL">Add a settings</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_HEADER_TITLE">Add a specific settings</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_PROJECT_SELECTOR_TITLE">Project</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_DISABLE_WIDGET_LABEL">Pause all notifications</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_ACTIVITY_SECTION_TITLE">Which activities do you want to be notified about?</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_FREQUENCY_SECTION_TITLE">Notifications frequency</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_FOOTER_CLOSE_ACTION">Cancel</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_FOOTER_APPLY_ACTION">Validate</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_DISABLE_WIDGET_LABEL">Pause all notifications for this project</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_ACTIVITY_SECTION_TITLE">Which activities do you want to be notified about?</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_FREQUENCY_SECTION_TITLE">Notifications frequency</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_FOOTER_APPLY_ACTION">Validate</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_FOOTER_CLOSE_ACTION">Cancel</message>
diff --git a/main/skin-workspace-catalog/i18n/messages_fr.xml b/main/skin-workspace-catalog/i18n/messages_fr.xml
index c940ade..28e99ac 100644
--- a/main/skin-workspace-catalog/i18n/messages_fr.xml
+++ b/main/skin-workspace-catalog/i18n/messages_fr.xml
@@ -114,6 +114,9 @@
     
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_HEADER_TITLE">Notifications par email</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_DISABLE_WIDGET_LABEL">Tout mettre en pause</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_SECTION_TITLE">Pour quelles activités souhaitez-vous recevoir des emails ?</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_WIDGET_LABEL_ALL">Toutes les activités des projets (nouveau document, nouvelle brève…)</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_WIDGET_LABEL_CONCERNING_ME">Les activités qui me concernent</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_FREQUENCY_SECTION_TITLE">Fréquence des notifications</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_FREQUENCY_WIDGET_LABEL_EACH">Recevoir un email <strong>à chaque nouvelle activité</strong></message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_FREQUENCY_WIDGET_LABEL_DAILY">Recevoir un résumé <strong>quotidien</strong></message>
@@ -123,14 +126,18 @@
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_PROJECTS_SECTION_HINT">Ceci est la liste des projets pour lesquels vous avez choisi d’affiner les notifications. Vous pouvez assigner des réglages spécifiques pour tous les projets dont vous êtes membre.</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ITEM_ACTION_EDIT">Modifier</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ITEM_ACTION_DELETE">Supprimer</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_ALL">Toutes les activités du projet (nouveau document, nouvelle brève…)</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_CONCERNING_ME">Les activités qui me concernent</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_PROJECTS_SECTION_NEW_PREFERENCES_ACTION_LABEL">Ajouter un réglage</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_HEADER_TITLE">Ajouter un réglage spécifique</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_PROJECT_SELECTOR_TITLE">Projet</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_DISABLE_WIDGET_LABEL">Tout mettre en pause</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_ACTIVITY_SECTION_TITLE">Pour quelle(s) activité(s) souhaitez-vous recevoir des emails ?</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_FREQUENCY_SECTION_TITLE">Fréquence des notifications</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_FOOTER_CLOSE_ACTION">Annuler</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_FOOTER_APPLY_ACTION">Valider</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_DISABLE_WIDGET_LABEL">Mettre en pause toutes les notifications de ce projet</message>
+    <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_ACTIVITY_SECTION_TITLE">Pour quelle(s) activité(s) souhaitez-vous recevoir des emails ?</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_FREQUENCY_SECTION_TITLE">Fréquence des notifications</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_FOOTER_APPLY_ACTION">Valider</message>
     <message key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_FOOTER_CLOSE_ACTION">Annuler</message>
diff --git a/main/skin-workspace-catalog/services/workspaces/pages/services/workspaces-preferences/preferences.xsl b/main/skin-workspace-catalog/services/workspaces/pages/services/workspaces-preferences/preferences.xsl
index b795db4..c484ae2 100644
--- a/main/skin-workspace-catalog/services/workspaces/pages/services/workspaces-preferences/preferences.xsl
+++ b/main/skin-workspace-catalog/services/workspaces/pages/services/workspaces-preferences/preferences.xsl
@@ -190,6 +190,8 @@
                 <form id="preference-default-notification-form-{$unique-id}" data-default-notifications-form="true">
                     <xsl:call-template name="notifications-body-disable-section"/>
                     
+                    <xsl:call-template name="notifications-body-activity-section"/>
+                    
                     <xsl:call-template name="notifications-body-frequency-section"/>
                                     
                     <xsl:call-template name="notifications-body-projects-section"/>
@@ -216,6 +218,36 @@
         <i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_DISABLE_WIDGET_LABEL"/>
     </xsl:template>
     
+    <xsl:template name="notifications-body-activity-section">
+        <div class="ametys-content-section" data-notification-activity="true">
+            <xsl:call-template name="notifications-body-default-form-activity-title"/>
+            
+            <xsl:call-template name="notifications-body-default-form-activity-widgets"/>
+        </div>
+    </xsl:template>
+    
+    <xsl:template name="notifications-body-default-form-activity-title">
+    <h3>
+        <i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_SECTION_TITLE" />
+    </h3>
+    </xsl:template>
+    
+    <xsl:template name="notifications-body-default-form-activity-widgets">
+        <div class="ametys-radio-group">
+            <xsl:call-template name="ametys-radio">
+                <xsl:with-param name="name">activity</xsl:with-param>
+                <xsl:with-param name="value">all</xsl:with-param>
+                <xsl:with-param name="label"><i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_WIDGET_LABEL_ALL"/></xsl:with-param>
+            </xsl:call-template>
+            
+            <xsl:call-template name="ametys-radio">
+                <xsl:with-param name="name">activity</xsl:with-param>
+                <xsl:with-param name="value">concerningMe</xsl:with-param>
+                <xsl:with-param name="label"><i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_BODY_ACTIVITY_WIDGET_LABEL_CONCERNING_ME"/></xsl:with-param>
+            </xsl:call-template>
+        </div>
+    </xsl:template>
+    
     <xsl:template name="notifications-body-frequency-section">
         <div class="ametys-content-section" data-notification-frequency="true">
             <xsl:call-template name="notifications-body-default-form-frequency-title"/>
@@ -333,6 +365,8 @@
                 
                 <xsl:call-template name="notifications-new-project-preferences-modal-body-disable-section"/>
                 
+                <xsl:call-template name="notifications-new-project-preferences-modal-body-activity-section"/>
+                
                 <xsl:call-template name="notifications-new-project-preferences-modal-body-frequency-section"/>
             </form>
         </div>
@@ -375,6 +409,36 @@
         </label>
     </xsl:template>
     
+    <xsl:template name="notifications-new-project-preferences-modal-body-activity-section">
+        <div class="ametys-content-section" data-notification-activity="true">
+            <xsl:call-template name="notifications-new-project-preferences-modal-body-activity-section-title"/>
+            
+            <xsl:call-template name="notifications-new-project-preferences-modal-body-activity-section-widget"/>
+        </div>
+    </xsl:template>
+    
+    <xsl:template name="notifications-new-project-preferences-modal-body-activity-section-title">
+        <h3>
+            <i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_NEW_PROJECT_PREFERENCES_MODAL_ACTIVITY_SECTION_TITLE"/>
+        </h3>
+    </xsl:template>
+    
+    <xsl:template name="notifications-new-project-preferences-modal-body-activity-section-widget">
+        <div class="ametys-radio-group">
+            <xsl:call-template name="ametys-radio">
+                <xsl:with-param name="name">activity</xsl:with-param>
+                <xsl:with-param name="value">all</xsl:with-param>
+                <xsl:with-param name="label"><i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_ALL"/></xsl:with-param>
+            </xsl:call-template>
+            
+            <xsl:call-template name="ametys-radio">
+                <xsl:with-param name="name">activity</xsl:with-param>
+                <xsl:with-param name="value">concerningMe</xsl:with-param>
+                <xsl:with-param name="label"><i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_CONCERNING_ME"/></xsl:with-param>
+            </xsl:call-template>
+        </div>
+    </xsl:template>
+    
     <xsl:template name="notifications-new-project-preferences-modal-body-frequency-section">
         <div class="ametys-content-section" data-notification-frequency="true">
             <xsl:call-template name="notifications-new-project-preferences-modal-body-frequency-section-title"/>
@@ -464,6 +528,8 @@
                 <input name="project-name" type="hidden"/>
                 <xsl:call-template name="notification-project-preferences-modal-body-disable-section"/>
                 
+                <xsl:call-template name="notification-project-preferences-modal-body-activity-section"/>
+                
                 <xsl:call-template name="notification-project-preferences-modal-body-frequency-section"/>
             </form>
         </div>
@@ -489,6 +555,36 @@
         </label>
     </xsl:template>
     
+    <xsl:template name="notification-project-preferences-modal-body-activity-section">
+        <div class="ametys-content-section" data-notification-activity="true">
+            <xsl:call-template name="notification-project-preferences-modal-body-activity-section-title"/>
+            
+            <xsl:call-template name="notification-project-preferences-modal-body-activity-section-widget"/>
+        </div>
+    </xsl:template>
+    
+    <xsl:template name="notification-project-preferences-modal-body-activity-section-title">
+        <h3>
+            <i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_PREFERENCES_MODAL_ACTIVITY_SECTION_TITLE"/>
+        </h3>
+    </xsl:template>
+    
+    <xsl:template name="notification-project-preferences-modal-body-activity-section-widget">
+        <div class="ametys-radio-group">
+            <xsl:call-template name="ametys-radio">
+                <xsl:with-param name="name">activity</xsl:with-param>
+                <xsl:with-param name="value">all</xsl:with-param>
+                <xsl:with-param name="label"><i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_ALL"/></xsl:with-param>
+            </xsl:call-template>
+            
+            <xsl:call-template name="ametys-radio">
+                <xsl:with-param name="name">activity</xsl:with-param>
+                <xsl:with-param name="value">concerningMe</xsl:with-param>
+                <xsl:with-param name="label"><i18n:text i18n:catalogue="skin.workspace-catalog" i18n:key="SKIN_SERVICE_PREFERENCE_NOTIFICATIONS_PROJECT_ACTIVITY_WIDGET_LABEL_CONCERNING_ME"/></xsl:with-param>
+            </xsl:call-template>
+        </div>
+    </xsl:template>
+    
     <xsl:template name="notification-project-preferences-modal-body-frequency-section">
         <div class="ametys-content-section" data-notification-frequency="true">
             <xsl:call-template name="notification-project-preferences-modal-body-frequency-section-title"/>
-- 
2.33.0

