From da0fcb833c119fa5b4ab42f113906a15ce4c55a3 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 06 2016 09:47:24 +0000
Subject: [PATCH 1/5] Add a welcome screen to new users of pagure


Fixes https://pagure.io/pagure/issue/1234

---

diff --git a/pagure/__init__.py b/pagure/__init__.py
index 66274b6..591d27e 100644
--- a/pagure/__init__.py
+++ b/pagure/__init__.py
@@ -96,6 +96,11 @@ if APP.config.get('PAGURE_AUTH', None) in ['fas', 'openid']:
     @FAS.postlogin
     def set_user(return_url):
         ''' After login method. '''
+        flask.session['_new_user'] = False
+        if not pagure.lib.search_user(
+                SESSION, username=flask.g.fas_user.username):
+            flask.session['_new_user'] = True
+
         try:
             pagure.lib.set_up_user(
                 session=SESSION,
@@ -353,12 +358,19 @@ def inject_variables():
                 namespace=namespace)
         return watch
 
+    new_user = False
+    if flask.session.get('_new_user'):
+        new_user = True
+        flask.flash('Welcome to pagure')
+        flask.session['_new_user'] = False
+
     return dict(
         version=__version__,
         admin=user_admin,
         authenticated=authenticated(),
         forkbuttonform=forkbuttonform,
         is_watching=is_watching,
+        new_user=new_user,
     )
 
 
diff --git a/pagure/templates/master.html b/pagure/templates/master.html
index e622b64..7d71fcc 100644
--- a/pagure/templates/master.html
+++ b/pagure/templates/master.html
@@ -127,6 +127,42 @@
         </div>
     </div>
 
+    {% if new_user %}
+    <div class="modal fade" id="welcome_screen" tabindex="-1"
+        role="dialog" aria-labelledby="add_group" aria-hidden="false">
+      <div class="modal-dialog" role="document">
+        <div class="modal-content">
+          <div class="modal-header">
+            <button type="button" class="close" data-dismiss="modal"
+                aria-label="Close">
+              <span aria-hidden="true">&times;</span>
+            </button>
+            <h4 class="modal-title" id="welcome_title">Welcome to Pagure {{ g.fas_user.username }}</h4>
+          </div>
+          <div class="modal-body">
+            <p>
+              We are glad to welcome you on pagure.
+            </p>
+            <p>
+              In order to get started with pagure, you may want to read
+              the <a href="https://docs.pagure.org/pagure/usage/first_steps.html">
+              First steps on Pagure</a> documentation.
+            </p>
+            <p>
+              You may also find some more information on how to use pagure
+              in the <a href="https://docs.pagure.org/pagure/usage.html">
+              usage section of the documentation</a>.
+            </p>
+          </div>
+          <div class="modal-footer">
+            <button type="button" class="btn btn-secondary"
+              data-dismiss="modal">Close</button>
+          </div>
+        </div>
+      </div>
+    </div>
+    {% endif %}
+
     {% block jscripts %}
     <script type="text/javascript"
         src="{{ url_for('static',
@@ -142,6 +178,13 @@
     <script type="text/javascript">
 $('[data-toggle="tooltip"]').tooltip({placement : 'bottom'});
     </script>
+    {% if new_user %}
+    <script type="text/javascript">
+    $(document).ready(function(){
+        $("#welcome_screen").modal('show');
+    });
+    </script>
+    {% endif %}
     {% endblock %}
 
 {% if config['FEDMENU_URL'] %}

From c2a3631f7031be8a06566a4b870ba69a8a65354c Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 06 2016 09:47:24 +0000
Subject: [PATCH 2/5] Small grammar improvements suggested by @tibbs, thanks!


---

diff --git a/pagure/templates/master.html b/pagure/templates/master.html
index 7d71fcc..c00cfc8 100644
--- a/pagure/templates/master.html
+++ b/pagure/templates/master.html
@@ -137,16 +137,18 @@
                 aria-label="Close">
               <span aria-hidden="true">&times;</span>
             </button>
