]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Allow to modify if people want to receive promotional updates
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Nov 2019 14:25:02 +0000 (14:25 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 21 Nov 2019 14:25:02 +0000 (14:25 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/accounts.py
src/backend/countries.py
src/templates/messages/base-promo.html
src/templates/people/index.html
src/templates/people/subscribe.html [new file with mode: 0644]
src/templates/people/subscribed.html [new file with mode: 0644]
src/templates/people/unsubscribe.html [new file with mode: 0644]
src/templates/people/unsubscribed.html [new file with mode: 0644]
src/web/__init__.py
src/web/people.py

index 7c618798651ac8b3ae9b80add786d3a671731590..53574dff5a41edddbc6eb66aa45a01d1d17e66e5 100644 (file)
@@ -275,6 +275,10 @@ templates_people_DATA = \
        src/templates/people/passwd.html \
        src/templates/people/search.html \
        src/templates/people/sip.html \
+       src/templates/people/subscribe.html \
+       src/templates/people/subscribed.html \
+       src/templates/people/unsubscribe.html \
+       src/templates/people/unsubscribed.html \
        src/templates/people/user.html \
        src/templates/people/user-edit.html \
        src/templates/people/users.html
index 2c9c47ec54fb32ded21e7e8d0d958c026940c671..bc284bffc1063046953004505dab3c1ecb9b2162 100644 (file)
@@ -366,6 +366,10 @@ class Accounts(Object):
                        first_name=res.first_name, last_name=res.last_name,
                        country_code=res.country_code)
 
+               # Non-EU users do not need to consent to promo emails
+               if account.country_code and not account.country_code in countries.EU_COUNTRIES:
+                       account.consents_to_promotional_emails = True
+
                # Invite newly registered users to newsletter
                self.backend.messages.send_template(
                        "newsletter/subscribe", address="%s <%s>" % (account, account.email))
@@ -1060,6 +1064,25 @@ class Account(LDAPObject):
                # Delete avatar hash
                self.memcache.delete("accounts:%s:avatar-hash" % self.dn)
 
+       # Consent to promotional emails
+
+       def get_consents_to_promotional_emails(self):
+               return self.is_member_of_group("promotional-consent")
+
+       def set_contents_to_promotional_emails(self, value):
+               group = self.backend.groups.get_by_gid("promotional-consent")
+               assert group, "Could not find group: promotional-consent"
+
+               if value is True:
+                       group.add_member(self)
+               else:
+                       group.del_member(self)
+
+       consents_to_promotional_emails = property(
+               get_consents_to_promotional_emails,
+               set_contents_to_promotional_emails,
+       )
+
 
 class StopForumSpam(Object):
        def init(self, uid, email, address):
@@ -1265,6 +1288,10 @@ class Group(LDAPObject):
                """
                        Adds a member to this group
                """
+               # Do nothing if this user is already in the group
+               if account.is_member_of_group(self.gid):
+                       return
+
                if "posixGroup" in self.objectclasses:
                        self._add_string("memberUid", account.uid)
                else:
@@ -1274,6 +1301,20 @@ class Group(LDAPObject):
                self.members.append(account)
                self.members.sort()
 
+       def del_member(self, account):
+               """
+                       Removes a member from a group
+               """
+               # Do nothing if this user is not in the group
+               if not account.is_member_of_group(self.gid):
+                       return
+
+               if "posixGroup" in self.objectclasses:
+                       self._delete_string("memberUid", account.uid)
+               else:
+                       self._delete_string("member", account.dn)
+
+
 if __name__ == "__main__":
        a = Accounts()
 
index d5a898fb8b9d5ad20069ae5d42251a4824a92f02..782c3fe1e6738c879074add52389c1624834d7c5 100644 (file)
@@ -40,6 +40,38 @@ ZONES = {
                        "PF", "PG", "PN", "PW", "SB", "TK", "TO", "TV", "UM", "VU", "WF", "WS"],
 }
 
