Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #512 from praekelt/feature/reactivate-social-media
Browse files Browse the repository at this point in the history
Make social media sharing a setting to enable.
  • Loading branch information
rjacobs31 committed Mar 13, 2017
2 parents 23db80a + 7952c89 commit c0bba9a
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 78 deletions.
1 change: 1 addition & 0 deletions oneplus/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
def social_media(request):
from django.conf import settings
return {
'SOCIAL_MEDIA_ACTIVE': settings.SOCIAL_MEDIA_ACTIVE,
'FB_APP_NUM': settings.FB_APP_NUM,
'FB_REDIRECT': settings.FB_REDIRECT,
'FB_SITE_TITLE': settings.FB_SITE_TITLE,
Expand Down
11 changes: 10 additions & 1 deletion oneplus/public_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging

from django.conf import settings
from django.shortcuts import render
from django.shortcuts import redirect, render
from auth.models import Learner
from core.models import Participant, ParticipantBadgeTemplateRel
from gamification.models import GamificationBadgeTemplate
Expand All @@ -24,6 +24,9 @@ def get_learner_label(learner):

@oneplus_check_user
def badges(request, state, user):
if not settings.SOCIAL_MEDIA_ACTIVE:
return redirect('arrive')

def get():
badge_id = request.GET.get('b', None)
participant_id = request.GET.get('p', None)
Expand Down Expand Up @@ -77,6 +80,9 @@ def get():

@oneplus_check_user
def level(request, state, user):
if not settings.SOCIAL_MEDIA_ACTIVE:
return redirect('arrive')

def get():
participant_id = request.GET.get('p', None)

Expand Down Expand Up @@ -122,6 +128,9 @@ def get():

@oneplus_check_user
def leaderboard(request, state, user, board_type=''):
if not settings.SOCIAL_MEDIA_ACTIVE:
return redirect('arrive')

def get():
participant_id = request.GET.get('p', None)
max_uncollapsed = 3
Expand Down
6 changes: 6 additions & 0 deletions oneplus/sharing_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

@oneplus_participant_required
def level(request, state, user, participant):
if not settings.SOCIAL_MEDIA_ACTIVE:
return redirect('arrive')

# get learner state
_participant = participant
learner = _participant.learner
Expand Down Expand Up @@ -49,6 +52,9 @@ def get():

@oneplus_participant_required
def leaderboard(request, state, user, participant, board_type=''):
if not settings.SOCIAL_MEDIA_ACTIVE:
return redirect('arrive')

max_uncollapsed = 3

if board_type == 'class':
Expand Down
69 changes: 35 additions & 34 deletions oneplus/templates/core/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,41 +58,42 @@
<li><a class="footer-link" href="/signout">Log out</a></li>
{% endif %}
</ul>

<ul class="link-bar">
<li class="vert-center"><div>Tell your friends about us!</div></li>
<li class="js-required should-inline-block" style="display:none">
<a class="footer-link vert-center"
href="https://www.facebook.com/dialog/share?app_id={{ FB_APP_NUM|urlencode:'' }}&display=popup&href={{ FB_REDIRECT|urlencode:'' }}&redirect_uri={{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon fb-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://twitter.com/intent/tweet?text={{ "Check out Dig-it!"|urlencode:'' }}&url={{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon tw-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://plus.google.com/share?url={{ FB_REDIRECT|urlencode:'' }}" onclick="javascript:window.open(this.href,
'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
<img class="share-icon vert-center" src="https://www.gstatic.com/images/icons/gplus-32.png"
alt="Share on Google+"/>
</a>
</li>
<li>
<a href="whatsapp://send?text={{ "Check out Dig-it! "|urlencode:'' }}{{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon wa-logo vert-center"></div>
</a>
</li>
<script>
var jsRequiredClasses = document.querySelectorAll(".js-required.should-inline-block");
if (jsRequiredClasses) {
for (var counter = 0; counter < jsRequiredClasses.length; counter++) {
jsRequiredClasses[counter].style["display"] = 'inline-block';
{% if SOCIAL_MEDIA_ACTIVE %}
<ul class="link-bar">
<li class="vert-center"><div>Tell your friends about us!</div></li>
<li class="js-required should-inline-block" style="display:none">
<a class="footer-link vert-center"
href="https://www.facebook.com/dialog/share?app_id={{ FB_APP_NUM|urlencode:'' }}&display=popup&href={{ FB_REDIRECT|urlencode:'' }}&redirect_uri={{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon fb-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://twitter.com/intent/tweet?text={{ "Check out Dig-it!"|urlencode:'' }}&url={{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon tw-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://plus.google.com/share?url={{ FB_REDIRECT|urlencode:'' }}" onclick="javascript:window.open(this.href,
'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
<img class="share-icon vert-center" src="https://www.gstatic.com/images/icons/gplus-32.png"
alt="Share on Google+"/>
</a>
</li>
<li>
<a href="whatsapp://send?text={{ "Check out Dig-it! "|urlencode:'' }}{{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon wa-logo vert-center"></div>
</a>
</li>
<script>
var jsRequiredClasses = document.querySelectorAll(".js-required.should-inline-block");
if (jsRequiredClasses) {
for (var counter = 0; counter < jsRequiredClasses.length; counter++) {
jsRequiredClasses[counter].style["display"] = 'inline-block';
}
}
}
</script>
</ul>
</script>
</ul>
{% endif %}
</footer>
</body>
</html>
10 changes: 5 additions & 5 deletions oneplus/templates/learn/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1 class="color-accent">Hello, {{ user.name }}.</h1>
<h2>Great to see you again.</h2>
</hgroup>

{% comment %}Normal challenge{% endcomment %}
{# Normal challenge #}
{% if state.home_tasks_today < state.home_required_tasks %}
{% if not state.questions_complete %}
<article class="card pale-teal-accent border-color-accent">
Expand All @@ -35,7 +35,7 @@ <h3 class="card-top-phrase">Ready for today's challenge?</h3>
{% endif %}
{% endif %}

{% comment %}Current challenge stats{% endcomment %}
{# Current challenge stats #}
<article class="card sunflower-yellow-accent border-color-accent">
<section class="top">
<div class="img-container">
Expand Down Expand Up @@ -64,13 +64,13 @@ <h3 class="card-top-phrase">{{ feedback_string }}</h3>
{% endif %}
</article>

{% comment %}Overall stats{% endcomment %}
{# Overall stats #}
<article class="card squash-accent border-color-accent">
<section class="top">
<div class="img-container">
<img class="limit-size" src="/media/img/splash/splash_level_{{ level }}.png" width="100%" height="auto"/>
</div>
{% if public_sharing %}
{% if public_sharing and SOCIAL_MEDIA_ACTIVE %}
<a class="button border-color-accent color-accent" href="{% url 'share:level' %}">Share level and badge</a>
{% endif %}
<h1 class="center-font color-accent">Level</h1>
Expand Down Expand Up @@ -106,7 +106,7 @@ <h1 class="center-font color-accent">Level</h1>
</section>
</article>

{% comment %}Latest story{% endcomment %}
{# Latest story #}
{% if post %}
<article class="card amethyst-accent border-color-accent">
<section class="top">
Expand Down
2 changes: 1 addition & 1 deletion oneplus/templates/prog/leader.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{% load oneplus_extras %}

<article class="content squash-accent">
{% if allow_sharing %}
{% if allow_sharing and SOCIAL_MEDIA_ACTIVE %}
<article class="card border-color-accent" id="share-my">
<div class="text heading" >
<h3 class="card-top-phrase share-heading">Share my...</h3>
Expand Down
68 changes: 35 additions & 33 deletions oneplus/templates/public/public_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,42 @@
{% endif %}
</ul>

<ul class="link-bar">
<li class="vert-center"><div>Tell your friends about us!</div></li>
<li class="js-required should-inline-block" style="display:none">
<a class="footer-link vert-center"
href="https://www.facebook.com/dialog/share?app_id={{ FB_APP_NUM|urlencode:'' }}&display=popup&href={{ FB_REDIRECT|urlencode:'' }}&redirect_uri={{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon fb-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://twitter.com/intent/tweet?text={{ "Check out Dig-it!"|urlencode:'' }}&url={{ FB_REDIRECT|urlencode:'' }}" src="">
<div class="share-icon tw-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://plus.google.com/share?url={{ FB_REDIRECT|urlencode:'' }}" onclick="javascript:window.open(this.href,
'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
<img class="share-icon vert-center" src="https://www.gstatic.com/images/icons/gplus-32.png"
alt="Share on Google+"/>
</a>
</li>
<li>
<a href="whatsapp://send?text={{ "Check out Dig-it! "|urlencode:'' }}{{ FB_REDIRECT|urlencode:'' }}" src="">
<div class="share-icon wa-logo vert-center"></div>
</a>
</li>
<script>
var jsRequiredClasses = document.querySelectorAll(".js-required.should-inline-block");
if (jsRequiredClasses) {
for (var counter = 0; counter < jsRequiredClasses.length; counter++) {
jsRequiredClasses[counter].style["display"] = 'inline-block';
{% if SOCIAL_MEDIA_ACTIVE %}
<ul class="link-bar">
<li class="vert-center"><div>Tell your friends about us!</div></li>
<li class="js-required should-inline-block" style="display:none">
<a class="footer-link vert-center"
href="https://www.facebook.com/dialog/share?app_id={{ FB_APP_NUM|urlencode:'' }}&display=popup&href={{ FB_REDIRECT|urlencode:'' }}&redirect_uri={{ FB_REDIRECT|urlencode:'' }}">
<div class="share-icon fb-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://twitter.com/intent/tweet?text={{ "Check out Dig-it!"|urlencode:'' }}&url={{ FB_REDIRECT|urlencode:'' }}" src="">
<div class="share-icon tw-logo vert-center"></div>
</a>
</li>
<li class="js-required should-inline-block" style="display:none">
<a href="https://plus.google.com/share?url={{ FB_REDIRECT|urlencode:'' }}" onclick="javascript:window.open(this.href,
'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;">
<img class="share-icon vert-center" src="https://www.gstatic.com/images/icons/gplus-32.png"
alt="Share on Google+"/>
</a>
</li>
<li>
<a href="whatsapp://send?text={{ "Check out Dig-it! "|urlencode:'' }}{{ FB_REDIRECT|urlencode:'' }}" src="">
<div class="share-icon wa-logo vert-center"></div>
</a>
</li>
<script>
var jsRequiredClasses = document.querySelectorAll(".js-required.should-inline-block");
if (jsRequiredClasses) {
for (var counter = 0; counter < jsRequiredClasses.length; counter++) {
jsRequiredClasses[counter].style["display"] = 'inline-block';
}
}
}
</script>
</ul>
</script>
</ul>
{% endif %}
</footer>
</body>
</html>
28 changes: 26 additions & 2 deletions oneplus/tests/test_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def create_badgetemplate(name='badge template name', **kwargs):
**kwargs)


@override_settings(SOCIAL_MEDIA_ACTIVE=True)
class TestPublicBadge(TestCase):
def setUp(self):
self.course = create_course()
Expand Down Expand Up @@ -94,6 +95,13 @@ def setUp(self):

self.badge_await = create_badgetemplate(name='Awaiting Badge #1')

@override_settings(SOCIAL_MEDIA_ACTIVE=False)
def test_no_sm_badges(self):
resp = self.client.get(
'{0:s}?p={1:d}&b={2:d}'.format(reverse('public:badges'), 1, 1),
follow=True)
self.assertRedirects(resp, reverse('misc.onboarding'))

def test_no_perm(self):
self.learner.public_share = False
self.learner.save()
Expand Down Expand Up @@ -158,6 +166,7 @@ def test_invalid_badge(self):
self.assertContains(resp, "No one's home")


@override_settings(SOCIAL_MEDIA_ACTIVE=True)
class TestPublicLevel(TestCase):
def setUp(self):
self.course = create_course()
Expand All @@ -178,6 +187,13 @@ def setUp(self):
self.participant = create_participant(self.learner, self.classs, datejoined=datetime(2014, 7, 18, 1, 1))
self.module = create_module('module name', self.course)

@override_settings(SOCIAL_MEDIA_ACTIVE=False)
def test_no_sm_level(self):
resp = self.client.get(
'{0:s}?p={1:d}'.format(reverse('public:level'), 1),
follow=True)
self.assertRedirects(resp, reverse('misc.onboarding'))

def test_no_perm(self):
self.learner.public_share = False
self.learner.save()
Expand Down Expand Up @@ -250,6 +266,7 @@ def test_level_max(self):
self.assertContains(resp, '{0:s} {1:s} is awesome'.format(self.learner.first_name, self.learner.last_name))


@override_settings(SOCIAL_MEDIA_ACTIVE=True, VUMI_GO_FAKE=True)
class TestPublicLeaderboardSharing(TestCase):
def setUp(self):
self.course = create_course()
Expand All @@ -272,7 +289,14 @@ def setUp(self):
self.learner, self.classs, datejoined=datetime(2014, 7, 18, 1, 1))
self.module = create_module('module name', self.course)

@override_settings(VUMI_GO_FAKE=True)
@override_settings(SOCIAL_MEDIA_ACTIVE=False)
def test_no_sm_leader(self):
resp = self.client.get("{0:s}?p={1:d}".format(reverse('public:leaderboard',
kwargs={"board_type": 'class'}),
1),
follow=True)
self.assertRedirects(resp, reverse('misc.onboarding'))

def test_leaderboard_class(self):
#login learner
self.client.get(reverse('auth.autologin', kwargs={'token': self.learner.unique_token}))
Expand Down Expand Up @@ -333,4 +357,4 @@ def test_get_learner_label_all_names(self):
self.learner.save()

label = get_learner_label(self.learner)
self.assertEquals(label, 'blarg honk')
self.assertEquals(label, 'blarg honk')
Loading

0 comments on commit c0bba9a

Please sign in to comment.