-            <h4 class="modal-title" id="welcome_title">Welcome to Pagure {{ g.fas_user.username }}</h4>
+            <h4 class="modal-title" id="welcome_title">
+              Welcome to Pagure, {{ g.fas_user.username }}!
+            </h4>
           </div>
           <div class="modal-body">
             <p>
-              We are glad to welcome you on pagure.
+              We are glad to welcome you to pagure.
             </p>
             <p>
               In order to get started with pagure, you may want to read
               the <a href="https://docs.pagure.org/pagure/usage/first_steps.html">
-              First steps on Pagure</a> documentation.
+              First steps in Pagure</a> documentation.
             </p>
             <p>
               You may also find some more information on how to use pagure

From 1c318fa6a06818a02fcfd7bdd936ccb140d89f61 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 06 2016 09:47:24 +0000
Subject: [PATCH 3/5] Make the welcome screen an alert instead of a panel


---

diff --git a/pagure/templates/master.html b/pagure/templates/master.html
index c00cfc8..e227a20 100644
--- a/pagure/templates/master.html
+++ b/pagure/templates/master.html
@@ -112,6 +112,36 @@
                 </div>
                 {% endif %}
             {% endwith %}
+            {% if new_user %}
+              <div class="notification-spacer">
+                <div class="container p-t-2">
+                    <div class="alert alert-info alert-dismissible" role="alert">
+                      <button type="button" class="close" data-dismiss="alert" aria-label="Close">
+                        <span aria-hidden="true">&times;</span>
+                        <span class="sr-only">Close</span>
+                      </button>
+                      <h4 class="modal-title" id="welcome_title">
+                        Welcome to Pagure, {{ g.fas_user.username }}!
+                      </h4>
+                      <div class="modal-body">
+                        <p>
+                          We are glad to welcome you to pagure.
+                        </p>
+                        <p>
+                          In order to get started with pagure, you may want to read
+                          the <a href="https://docs.pagure.org/pagure/usage/first_steps.html">
+                          First steps in Pagure</a> documentation.
+                        </p>
+                        <p>
+                          You may also find some more information on how to use pagure
+                          in the <a href="https://docs.pagure.org/pagure/usage.html">
+                          usage section of the documentation</a>.
+                        </p>
+                      </div>
+                    </div>
+                </div>
+              </div>
+            {% endif %}
 
             {% block content %}{% endblock %}
     </div>
@@ -127,44 +157,6 @@
         </div>
     </div>
 
-    {% if new_user %}
-    <div class="modal fade" id="welcome_screen" tabindex="-1"
-        role="dialog" aria-labelledby="add_group" aria-hidden="false">
-      <div class="modal-dialog" role="document">
-        <div class="modal-content">
-          <div class="modal-header">
-            <button type="button" class="close" data-dismiss="modal"
-                aria-label="Close">
-              <span aria-hidden="true">&times;</span>
-            </button>
-            <h4 class="modal-title" id="welcome_title">
-              Welcome to Pagure, {{ g.fas_user.username }}!
-            </h4>
-          </div>
-          <div class="modal-body">
-            <p>
-              We are glad to welcome you to pagure.
-            </p>
-            <p>
-              In order to get started with pagure, you may want to read
-              the <a href="https://docs.pagure.org/pagure/usage/first_steps.html">
-              First steps in Pagure</a> documentation.
-            </p>
-            <p>
-              You may also find some more information on how to use pagure
-              in the <a href="https://docs.pagure.org/pagure/usage.html">
-              usage section of the documentation</a>.
-            </p>
-          </div>
-          <div class="modal-footer">
-            <button type="button" class="btn btn-secondary"
-              data-dismiss="modal">Close</button>
-          </div>
-        </div>
-      </div>
-    </div>
-    {% endif %}
-
     {% block jscripts %}
     <script type="text/javascript"
         src="{{ url_for('static',
@@ -180,13 +172,6 @@
     <script type="text/javascript">
 $('[data-toggle="tooltip"]').tooltip({placement : 'bottom'});
     </script>
