From f8996899a68eb9a87b5e436189406bffc73762ef Mon Sep 17 00:00:00 2001
From: "guilhem.carron" <gcarron@grandlyon.com>
Date: Thu, 9 Sep 2021 16:42:16 +0200
Subject: [PATCH] Add terms consent doc

---
 docs/ecolyo/functionalities/terms.md         | 24 +++++++
 docs/ecolyo/project_architecture/doctypes.md | 69 +++++++++++++-------
 mkdocs.yml                                   |  1 +
 3 files changed, 70 insertions(+), 24 deletions(-)
 create mode 100644 docs/ecolyo/functionalities/terms.md

diff --git a/docs/ecolyo/functionalities/terms.md b/docs/ecolyo/functionalities/terms.md
new file mode 100644
index 0000000..ebc5bf9
--- /dev/null
+++ b/docs/ecolyo/functionalities/terms.md
@@ -0,0 +1,24 @@
+This section explains the way we handle terms in the application.
+
+## Description
+
+The terms version is handled with the _io.cozy.terms_ doctype. It is incremented each time we edit the CGU, the data consent validation or the legal notices. Once we increment the terms version, the user will be prompted to accept these terms, otherwise we won't be able to access the app.
+
+### Private Routes
+
+All routes are private, and are accessible only if the user has accepted the last version of the terms.
+The only public routes are :
+
+- _/terms_ : shows the terms validation page, and is the main page the user is redirected to if his consent is outdated
+- _/cgu_ : shows the CGU public page, accessible by the terms page
+- _/legal_ : shows the Legal Notice public page, accessible by the terms page
+
+### Terms managment
+
+We check the terms acceptation in the **SplashScreen** while the application is initializing, if there is no consent (first connexion), or the consent is outdated (update of terms), the user will be redirected to the terms acceptation page.
+User has to check the two checboxes (one for Data share consent, and one for CGU and Legal Notice) to unlock the terms acceptation button. Once he has accepted it, a new term doctype is created with the value _accepted_ to true. So he can access now the entire application.
+We store in user's profile a boolean _showConsentModal_ that allows the app to know about the consent status.
+
+### Version number
+
+The version number of the last terms is stored in the **config.json** file. If this version number doesn't correspond with the last term accepted, the user won't be able to access the app and wil be prompted to accept new terms.
diff --git a/docs/ecolyo/project_architecture/doctypes.md b/docs/ecolyo/project_architecture/doctypes.md
index 7a1df27..6facc0e 100644
--- a/docs/ecolyo/project_architecture/doctypes.md
+++ b/docs/ecolyo/project_architecture/doctypes.md
@@ -56,22 +56,23 @@ This doctype is used to store all information about the user.
 
 ### Structure
 
