Commit 0fb28f4b authored by build-pipeline's avatar build-pipeline
Browse files

publish: Merge branch 'features/US466-mail-token-analysis' into 'dev'

generated from commit 47c3b515
parent f8c72d35
......@@ -430,6 +430,16 @@ __webpack_require__("/Sqe");
var _DateNavigator = _interopRequireDefault(__webpack_require__("Hno1"));
var _luxon = __webpack_require__("ExVU");
var _reactRouterDom = __webpack_require__("55Ip");
var _usageEvent = _interopRequireDefault(__webpack_require__("dECN"));
var _cozyClient = __webpack_require__("SH7X");
var _usageEvent2 = __webpack_require__("/fHX");
(function () {
var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
enterModule && enterModule(module);
......@@ -440,6 +450,8 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
};
var AnalysisView = function AnalysisView() {
var client = (0, _cozyClient.useClient)();
var _useState = (0, _react.useState)(0),
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
headerHeight = _useState2[0],
......@@ -461,10 +473,21 @@ var AnalysisView = function AnalysisView() {
currentAnalysisDate = _useState4[0],
setCurrentAnalysisDate = _useState4[1];
var _useSelector3 = (0, _reactRedux.useSelector)(function (state) {
return state.ecolyo.profile;
}),
mailToken = _useSelector3.mailToken;
var dispatch = (0, _reactRedux.useDispatch)();
var defineHeaderHeight = (0, _react.useCallback)(function (height) {
setHeaderHeight(height);
}, []);
}, []); // Handle email report comeback
var _useLocation = (0, _reactRouterDom.useLocation)(),
search = _useLocation.search;
var query = new URLSearchParams(search);
var paramToken = query.get('token');
(0, _react.useEffect)(function () {
var updateAnalysisNotification = function updateAnalysisNotification() {
if (analysisNotification) {
......@@ -472,11 +495,30 @@ var AnalysisView = function AnalysisView() {
haveSeenLastAnalysis: true
}));
dispatch((0, _global.toggleAnalysisNotification)(false));
} // Save usageevent came back from email
if (paramToken && mailToken && paramToken === mailToken) {
_usageEvent.default.addEventIfDoesntExist(client, {
type: _usageEvent2.UsageEventType.REPORT_FROM_EMAIL,
target: 'analysis',
result: '1'
}, {
type: _usageEvent2.UsageEventType.REPORT_FROM_EMAIL,
eventDate: {
$lt: _luxon.DateTime.local().setZone('utc', {
keepLocalTime: true
}).endOf('month').toString(),
$gt: _luxon.DateTime.local().setZone('utc', {
keepLocalTime: true
}).startOf('month').toString()
}
});
}
};
updateAnalysisNotification();
}, [dispatch, analysisNotification, monthlyAnalysisDate, selectedDate]);
}, [dispatch, analysisNotification, monthlyAnalysisDate, selectedDate, paramToken, mailToken, client]);
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_CozyBar.default, {
titleKey: 'analysis.viewTitle'
}), /*#__PURE__*/_react.default.createElement(_Header.default, {
......@@ -492,8 +534,8 @@ var AnalysisView = function AnalysisView() {
})));
};
__signature__(AnalysisView, "useState{[headerHeight, setHeaderHeight](0)}\nuseSelector{{\n global: { analysisNotification },\n profile: { monthlyAnalysisDate },\n }}\nuseSelector{{ selectedDate }}\nuseState{[currentAnalysisDate, setCurrentAnalysisDate](monthlyAnalysisDate)}\nuseDispatch{dispatch}\nuseCallback{defineHeaderHeight}\nuseEffect{}", function () {
return [_reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useDispatch];
__signature__(AnalysisView, "useClient{client}\nuseState{[headerHeight, setHeaderHeight](0)}\nuseSelector{{\n global: { analysisNotification },\n profile: { monthlyAnalysisDate },\n }}\nuseSelector{{ selectedDate }}\nuseState{[currentAnalysisDate, setCurrentAnalysisDate](monthlyAnalysisDate)}\nuseSelector{{ mailToken }}\nuseDispatch{dispatch}\nuseCallback{defineHeaderHeight}\nuseLocation{{ search }}\nuseEffect{}", function () {
return [_cozyClient.useClient, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useSelector, _reactRedux.useDispatch, _reactRouterDom.useLocation];
});
var _default = AnalysisView;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html><html lang="{{.Locale}}"><head><meta charset="utf-8"><title>Ecolyo</title><link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16"><!-- PWA Manifest --><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#297EF2"><meta name="theme-color" content="#ffffff"><!-- PWA Chrome --><link rel="icon" sizes="192x192" href="/android-chrome-192x192.png"><link rel="icon" sizes="512x512" href="/android-chrome-512x512.png"><!-- PWA iOS --><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="apple-touch-startup-image" href="/apple-touch-icon.png"><meta name="apple-mobile-web-app-title" content="Ecolyo"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,viewport-fit=cover">{{.ThemeCSS}} {{.CozyBar}}</head><body><div role="application" class="application" data-cozy-token="{{.Token}}" data-cozy-domain="{{.Domain}}" data-cozy-locale="{{.Locale}}" data-cozy-app-name="{{.AppName}}" data-cozy-app-slug="{{.AppSlug}}" data-cozy-app-name-prefix="{{.AppNamePrefix}}" data-cozy-app-editor="{{.AppEditor}}" data-cozy-icon-path="{{.IconPath}}"><script src="vendors/ecolyo.71e07b5bcf60941ad333.js"></script><script src="app/ecolyo.7025ad350b8632c35dea.js"></script></div></body></html>
\ No newline at end of file
<!DOCTYPE html><html lang="{{.Locale}}"><head><meta charset="utf-8"><title>Ecolyo</title><link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32"><link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16"><!-- PWA Manifest --><link rel="manifest" href="/manifest.json" crossorigin="use-credentials"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#297EF2"><meta name="theme-color" content="#ffffff"><!-- PWA Chrome --><link rel="icon" sizes="192x192" href="/android-chrome-192x192.png"><link rel="icon" sizes="512x512" href="/android-chrome-512x512.png"><!-- PWA iOS --><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="apple-touch-startup-image" href="/apple-touch-icon.png"><meta name="apple-mobile-web-app-title" content="Ecolyo"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,viewport-fit=cover">{{.ThemeCSS}} {{.CozyBar}}</head><body><div role="application" class="application" data-cozy-token="{{.Token}}" data-cozy-domain="{{.Domain}}" data-cozy-locale="{{.Locale}}" data-cozy-app-name="{{.AppName}}" data-cozy-app-slug="{{.AppSlug}}" data-cozy-app-name-prefix="{{.AppNamePrefix}}" data-cozy-app-editor="{{.AppEditor}}" data-cozy-icon-path="{{.IconPath}}"><script src="vendors/ecolyo.71e07b5bcf60941ad333.js"></script><script src="app/ecolyo.baec73f98e180b41c731.js"></script></div></body></html>
\ No newline at end of file
......@@ -594,6 +594,27 @@ const calculateConsumptionVariation = async client => {
}
};
 
const sendEmailSubscription = async client => {
log('info', `sendEmailSubscription`);
const profile = await new _profile.default(client).getProfile();
if (profile && profile.sendAnalysisNotification) {
const cameBackFromEmail = {
createdBy: 'ecolyo',
measureName: _dacc.DaccEvent.SUMMARY_SUBSCRIPTION_MONTHLY,
startDate: _luxon.DateTime.local().setZone('utc', {
keepLocalTime: true
}).startOf('day').toISODate(),
value: profile.sendAnalysisNotification ? 1 : 0,
// eslint-disable-next-line @typescript-eslint/camelcase
group1: {
event_type: 'subscribed'
}
};
await sendIndicator(cameBackFromEmail, client);
}
};
const aggregateEvents = async (events, eventType, firstConnectionEvent, client) => {
let reducedEvents = null; // Used to store reducedEvents during calculation
 
......@@ -880,6 +901,27 @@ const aggregateEvents = async (events, eventType, firstConnectionEvent, client)
await calculPeriodBetweenChallenge(events, client);
break;
 
case _usageEvent2.UsageEventType.REPORT_FROM_EMAIL:
for (const event of events) {
const cameBackFromEmail = {
createdBy: 'ecolyo',
measureName: _dacc.DaccEvent.SUMMARY_SUBSCRIPTION_MONTHLY,
startDate: event.eventDate.toISODate(),
value: 1,
// eslint-disable-next-line @typescript-eslint/camelcase
group1: {
event_type: 'email'
}
};
const result = await sendIndicator(cameBackFromEmail, client);
if (result) {
readUsageEvents.push(event);
}
}
break;
default:
break;
}
......@@ -925,6 +967,7 @@ const AggregatorUsageEvents = async ({
keepLocalTime: true
}).startOf('day').day === profile.monthlyAnalysisDate.day) {
calculateConsumptionVariation(client);
sendEmailSubscription(client);
}
 
