From d3ca96cd4101aa6cfa6523c68f8d891fbea15b76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Mon, 24 Oct 2022 18:00:30 +0200
Subject: [PATCH] legal extranet

---
 app/controllers/extranet/pages_controller.rb  | 12 ++++++
 app/models/communication/extranet.rb          |  1 +
 .../communication/extranet/with_legal.rb      | 19 +++++++++
 .../extranet/application/_footer.html.erb     | 12 +++---
 app/views/extranet/application/_nav.html.erb  | 42 ++++++++++---------
 .../extranet/gdpr/_cookie_consent.html.erb    | 10 +++++
 .../extranet/layouts/application.html.erb     |  2 +-
 app/views/extranet/layouts/devise.html.erb    |  2 +-
 .../extranet/pages/cookies_policy.html.erb    |  8 ++++
 .../extranet/pages/privacy_policy.html.erb    |  8 ++++
 .../extranet/pages/terms_of_service.html.erb  |  8 ++++
 config/routes/extranet.rb                     |  3 ++
 12 files changed, 99 insertions(+), 28 deletions(-)
 create mode 100644 app/controllers/extranet/pages_controller.rb
 create mode 100644 app/models/communication/extranet/with_legal.rb
 create mode 100644 app/views/extranet/gdpr/_cookie_consent.html.erb
 create mode 100644 app/views/extranet/pages/cookies_policy.html.erb
 create mode 100644 app/views/extranet/pages/privacy_policy.html.erb
 create mode 100644 app/views/extranet/pages/terms_of_service.html.erb

diff --git a/app/controllers/extranet/pages_controller.rb b/app/controllers/extranet/pages_controller.rb
new file mode 100644
index 000000000..90cfe247f
--- /dev/null
+++ b/app/controllers/extranet/pages_controller.rb
@@ -0,0 +1,12 @@
+class Extranet::PagesController < Extranet::ApplicationController
+  skip_before_action :authenticate_user!, :authorize_extranet_access!
+
+  def termes_of_use
+  end
+
+  def cookie_policy
+  end
+
+  def privacy_policy
+  end
+end
diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb
index 8437a8e4d..cd9c9bd78 100644
--- a/app/models/communication/extranet.rb
+++ b/app/models/communication/extranet.rb
@@ -33,6 +33,7 @@
 #
 class Communication::Extranet < ApplicationRecord
   include WithAbouts
+  include WithLegal
   include WithSso
   include WithUniversity
 
diff --git a/app/models/communication/extranet/with_legal.rb b/app/models/communication/extranet/with_legal.rb
new file mode 100644
index 000000000..a4420cd47
--- /dev/null
+++ b/app/models/communication/extranet/with_legal.rb
@@ -0,0 +1,19 @@
+module Communication::Extranet::WithLegal
+  extend ActiveSupport::Concern
+
+  included do
+    include ActionView::Helpers::SanitizeHelper
+  end
+
+  def has_terms?
+    strip_tags(terms).strip.present?
+  end
+
+  def has_cookies_policy?
+    strip_tags(cookies_policy).strip.present?
+  end
+
+  def has_privacy_policy?
+    strip_tags(privacy_policy).strip.present?
+  end
+end
diff --git a/app/views/extranet/application/_footer.html.erb b/app/views/extranet/application/_footer.html.erb
index ccb9d2c54..4f37174ad 100644
--- a/app/views/extranet/application/_footer.html.erb
+++ b/app/views/extranet/application/_footer.html.erb
@@ -25,17 +25,17 @@
 
       <nav class="text-md-end col-md-6">
         <%= link_to t('terms_of_service'),
-                    t('terms_of_service_url'),
+                    terms_of_service_path,
                     target: '_blank',
-                    rel: 'noreferrer' %>
+                    rel: 'noreferrer' if current_extranet.has_terms? %>
         <%= link_to t('privacy_policy'),
-                    t('privacy_policy_url'),
+                    privacy_policy_path,
                     target: '_blank',
-                    rel: 'noreferrer' %>
+                    rel: 'noreferrer' if current_extranet.has_privacy_policy? %>
         <%= link_to t('cookies_policy'),
-                    t('cookies_policy_url'),
+                    cookies_policy_path,
                     target: '_blank',