+EU_COUNTRIES = (
+       "BE",
+       "BG",
+       "CZ",
+       "DK",
+       "DE",
+       "EE",
+       "IE",
+       "EL",
+       "ES",
+       "FR",
+       "FR",
+       "GB",
+       "HR",
+       "IT",
+       "CY",
+       "LV",
+       "LT",
+       "LU",
+       "HU",
+       "MT",
+       "NL",
+       "AT",
+       "PL",
+       "PT",
+       "RO",
+       "SI",
+       "SK",
+       "FI",
+       "SE",
+)
+
 def get_name(code):
        try:
                return iso3166.countries_by_alpha2[code].name
index 3c0815a9d073ba5f4f4bcea4ed1b0c8361b64d00..2c56f343ce7d94569798fc4d9348bf8afc0995b4 100644 (file)
@@ -2,5 +2,5 @@
 
 {% block footer %}
        {{ _("Don't like these emails?") }}
-       <a href="https://people.ipfire.org/">{{ _("Unsubscribe") }}</a>.
+       <a href="https://people.ipfire.org/unsubscribe">{{ _("Unsubscribe") }}</a>.
 {% end block %}
index f8173acd4f7309ad17eaa198a73bf51d4d5523b3..1fb58b56a516365daae434371a81f6d055146787 100644 (file)
                        </div>
                </div>
 
+               {% if not current_user.consents_to_promotional_emails %}
+                       <div class="card glow-primary border-primary">
+                               <div class="card-body">
+                                       <h6>{{ _("You are currently not subscribed to important updates from the IPFire Project") }}</h6>
+
+                       <div class="row">
+                           <div class="col-2 d-flex align-items-center justify-content-center">
+                               <i class="fas fa-envelope-open-text fa-3x text-primary"></i>
+                           </div>
+
+                           <div class="col-10 col-lg-6 mb-3 mb-lg-0">
+                               <p class="card-text">
+                                   {{ _("Subscribe to receive notifications about important security updates of IPFire and other news from inside the project") }}
+                               </p>
+                           </div>
+
+                           <div class="col-12 col-lg-4">
+                               <a class="btn btn-success btn-block" href="/subscribe">
+                                   {{ _("Subscribe Now") }}
+                               </a>
+                           </div>
+                       </div>
+                               </div>
+                       </div>
+               {% end %}
+
                {% if hints %}
                        <div class="card my-5">
                                <div class="card-body">