const uniqueReadUsageEvents = (0, _lodash.uniq)(readUsageEvents);
......@@ -957,6 +1000,7 @@ const AggregatorUsageEvents = async ({
reactHotLoader.register(buildProfileWithFuildType, "buildProfileWithFuildType", "/builds/web-et-numerique/llle_project/ecolyo/src/targets/services/aggregatorUsageEvents.ts");
reactHotLoader.register(getConsumptionValue, "getConsumptionValue", "/builds/web-et-numerique/llle_project/ecolyo/src/targets/services/aggregatorUsageEvents.ts");
reactHotLoader.register(calculateConsumptionVariation, "calculateConsumptionVariation", "/builds/web-et-numerique/llle_project/ecolyo/src/targets/services/aggregatorUsageEvents.ts");
reactHotLoader.register(sendEmailSubscription, "sendEmailSubscription", "/builds/web-et-numerique/llle_project/ecolyo/src/targets/services/aggregatorUsageEvents.ts");
reactHotLoader.register(aggregateEvents, "aggregateEvents", "/builds/web-et-numerique/llle_project/ecolyo/src/targets/services/aggregatorUsageEvents.ts");
reactHotLoader.register(AggregatorUsageEvents, "AggregatorUsageEvents", "/builds/web-et-numerique/llle_project/ecolyo/src/targets/services/aggregatorUsageEvents.ts");
})();
......@@ -39446,11 +39490,11 @@ var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoader
};
 