-    {% if new_user %}
-    <script type="text/javascript">
-    $(document).ready(function(){
-        $("#welcome_screen").modal('show');
-    });
-    </script>
-    {% endif %}
     {% endblock %}
 
 {% if config['FEDMENU_URL'] %}

From 2eacfa5a833f9fcf963b778d35a313a5145c555d Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 06 2016 09:47:24 +0000
Subject: [PATCH 4/5] Drop this flash message, duplicates the welcome screen


---

diff --git a/pagure/__init__.py b/pagure/__init__.py
index 591d27e..45fed05 100644
--- a/pagure/__init__.py
+++ b/pagure/__init__.py
@@ -361,7 +361,6 @@ def inject_variables():
     new_user = False
     if flask.session.get('_new_user'):
         new_user = True
-        flask.flash('Welcome to pagure')
         flask.session['_new_user'] = False
 
     return dict(

From bc0554cb86f9b08ca7adc062ae3a955a346adedd Mon Sep 17 00:00:00 2001
From: Pierre-Yves Chibon <pingou@pingoured.fr>
Date: Oct 06 2016 09:57:47 +0000
Subject: [PATCH 5/5] Make the instance name configurable and reword a little the welcome screen


---

diff --git a/doc/configuration.rst b/doc/configuration.rst
index 0fdffef..f3e0e3b 100644
--- a/doc/configuration.rst
+++ b/doc/configuration.rst
@@ -530,3 +530,15 @@ the only CI service supported at the moment).
 Defaults to: ``None``.
 
 .. warning:: Requires `Redis` to be configured and running.
+
+
+INSTANCE_NAME
+~~~~~~~~~~~~~
+
+This allows giving a name to this running instance of pagure. The name is
+then used in the welcome screen showns upon first login.
+
+Defaults to: ``Pagure``
+
+.. note: the welcome screen currently does not work with the `local`
+         authentication.
diff --git a/pagure/default_config.py b/pagure/default_config.py
index 932d4d5..6b03967 100644
--- a/pagure/default_config.py
+++ b/pagure/default_config.py
@@ -21,6 +21,10 @@ SECRET_KEY = '<insert here your own key>'
 # url to the database server:
 DB_URL = 'sqlite:////var/tmp/pagure_dev.sqlite'
 
+# Name the instance, used in the welcome screen upon first login (not
+# working with `local` auth)
+INSTANCE_NAME = 'Pagure'
+
 # url to datagrepper (optional):
 #DATAGREPPER_URL = 'https://apps.fedoraproject.org/datagrepper'
 #DATAGREPPER_CATEGORY = 'pagure'
diff --git a/pagure/templates/master.html b/pagure/templates/master.html
index e227a20..d20f9be 100644
--- a/pagure/templates/master.html
+++ b/pagure/templates/master.html
@@ -116,20 +116,23 @@
               <div class="notification-spacer">
                 <div class="container p-t-2">
                     <div class="alert alert-info alert-dismissible" role="alert">
-                      <button type="button" class="close" data-dismiss="alert" aria-label="Close">
+                      <button type="button" class="close" data-dismiss="alert"
+                          aria-label="Close">
                         <span aria-hidden="true">&times;</span>
                         <span class="sr-only">Close</span>
                       </button>
                       <h4 class="modal-title" id="welcome_title">
-                        Welcome to Pagure, {{ g.fas_user.username }}!
+                        Welcome to {{ config['INSTANCE_NAME'] }}, {{ g.fas_user.username }}!
                       </h4>
                       <div class="modal-body">
                         <p>
                           We are glad to welcome you to pagure.
                         </p>
                         <p>
-                          In order to get started with pagure, you may want to read
-                          the <a href="https://docs.pagure.org/pagure/usage/first_steps.html">
+                          In order to get started with pagure, to set-up
+                          your preferred email address or your ssh key,
+                          you may want to read the
+                          <a href="https://docs.pagure.org/pagure/usage/first_steps.html">
                           First steps in Pagure</a> documentation.
                         </p>
                         <p>