-                    rel: 'noreferrer' %>
+                    rel: 'noreferrer' if current_extranet.has_cookies_policy? %>
         <%= link_to t('cookies_consent_choice'),
                     '',
                     class: 'js-gdpr__cookie_consent__display_again' %>
diff --git a/app/views/extranet/application/_nav.html.erb b/app/views/extranet/application/_nav.html.erb
index df6f594d5..13e9921f6 100644
--- a/app/views/extranet/application/_nav.html.erb
+++ b/app/views/extranet/application/_nav.html.erb
@@ -3,25 +3,27 @@
     <a class="navbar-brand" href="/">
       <%= render 'logo' %>
     </a>
-    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#menu" aria-controls="menu" aria-expanded="false" aria-label="Toggle menu">
-      <%= t('extranet.menu') %> <span class="navbar-toggler-icon"></span>
-    </button>
-    <div class="collapse navbar-collapse" id="menu">
-      <%= render_navigation context: :extranet %>
-      <ul class="navbar-nav navbar-nav__account">
-        <li class="nav-item dropdown<%= ' active' if '/account'.in?(request.path) %>">
-          <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
-            <i class="bi bi-person-circle"></i>
-            <%= t('extranet.account.my') %>
-          </a>
-          <ul class="dropdown-menu dropdown-menu-end text-end">
-            <li><%= link_to current_user.to_s, account_path, class: "dropdown-item" %></li>
-            <li><%= link_to t('extranet.account.edit'), edit_account_path, class: "dropdown-item" %></li>
-            <li><%= link_to t('extranet.account.edit_personal_data'), edit_personal_data_path, class: "dropdown-item" %></li>
-            <li><%= link_to t('extranet.account.logout'), destroy_user_session_path, method: :delete, class: "dropdown-item" %></li>
-          </ul>
-        </li>
-      </ul>
-    </div>
+    <% if user_signed_in? %>
+      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#menu" aria-controls="menu" aria-expanded="false" aria-label="Toggle menu">
+        <%= t('extranet.menu') %> <span class="navbar-toggler-icon"></span>
+      </button>
+      <div class="collapse navbar-collapse" id="menu">
+        <%= render_navigation context: :extranet %>
+        <ul class="navbar-nav navbar-nav__account">
+          <li class="nav-item dropdown<%= ' active' if '/account'.in?(request.path) %>">
+            <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
+              <i class="bi bi-person-circle"></i>
+              <%= t('extranet.account.my') %>
+            </a>
+            <ul class="dropdown-menu dropdown-menu-end text-end">
+              <li><%= link_to current_user.to_s, account_path, class: "dropdown-item" %></li>
+              <li><%= link_to t('extranet.account.edit'), edit_account_path, class: "dropdown-item" %></li>
+              <li><%= link_to t('extranet.account.edit_personal_data'), edit_personal_data_path, class: "dropdown-item" %></li>
+              <li><%= link_to t('extranet.account.logout'), destroy_user_session_path, method: :delete, class: "dropdown-item" %></li>
+            </ul>
+          </li>
+        </ul>
+      </div>
+    <% end %>
   </div>
 </nav>
diff --git a/app/views/extranet/gdpr/_cookie_consent.html.erb b/app/views/extranet/gdpr/_cookie_consent.html.erb
new file mode 100644
index 000000000..3a1cfe18e
--- /dev/null
+++ b/app/views/extranet/gdpr/_cookie_consent.html.erb
@@ -0,0 +1,10 @@
+<div class="gdpr__cookie_consent js-gdpr__cookie_consent">
+  <div class="gdpr__cookie_consent__text">
+    <%= t('gdpr.cookie_consent.text') %>
+    <%= t('gdpr.cookie_consent.learn_more_html', link: cookies_policy_path) %>
+  </div>
+  <div class="gdpr__cookie_consent__buttons">
+    <button class="gdpr__cookie_consent__buttons__ok js-gdpr__cookie_consent__buttons__ok btn btn-primary btn-sm btn-xs"> <%= t('gdpr.cookie_consent.button_ok') %></button>
+    <button class="gdpr__cookie_consent__buttons__ko js-gdpr__cookie_consent__buttons__ko btn btn-primary btn-sm btn-xs"> <%= t('gdpr.cookie_consent.button_ko') %></button>
+  </div>
+</div>
\ No newline at end of file
diff --git a/app/views/extranet/layouts/application.html.erb b/app/views/extranet/layouts/application.html.erb
index 04e325e33..a887b371f 100644
--- a/app/views/extranet/layouts/application.html.erb
+++ b/app/views/extranet/layouts/application.html.erb
@@ -17,7 +17,7 @@
       <%= yield %>
     </main>
     <%= render 'extranet/application/footer' %>