class UsageEventService {
/**
* addEvent
* @param {Client} client
* @param {AddEventParams} params
* @returns {Promise<UsageEvent>} usageEvent added
/**
* addEvent
* @param {Client} client
* @param {AddEventParams} params
* @returns {Promise<UsageEvent>} usageEvent added
*/
static async addEvent(client, params) {
const usageEvent = (0, _objectSpread2.default)({}, params, {
......@@ -39465,11 +39509,28 @@ class UsageEventService {
} = await client.create(_doctypes.USAGEEVENT_DOCTYPE, usageEvent);
return this.parseUsageEventEntityToUsageEvent(data);
}
/**
* updateUsageEventsAggregated
* @param {Client} client
* @param {string[]} ids
* @returns {Promise<boolean>} return true if all events are updated
/**
* addEvent
* @param {Client} client
* @param {AddEventParams} params
* @returns {Promise<UsageEvent>} usageEvent added
*/
static async addEventIfDoesntExist(client, params, filterParams) {
const events = await this.getEvents(client, filterParams);
if (events.length <= 0) {
return this.addEvent(client, params);
}
return null;
}
/**
* updateUsageEventsAggregated
* @param {Client} client
* @param {string[]} ids
* @returns {Promise<boolean>} return true if all events are updated
*/
 
 
......@@ -39486,11 +39547,11 @@ class UsageEventService {
 
return true;
}
/**
* getEvents
* @param {Client} client
* @param {MongoSelector} filterParams
* @returns {Promise<UsageEvent[]>} usageEvent added
/**
* getEvents
* @param {Client} client
* @param {MongoSelector} filterParams
* @returns {Promise<UsageEvent[]>} usageEvent added
*/
 
 
......@@ -39506,10 +39567,10 @@ class UsageEventService {
});
return usageEvents;
}
/**
* Retrieve UsageEvent from the UsageEventEntity
* @param {UsageEventEntity} usageEventEntity
* @returns {UsageEvent}
/**
* Retrieve UsageEvent from the UsageEventEntity
* @param {UsageEventEntity} usageEventEntity
* @returns {UsageEvent}
*/
 
 
......@@ -49064,6 +49125,7 @@ exports.UsageEventType = UsageEventType;
UsageEventType["ACTION_CHANGE_EVENT"] = "ActionChangeEvent";
UsageEventType["ACTION_END_EVENT"] = "ActionEndEvent";
UsageEventType["PROFILE_SET_EVENT"] = "ProfileSetEvent";
UsageEventType["REPORT_FROM_EMAIL"] = "ReportFromEvent";
})(UsageEventType || (exports.UsageEventType = UsageEventType = {}));
 
/***/ }),
......@@ -83410,6 +83472,7 @@ exports.DaccEvent = DaccEvent;
DaccEvent["NAVIGATION_ACTION_DAILY"] = "navigation-action-daily";
DaccEvent["EVENT_DURATION"] = "event-duration";
DaccEvent["QUIZ_STARS"] = "quiz-stars";
DaccEvent["SUMMARY_SUBSCRIPTION_MONTHLY"] = "summary-subscription-monthly";
})(DaccEvent || (exports.DaccEvent = DaccEvent = {}));
 