-| Field                    | Type                | Description                                                                                                                  |
-| ------------------------ | ------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
-| id                       | string              | Profile id                                                                                                                   |
-| ecogestureHash           | string              | Hash used to verify the content of ecogestures                                                                               |
-| challengeHash            | string              | Hash used to verify the content of challenges                                                                                |
-| duelHash                 | string              | Hash used to verify the content of duels                                                                                     |
-| quizHash                 | string              | Hash used to verify the content of quiz                                                                                      |
-| explorationHash          | string              | Hash used to verify the content of exploration                                                                               |
-| isFirstConnection        | boolean             | Boolean used to inform if the user connects for the first time                                                               |
-| lastConnectionDate       | DateTime            | Date of the last user connection                                                                                             |
-| haveSeenLastAnalysis     | boolean             | Boolean used to inform if user has seen the last analysis                                                                    |
-| haveSeenOldFluidModal    | Datetime or boolean | Used to inform if user has seen the modal display when his data are too old. Its value is false or a DateTime when he saw it |
-| sendAnalysisNotification | boolean             | Boolean used to inform if user has seen the analysis notification                                                            |
-| monthlyAnalysisDate      | DateTime            | Date of the last monthly analysis                                                                                            |
-| profileType              | ProfileType         | User consumption profile                                                                                                     |
-| isProfileTypeCompleted   | boolean             | Check if a user has completed his consumption profile                                                                        |
+| Field                    | Type                | Description                                                                                                                       |
+| ------------------------ | ------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
+| id                       | string              | Profile id                                                                                                                        |
+| ecogestureHash           | string              | Hash used to verify the content of ecogestures                                                                                    |
+| challengeHash            | string              | Hash used to verify the content of challenges                                                                                     |
+| duelHash                 | string              | Hash used to verify the content of duels                                                                                          |
+| quizHash                 | string              | Hash used to verify the content of quiz                                                                                           |
+| explorationHash          | string              | Hash used to verify the content of exploration                                                                                    |
+| isFirstConnection        | boolean             | Boolean used to inform if the user connects for the first time                                                                    |
+| lastConnectionDate       | DateTime            | Date of the last user connection                                                                                                  |
+| haveSeenLastAnalysis     | boolean             | Boolean used to inform if user has seen the last analysis                                                                         |
+| haveSeenOldFluidModal    | Datetime or boolean | Used to inform if user has seen the modal display when his data are too old. Its value is false or a DateTime when he saw it      |
+| sendAnalysisNotification | boolean             | Boolean used to inform if user has seen the analysis notification                                                                 |
+| monthlyAnalysisDate      | DateTime            | Date of the last monthly analysis                                                                                                 |
+| profileType              | ProfileType         | User consumption profile                                                                                                          |
+| isProfileTypeCompleted   | boolean             | Check if a user has completed his consumption profile                                                                             |
+| showConsentModal         | boolean             | Boolean used to show the terms acceptation page, and to protect the app private routes if last terms are not accepted or outdated |
 
 ### Example
 
@@ -109,7 +110,8 @@ This doctype is used to store all information about the user.
     "outsideFacingWalls": "2",
     "warmingFluid": 0
   },
-  "isProfileTypeCompleted": true
+  "isProfileTypeCompleted": true,
+  "showConsentModal": true
 }
 ```
 
@@ -619,10 +621,29 @@ This doctype is used to store all usage events.
 
 ### Structure
 
-| Field       | Type             | Description                            |
-| ----------- | ---------------- | -------------------------------------- |
-| date        | DateTime         | Date of the event                      |
-| type        | UsageEventType   | Type of the event                      |
-| target      | string           | Targeted konnector, page, challenge, quiz, exploration, action or timeStep                 |
-| result      | string           | Result for KonnectorConnectEvent or KonnectorRefreshEvent.<br>Values: "success" or "error"             |
-| context     | string           | Luxon Duration of the duel             |
\ No newline at end of file
+| Field   | Type           | Description                                                                                |
+| ------- | -------------- | ------------------------------------------------------------------------------------------ |
+| date    | DateTime       | Date of the event                                                                          |
+| type    | UsageEventType | Type of the event                                                                          |
+| target  | string         | Targeted konnector, page, challenge, quiz, exploration, action or timeStep                 |
+| result  | string         | Result for KonnectorConnectEvent or KonnectorRefreshEvent.<br>Values: "success" or "error" |
+| context | string         | Luxon Duration of the duel                                                                 |
+
+## Terms
+
+### Description
+
+This doctype is used to store the different version of the terms of the application.
+
+### Doctype
+
+**`io.cozy.terms`**
+
+### Structure
+
+| Field      | Type     | Description                                                       |
+| ---------- | -------- | ----------------------------------------------------------------- |
+| accepted   | boolean  | The fact that the terms has been accepted by the Cozy user or not |
+| acceptedAt | DateTime | The date when the Cozy user accepted these terms                  |
+| termsId    | string   | The id of the terms                                               |
+| version    | string   | The version number                                                |
diff --git a/mkdocs.yml b/mkdocs.yml
index a9f1ce3..91d8376 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -66,6 +66,7 @@ nav:
           - Analysis: ecolyo/functionalities/analysis.md
           - Usage events tracking: ecolyo/functionalities/usage_events_tracking.md
           - Feedback: ecolyo/functionalities/feedback.md
+          - Terms: ecolyo/functionalities/terms.md
   - Pilote:
       - Pilote - TS - Back:
           - Index: pilote/Pilote - TS - Back/index.md
-- 
GitLab