-    <%= render 'gdpr/cookie_consent' %>
+    <%= render 'extranet/gdpr/cookie_consent' %>
     <%= render 'bugsnag' %>
   </body>
 </html>
diff --git a/app/views/extranet/layouts/devise.html.erb b/app/views/extranet/layouts/devise.html.erb
index dc9c6b8ab..c0e1e7413 100644
--- a/app/views/extranet/layouts/devise.html.erb
+++ b/app/views/extranet/layouts/devise.html.erb
@@ -34,7 +34,7 @@
       </div>
     </div>
     <%= render 'extranet/application/footer', hide_logo: true %>
-    <%= render 'gdpr/cookie_consent' %>
+    <%= render 'extranet/gdpr/cookie_consent' %>
     <%= render 'bugsnag' %>
   </body>
 </html>
diff --git a/app/views/extranet/pages/cookies_policy.html.erb b/app/views/extranet/pages/cookies_policy.html.erb
new file mode 100644
index 000000000..406e9d0b4
--- /dev/null
+++ b/app/views/extranet/pages/cookies_policy.html.erb
@@ -0,0 +1,8 @@
+<% content_for :title, Communication::Extranet.human_attribute_name('cookies_policy') %>
+<% content_for :header do %>
+  <h1><%= Communication::Extranet.human_attribute_name('cookies_policy') %></h1>
+<% end %>
+
+<div class="content">
+  <%= sanitize current_extranet.cookies_policy %>
+</div>
\ No newline at end of file
diff --git a/app/views/extranet/pages/privacy_policy.html.erb b/app/views/extranet/pages/privacy_policy.html.erb
new file mode 100644
index 000000000..f859cb73e
--- /dev/null
+++ b/app/views/extranet/pages/privacy_policy.html.erb
@@ -0,0 +1,8 @@
+<% content_for :title, Communication::Extranet.human_attribute_name('privacy_policy') %>
+<% content_for :header do %>
+  <h1><%= Communication::Extranet.human_attribute_name('privacy_policy') %></h1>
+<% end %>
+
+<div class="content">
+  <%= sanitize current_extranet.privacy_policy %>
+</div>
\ No newline at end of file
diff --git a/app/views/extranet/pages/terms_of_service.html.erb b/app/views/extranet/pages/terms_of_service.html.erb
new file mode 100644
index 000000000..070b82979
--- /dev/null
+++ b/app/views/extranet/pages/terms_of_service.html.erb
@@ -0,0 +1,8 @@
+<% content_for :title, Communication::Extranet.human_attribute_name('terms') %>
+<% content_for :header do %>
+  <h1><%= Communication::Extranet.human_attribute_name('terms') %></h1>
+<% end %>
+
+<div class="content">
+  <%= sanitize current_extranet.terms %>
+</div>
\ No newline at end of file
diff --git a/config/routes/extranet.rb b/config/routes/extranet.rb
index 513a41e59..3d5d9c7c7 100644
--- a/config/routes/extranet.rb
+++ b/config/routes/extranet.rb
@@ -15,4 +15,7 @@ scope :account do
   get 'personal_data' => 'extranet/personal_data#edit', as: :edit_personal_data
   patch 'personal_data' => 'extranet/personal_data#update', as: :personal_data
 end
+get 'terms-of-service' => 'extranet/pages#terms_of_service', as: :terms_of_service
+get 'privacy-policy' => 'extranet/pages#privacy_policy', as: :privacy_policy
+get 'cookies-policy' => 'extranet/pages#cookies_policy', as: :cookies_policy
 root to: 'extranet/home#index'
-- 
GitLab