diff --git a/src/templates/people/subscribe.html b/src/templates/people/subscribe.html
new file mode 100644 (file)
index 0000000..864930d
--- /dev/null
@@ -0,0 +1,27 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Subscribe") }}{% end block %}
+
+{% block content %}
+       <div class="row justify-content-center my-5">
+               <div class="col col-md-8 col-lg-6">
+                       <div class="card border-success">
+                               <div class="card-body">
+                                       <h5>{{ _("Subscribe to Receive Import Updates from the IPFire Project") }}</h5>
+
+                                       <p>
+                                               {{ _("Subscribe to receive updates after releases and other important news from the IPFire Project.") }}
+                                       </p>
+
+                                       <form action="" method="POST">
+                                               {% raw xsrf_form_html() %}
+
+                                               <button type="submit" class="btn btn-success btn-block">
+                                                       {{ _("Subscribe") }}
+                                               </button>
+                                       </form>
+                               </div>
+                       </div>
+               </div>
+       </div>
+{% end block %}
diff --git a/src/templates/people/subscribed.html b/src/templates/people/subscribed.html
new file mode 100644 (file)
index 0000000..035b503
--- /dev/null
@@ -0,0 +1,19 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Thank You") }}{% end block %}
+
+{% block content %}
+       <div class="row justify-content-center my-5">
+               <div class="col-12 col-md-6">
+                       <div class="card bg-success text-white p-md-5">
+                               <div class="card-body text-center">
+                                       <span class="fas fa-check fa-5x my-4"></span>
+
+                                       <p class="lead">
+                                               {{ _("You have been subscribed and will now receive updates from the IPFire Project.") }}
+                                       </p>
+                               </div>
+                       </div>
+               </div>
+       </div>
+{% end block %}
diff --git a/src/templates/people/unsubscribe.html b/src/templates/people/unsubscribe.html
new file mode 100644 (file)
index 0000000..e1e9009
--- /dev/null
@@ -0,0 +1,35 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Unsubscribe") }}{% end block %}
+
+{% block content %}
+       <div class="row justify-content-center my-5">
+               <div class="col col-md-8 col-lg-6">
+                       <div class="card border-danger">
+                               <div class="card-body">
+                                       <h5>{{ _("Unsubscribe From Updates From The IPFire Project") }}</h5>
+
+                                       <p>
+                                               {{ _("If you unsubscribe, you will no longer receive important emails from the IPFire Project.") }}
+                                       </p>
+
+                                       <form action="/subscribe" method="POST">
+                                               {% raw xsrf_form_html() %}
+
+                                               <button type="submit" class="btn btn-success btn-lg btn-block mb-3">
+                                                       {{ _("I want to continue receiving important updates") }}
+                                               </button>
+                                       </form>
+
+                                       <form action="/unsubscribe" method="POST">
+                                               {% raw xsrf_form_html() %}
+
+                                               <button type="submit" class="btn btn-danger btn-block">
+                                                       {{ _("Unsubscribe") }}
+                                               </button>
+                                       </form>
+                               </div>
+                       </div>
+               </div>
+       </div>
+{% end block %}
diff --git a/src/templates/people/unsubscribed.html b/src/templates/people/unsubscribed.html
new file mode 100644 (file)
index 0000000..caae804
--- /dev/null
@@ -0,0 +1,27 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ _("Thank You") }}{% end block %}
+
+{% block content %}
+       <div class="row justify-content-center my-5">
+               <div class="col-12 col-md-6">
+                       <div class="card bg-danger text-white p-md-5 mb-3">
+                               <div class="card-body text-center">
+                                       <span class="fas fa-check fa-5x my-4"></span>
+
+                                       <p class="lead">
+                                               {{ _("You have been unsubscribed and will no longer receive important updates from the IPFire Project.") }}
+                                       </p>
+                               </div>
+                       </div>
+
+                       <form action="" method="POST">
+                               {% raw xsrf_form_html() %}
+
+                               <button type="submit" class="btn btn-success btn-block">
+                                       {{ _("I want to continue receiving important updates") }}
+                               </button>
+                       </form>
+               </div>
+       </div>
+{% end block %}
index 4cead7808aa0795be7956ff72cc6da23acbbe821..41c3f6cdf466fd03eeb33b829eaa1d1432d562ce 100644 (file)
@@ -285,6 +285,10 @@ class Application(tornado.web.Application):
                        (r"/users/([a-z_][a-z0-9_-]{0,31})/passwd", people.UserPasswdHandler),
                        (r"/users/([a-z_][a-z0-9_-]{0,31})/sip", people.SIPHandler),
 
+                       # Promotional Consent Stuff
+                       (r"/subscribe", people.SubscribeHandler),
+                       (r"/unsubscribe", people.UnsubscribeHandler),
+
                        # Single-Sign-On for Discourse
                        (r"/sso/discourse", people.SSODiscourse),
 
index dfc02b5544ed778b5e96386674543dd208334319..893a80634fab060d722bb305e7750fc1277f35a1 100644 (file)
@@ -158,6 +158,38 @@ class SearchHandler(auth.CacheMixin, base.BaseHandler):
                self.render("people/search.html", q=q, accounts=accounts)
 
 
+class SubscribeHandler(auth.CacheMixin, base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self):
+               if self.current_user.consents_to_promotional_emails:
+                       return self.render("people/subscribed.html")
+
+               self.render("people/subscribe.html")
+
+       @tornado.web.authenticated
+       def post(self):
+               # Give consent
+               self.current_user.consents_to_promotional_emails = True
+
+               self.render("people/subscribed.html")
+
+
+class UnsubscribeHandler(auth.CacheMixin, base.BaseHandler):
+       @tornado.web.authenticated
+       def get(self):
+               if self.current_user.consents_to_promotional_emails:
+                       return self.render("people/unsubscribe.html")
+
+               self.render("people/unsubscribed.html")
+
+       @tornado.web.authenticated
+       def post(self):
+               # Withdraw consent
+               self.current_user.consents_to_promotional_emails = False
+
+               self.render("people/unsubscribed.html")
+
+
 class SIPHandler(auth.CacheMixin, base.BaseHandler):
        @tornado.web.authenticated
        def get(self, uid):