/***/ }),
......@@ -46661,13 +46661,26 @@ const monthlyReportNotification = async ({
}) => {
log('info', 'Fetching user profile...');
const upm = new _profile.default(client);
const userProfil = await upm.getProfile();
let userProfil = await upm.getProfile();
 
if (!userProfil || !userProfil.sendAnalysisNotification) {
log('info', 'End of process - Report Notification disabled in user profile');
return;
}
 
if (!userProfil.mailToken || userProfil.mailToken === '') {
const token = __webpack_require__(906).randomBytes(48).toString('hex');
try {
await upm.updateProfile({
mailToken: token
});
} catch (error) {
log('error', 'Update mailToken user profile error : ' + error);
throw error;
}
}
let username = '';
let url = '';
log('info', 'Fetching data for mail...'); // Retrieve public name from the stack
......@@ -46689,7 +46702,14 @@ const monthlyReportNotification = async ({
 
log('info', 'Creation of mail...');
const mailService = new _mail.default();
const mailContent = mailService.CreateBodyMonthlyReport(username, url);
userProfil = await upm.getProfile();
let token = undefined;
if (userProfil && userProfil.mailToken) {
token = userProfil.mailToken;
}
const mailContent = mailService.CreateBodyMonthlyReport(username, url, token);
const mailData = {
mode: 'noreply',
subject: '[Ecolyo] - Votre bilan mensuel',
......@@ -46793,7 +46813,7 @@ class MailService {
}
h2 {
font-size: 22px;
font-weight: 300;
}
.title {
......@@ -46873,7 +46893,7 @@ class MailService {
<tbody>
<tr>
<td
class="headerImg"
class="headerImg"
valign="middle"
align="center"
>
......@@ -46985,7 +47005,7 @@ class MailService {
style="color:#FFFFFF; font-size:16px;"
>
<p>
Bravo, vous faites partie des utilisateurs d’Ecolyo.
Bravo, vous faites partie des utilisateurs d’Ecolyo.
</p>
</div>
<div
......@@ -47030,7 +47050,7 @@ class MailService {
1 - Appuyez sur les trois petits points du menu en haut à droite.
</p>
<p style="margin: 0;">
2 - Sélectionnez "Ajouter à l'écran d'accueil".
2 - Sélectionnez "Ajouter à l'écran d'accueil".
</p>
<p style="margin: 0 0 1rem 0;">
3 - Nommez la page et appuyez sur "Ajouter". Un raccourci vers la page web est apparu sur l'écran d'accueil de votre smartphone.
......@@ -47087,7 +47107,7 @@ class MailService {
height="20"
/>
<span>OK j’ai compris</span>
</a>
</a>
</td>
</tr>
<tr>
......@@ -47095,7 +47115,7 @@ class MailService {
</tr>
<tr>
<td align="center">
<a class="link" href="${clientUrl}">${clientUrl}</a>
<a class="link" href="${clientUrl}">${clientUrl}</a>
</td>
</tr>
<tr>
......@@ -47176,12 +47196,16 @@ class MailService {
`;
}
 
CreateBodyMonthlyReport(username, clientUrl) {
CreateBodyMonthlyReport(username, clientUrl, token) {
let unsubscribeUrl;
 
if (!clientUrl.includes('analysis')) {
unsubscribeUrl = clientUrl + '/#/unsubscribe';
clientUrl = clientUrl + '/#/analysis';
if (token) {
clientUrl += '?token=' + token;
}
} else {
unsubscribeUrl = clientUrl.replace('analysis', 'unsubscribe');
}
......@@ -47220,7 +47244,7 @@ class MailService {
}
h2 {
font-size: 22px;
font-weight: 300;
}
.title {
......@@ -47300,7 +47324,7 @@ class MailService {
<tbody>
<tr>
<td
class="headerImg"
class="headerImg"
valign="middle"
align="center"
>
......@@ -47423,7 +47447,7 @@ class MailService {
</div>
</td>
</tr>
</tbody>
</table>
<table class="w580"
......@@ -47446,7 +47470,7 @@ class MailService {
height="20"
/>
<span>Voir mon bilan</span>
</a>
</a>
</td>
</tr>
<tr>
......@@ -47555,5 +47579,11 @@ exports.default = MailService;
})();
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(1)(module)))
 
/***/ }),
/* 906 */
/***/ (function(module, exports) {
module.exports = require("crypto");
/***/ })
/******/ ]);
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment