From 5db3d5a881c8facfdb200c6d873d4ceabecf4013 Mon Sep 17 00:00:00 2001
From: senza <maximesenzamici@gmail.com>
Date: Mon, 7 Mar 2022 11:58:20 +0100
Subject: [PATCH 1/3] Url shortner - View & url

---
 united4earth/server/models.py |  1 +
 united4earth/server/urls.py   |  3 ++-
 united4earth/server/views.py  | 17 ++++++++++++++++-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/united4earth/server/models.py b/united4earth/server/models.py
index 113df242d..a05a262db 100644
--- a/united4earth/server/models.py
+++ b/united4earth/server/models.py
@@ -20,6 +20,7 @@ User = get_user_model()
 
 
 
+
 class organisationSupport(Model):
   """Allow citizens to sign a text that is in an action group"""
   created_at = models.DateTimeField(auto_now_add=True)
diff --git a/united4earth/server/urls.py b/united4earth/server/urls.py
index f66990a35..1f3c4c2c1 100644
--- a/united4earth/server/urls.py
+++ b/united4earth/server/urls.py
@@ -19,7 +19,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
 from django.conf import settings
 from django.conf.urls.static import static
 from django.views import generic
-from .views import modulesToFundViewSet,modulesAvailableViewSet, IndexView
+from .views import modulesToFundViewSet,modulesAvailableViewSet, IndexView,shortLinkRedirect
 
 #translation imports
 from django.conf.urls.i18n import i18n_patterns
@@ -33,6 +33,7 @@ urlpatterns = [
     url(r'^i18n/', include('django.conf.urls.i18n')),
     url(r'^modules-to-fund/', modulesToFundViewSet.urls()),
     url(r'^modules-available/', modulesAvailableViewSet.urls()),
+    path("s/<str:slugs>", shortLinkRedirect, name="redirect"),
     url(r'^', IndexView.as_view(), name='index'),
     # url(r'^', generic.TemplateView.as_view(template_name='index.html'), name='index'),
 ]
diff --git a/united4earth/server/views.py b/united4earth/server/views.py
index 1b2cccf5f..b283093f1 100644
--- a/united4earth/server/views.py
+++ b/united4earth/server/views.py
@@ -34,4 +34,19 @@ class IndexView(APIView):
 
     print('context is',str(context))
     return render(request, "index.html", context)
-    
\ No newline at end of file
+  
+
+def shortLinkRedirect(request, slugs):
+  from risefor_lobbying.models import UrlShortner
+  from django.shortcuts import redirect
+  try:
+    #search for matching url in shortners
+    data = UrlShortner.objects.get(shortLink='/s/'+slugs)
+    frontUrl = data.url.replace(":","%3A")
+    #take URL and format it to front end Urls
+    finalUrl =  "/actions/action-group-detail/@"+frontUrl +"@"
+    #redirect
+    return redirect(finalUrl)
+  #if no match, redirect to actions listing
+  except (UrlShortner.DoesNotExist) or None:
+    return redirect("/actions")
\ No newline at end of file
-- 
GitLab


From 50d1cb526cd8dff74ae81f422b349f9ad8662fb3 Mon Sep 17 00:00:00 2001
From: senza <maximesenzamici@gmail.com>
Date: Mon, 7 Mar 2022 13:04:57 +0100
Subject: [PATCH 2/3] Shortlink remove backend, passed on to risefor lobbying

---
 united4earth/server/urls.py  |  3 +--
 united4earth/server/views.py | 18 +-----------------
 2 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/united4earth/server/urls.py b/united4earth/server/urls.py
index 1f3c4c2c1..f66990a35 100644
--- a/united4earth/server/urls.py
+++ b/united4earth/server/urls.py
@@ -19,7 +19,7 @@ from django.contrib.staticfiles.urls import staticfiles_urlpatterns
 from django.conf import settings
 from django.conf.urls.static import static
 from django.views import generic
-from .views import modulesToFundViewSet,modulesAvailableViewSet, IndexView,shortLinkRedirect
+from .views import modulesToFundViewSet,modulesAvailableViewSet, IndexView
 
 #translation imports
 from django.conf.urls.i18n import i18n_patterns
@@ -33,7 +33,6 @@ urlpatterns = [
     url(r'^i18n/', include('django.conf.urls.i18n')),
     url(r'^modules-to-fund/', modulesToFundViewSet.urls()),
     url(r'^modules-available/', modulesAvailableViewSet.urls()),
-    path("s/<str:slugs>", shortLinkRedirect, name="redirect"),
     url(r'^', IndexView.as_view(), name='index'),
     # url(r'^', generic.TemplateView.as_view(template_name='index.html'), name='index'),
 ]
diff --git a/united4earth/server/views.py b/united4earth/server/views.py
index b283093f1..8e7768450 100644
--- a/united4earth/server/views.py
+++ b/united4earth/server/views.py
@@ -33,20 +33,4 @@ class IndexView(APIView):
       context['representative'] = Representative.objects.get(id=request.path.split('/')[-2])
 
     print('context is',str(context))
-    return render(request, "index.html", context)
-  
-
-def shortLinkRedirect(request, slugs):
-  from risefor_lobbying.models import UrlShortner
-  from django.shortcuts import redirect
-  try:
-    #search for matching url in shortners
-    data = UrlShortner.objects.get(shortLink='/s/'+slugs)
-    frontUrl = data.url.replace(":","%3A")
-    #take URL and format it to front end Urls
-    finalUrl =  "/actions/action-group-detail/@"+frontUrl +"@"
-    #redirect
-    return redirect(finalUrl)
-  #if no match, redirect to actions listing
-  except (UrlShortner.DoesNotExist) or None:
-    return redirect("/actions")
\ No newline at end of file
+    return render(request, "index.html", context)
\ No newline at end of file
-- 
GitLab


From 9eff0b95676cefbe935296870b5a05357d849aaf Mon Sep 17 00:00:00 2001
From: senza <maximesenzamici@gmail.com>
Date: Mon, 7 Mar 2022 14:21:35 +0100
Subject: [PATCH 3/3] Shortlink - add new link to share buttons

---
 united4earth/static/js/main.js                            | 8 ++++++--
 .../templates/united4earth/action-group-detail-home.html  | 8 ++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/united4earth/static/js/main.js b/united4earth/static/js/main.js
index 7127af06d..f200c3cb3 100644
--- a/united4earth/static/js/main.js
+++ b/united4earth/static/js/main.js
@@ -560,7 +560,6 @@ function socialMediaShare(self){
   var shareButtons = self?.querySelectorAll("a");
   if (shareButtons) {
     shareButtons.forEach(shareButton => {
-      
       //listen to click on links
       shareButton.addEventListener("click", (e) => {
         //select classes to determine which platform was used
@@ -589,7 +588,12 @@ function socialMediaShare(self){
         //console.log("share text",shareText)
   
         //set home url
-        let currentPageUrl = location.href ;
+        let currentPageUrl = location.host + document.querySelector('solid-display-value[name="shortLink.shortLink"]').textContent;
+        
+        if (currentPageUrl == location.host) {
+          currentPageUrl = location.href;
+        }
+
         //remove anchor in URL, if there's one
         currentPageUrl = currentPageUrl.replace(/#\w+.*/,'');
         const whatsappUrl = "https://api.whatsapp.com/send?text=";
diff --git a/united4earth/templates/united4earth/action-group-detail-home.html b/united4earth/templates/united4earth/action-group-detail-home.html
index 5e39176fd..64e523396 100644
--- a/united4earth/templates/united4earth/action-group-detail-home.html
+++ b/united4earth/templates/united4earth/action-group-detail-home.html
@@ -2,7 +2,15 @@
 {% load staticfiles %}
 <div data-view="action-group-detail-home" id="action-group-detail-home" hidden>
   <div id="action-group-loader" hidden>{%trans "Loading..."%}</div>
+  <!-- Display shortlink used in Js -->
+  <solid-display
+    hidden
+    bind-resources
+    name="shortLink"
+    fields="shortLink.shortLink"
+  >
 
+  </solid-display>
 
   <section class="action-details background-gray p-5 mb-6">
     <div class="width-90 is-flex is-flex-direction-row">
-- 
GitLab