From 500f4f3ca9189321ff12128302d635314d94add8 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 07 2018 17:28:39 +0000 Subject: [PATCH 1/12] Updated README and dependency requirements --- diff --git a/README.md b/README.md index 06752fd..08daf0f 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,26 @@ # fedora-happiness-packets -This project conains the codebase for fedorahosted version of happinesspackets.io to be used during Appreciation week. +This project contains the codebase for fedora hosted version of happinesspackets.io to be used during Appreciation week. -Google Summer of Code Application Prerequisites for this projects are here: +# Setup -1. Create a FAS Id, join CommOps group +To run this project or the tests, you need to set up a virtualenv, install the dev requirements and set +the correct ``DJANGO_SETTINGS_MODULE``, for example with:: -2. Suscribe and send introductions to commops and summer-coding mailing lists. + virtualenv --no-site-packages --prompt='(happinesspackets)' virtualenv/ + source virtualenv/bin/activate + pip install -r requirements/dev.txt + export DJANGO_SETTINGS_MODULE=happinesspackets.settings.dev + ./manage.py collectstatic + python manage.py migrate + ./t -3. Ceate and share with us a Fedora wiki user page. For example, https://fedoraproject.org/wiki/User:Bee2502 +To run on http://127.0.0.1:8000/: -4. Follow the application process i.e create a subpage for your GSoC proposal and populate it with details. + python manage.py runserver -More info on that is here: https://docs.fedoraproject.org/mentored-projects/gsoc/2018/application.html +The ``t`` command is a very short shell script that runs the tests with the correct settings and reports on coverage. -Don't worry if you dont know everything i.e. the timeline. We can help you with that but fill as many details as you can. \ No newline at end of file +To run the integration tests:: + + ./manage.py test -v 2 -p integration_test*.py --settings=happinesspackets.settings.tsting diff --git a/requirements/base.txt b/requirements/base.txt index 971f15b..8295aa0 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -32,3 +32,5 @@ pep8==1.7.0 python-dateutil==2.5.0 factory-boy==2.9.2 opbeat==3.3 +mozilla-django-oidc==1.0.0 +fedmsg==1.1.1 From 23227b73439cb3b0c306a320eb7c883250b934e6 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 07 2018 18:42:47 +0000 Subject: [PATCH 2/12] Adds authentications --- diff --git a/README.md b/README.md index 08daf0f..cc08beb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ the correct ``DJANGO_SETTINGS_MODULE``, for example with:: python manage.py migrate ./t -To run on http://127.0.0.1:8000/: +To run on http://127.0.0.1:8000/ : python manage.py runserver diff --git a/happinesspackets/messaging/views.py b/happinesspackets/messaging/views.py index 8d939ed..eacbf4f 100644 --- a/happinesspackets/messaging/views.py +++ b/happinesspackets/messaging/views.py @@ -32,6 +32,11 @@ class StartView(ArchiveListView): def get_queryset(self): return super(StartView, self).get_queryset().order_by('?')[:2] + def get_context_data(self, **kwargs): + context = super(StartView, self).get_context_data(**kwargs) + user = self.request.user + return context + class FaqView(TemplateView): template_name = 'messaging/faq.html' diff --git a/happinesspackets/settings/base.py b/happinesspackets/settings/base.py index 42d9800..67d3824 100644 --- a/happinesspackets/settings/base.py +++ b/happinesspackets/settings/base.py @@ -12,11 +12,11 @@ BASE_DIR = PROJECT_DIR DEBUG = False ADMINS = ( - ('Sasha Romijn', 'github@mxsasha.eu'), + ('Anna Philips', 'ms.annaphilips@gmail.com'), ) SERVER_EMAIL = ADMINS[0][1] -DEFAULT_FROM_EMAIL = "Happiness Packets " +DEFAULT_FROM_EMAIL = "Happiness Packets " EMAIL_SUBJECT_PREFIX = "[happinesspackets] " @@ -60,11 +60,11 @@ STATICFILES_DIRS = ( # noinspection PyUnresolvedReferences MIDDLEWARE_CLASSES = [ + 'django.contrib.sessions.middleware.SessionMiddleware', 'happinesspackets.utils.middleware.SetRemoteAddrFromForwardedFor', 'opbeat.contrib.django.middleware.OpbeatAPMMiddleware', 'dogslow.WatchdogMiddleware', 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ] @@ -101,6 +101,7 @@ TEMPLATES = [ INSTALLED_APPS = [ 'django.contrib.auth', + 'mozilla_django_oidc', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', @@ -114,6 +115,20 @@ INSTALLED_APPS = [ 'happinesspackets.messaging', ] +AUTHENTICATION_BACKENDS = ( + 'mozilla_django_oidc.auth.OIDCAuthenticationBackend', +) + +OIDC_RP_SIGN_ALGO = 'RS256' +OIDC_RP_IDP_SIGN_KEY = '-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAq/0/XjILQxF3OaQZtFE3wVJ5UUuxZbxiJ/z+Zai0EOHiaMMxVyoo\nibDRen615r525DQ8TmQyR0eMQEpQ6SUvaOunahpYohgAkbkYggUMQhcoCLme18ZJ\nBTNWTP8w4t7mcuZd1cy1KtHpEvH4gkrjp8N3vIv1lzFraSc+p2rHMbV+AX5CJQ1H\nohBdwaqyOBKp0nzY27gu2EH2vzCwXkO4zGtrHfjjGc0Ra4WG+xz1AWg833xcFj3p\nqM3vca09jDLBme+GT151LcCCXRNyOZPZ3ZX62NxkMyqvVJHC3Uu2Q1hSHO7f6AZk\nZXY88PXXEH52T2ZrWiISowjTcGUboP8goQIDAQAB\n-----END RSA PUBLIC KEY-----\n' +OIDC_RP_CLIENT_ID = os.environ.get('OIDC_RP_CLIENT_ID') +OIDC_RP_CLIENT_SECRET = os.environ.get('OIDC_RP_CLIENT_SECRET') +OIDC_OP_AUTHORIZATION_ENDPOINT = "https://iddev.fedorainfracloud.org/openidc/Authorization" +OIDC_OP_TOKEN_ENDPOINT = "https://iddev.fedorainfracloud.org/openidc/Token" +OIDC_OP_USER_ENDPOINT = "https://iddev.fedorainfracloud.org/openidc/UserInfo" +LOGIN_REDIRECT_URL = "/" +LOGIN_REDIRECT_URL_FAILURE = "/error" +OIDC_RP_SCOPES = 'openid profile email' LOGGING = { 'version': 1, diff --git a/happinesspackets/settings/dev.py b/happinesspackets/settings/dev.py index 130cf59..f3c25ed 100644 --- a/happinesspackets/settings/dev.py +++ b/happinesspackets/settings/dev.py @@ -27,10 +27,11 @@ CSRF_COOKIE_SECURE = False ADMIN_ENABLED = True MIDDLEWARE_CLASSES = [ + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', 'happinesspackets.utils.middleware.SetRemoteAddrFromForwardedFor', 'dogslow.WatchdogMiddleware', 'django.middleware.common.CommonMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', diff --git a/happinesspackets/urls.py b/happinesspackets/urls.py index 8b231ea..375f4d3 100644 --- a/happinesspackets/urls.py +++ b/happinesspackets/urls.py @@ -6,6 +6,7 @@ from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ + url(r'^oidc/', include('mozilla_django_oidc.urls')), url(r'^', include('happinesspackets.messaging.urls', namespace="messaging")), ] diff --git a/templates/base.html b/templates/base.html index ae773ad..07b7cf6 100644 --- a/templates/base.html +++ b/templates/base.html @@ -34,6 +34,12 @@
  • FAQ
  • {% url 'messaging:archive' as url %}
  • Happiness Archive
  • + {% if user.is_authenticated %} + {{ user.email }}

    + {% else %} + {% url 'oidc_authentication_init' as url %} +
  • Login
  • + {% endif %} From c9304bb48a8b0c1b5797cea931397600269be17b Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 07 2018 19:19:25 +0000 Subject: [PATCH 3/12] Fix text bug --- diff --git a/templates/base.html b/templates/base.html index 07b7cf6..be54c05 100644 --- a/templates/base.html +++ b/templates/base.html @@ -35,7 +35,7 @@ {% url 'messaging:archive' as url %}
  • Happiness Archive
  • {% if user.is_authenticated %} - {{ user.email }}

    +
    {{ user.email }} {% else %} {% url 'oidc_authentication_init' as url %}
  • Login
  • From debeea824c1e13fdd82a9c7da9580c05efb30779 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 07 2018 19:25:11 +0000 Subject: [PATCH 4/12] Update the documentation --- diff --git a/README.md b/README.md index cc08beb..c57d7e5 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,10 @@ To run on http://127.0.0.1:8000/ : python manage.py runserver +Don't forget to start the mail server: + + python -m smtpd -n -c DebgingServer localhost:2525 + The ``t`` command is a very short shell script that runs the tests with the correct settings and reports on coverage. To run the integration tests:: From 167b7d909f7c386b7bd2ed6049dbc4f04453390e Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 07 2018 19:32:16 +0000 Subject: [PATCH 5/12] Fix typo --- diff --git a/README.md b/README.md index c57d7e5..7a83ec1 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ To run on http://127.0.0.1:8000/ : Don't forget to start the mail server: - python -m smtpd -n -c DebgingServer localhost:2525 + python -m smtpd -n -c DebuggingServer localhost:2525 The ``t`` command is a very short shell script that runs the tests with the correct settings and reports on coverage. From 8127e6668dbefd71f316c67bf8dbd9a535aff759 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 08 2018 23:51:12 +0000 Subject: [PATCH 6/12] Add logout --- diff --git a/happinesspackets/settings/base.py b/happinesspackets/settings/base.py index 67d3824..876a6a5 100644 --- a/happinesspackets/settings/base.py +++ b/happinesspackets/settings/base.py @@ -126,8 +126,9 @@ OIDC_RP_CLIENT_SECRET = os.environ.get('OIDC_RP_CLIENT_SECRET') OIDC_OP_AUTHORIZATION_ENDPOINT = "https://iddev.fedorainfracloud.org/openidc/Authorization" OIDC_OP_TOKEN_ENDPOINT = "https://iddev.fedorainfracloud.org/openidc/Token" OIDC_OP_USER_ENDPOINT = "https://iddev.fedorainfracloud.org/openidc/UserInfo" -LOGIN_REDIRECT_URL = "/" -LOGIN_REDIRECT_URL_FAILURE = "/error" +LOGIN_REDIRECT_URL = '/' +LOGOUT_REDIRECT_URL = '/' +LOGIN_REDIRECT_URL_FAILURE = '/error' OIDC_RP_SCOPES = 'openid profile email' LOGGING = { diff --git a/templates/base.html b/templates/base.html index be54c05..54fbc77 100644 --- a/templates/base.html +++ b/templates/base.html @@ -35,10 +35,20 @@ {% url 'messaging:archive' as url %}
  • Happiness Archive
  • {% if user.is_authenticated %} - {{ user.email }} +
    + {% csrf_token %} + +
    {% else %} - {% url 'oidc_authentication_init' as url %} -
  • Login
  • +
    + +
    {% endif %} From ec91e8049a6e2dd1e4985c50009d872f1661f3af Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 09 2018 00:04:18 +0000 Subject: [PATCH 7/12] Fix CSS for logout and login buttons --- diff --git a/assets/css/custom.css b/assets/css/custom.css index 8bb2f30..d564d63 100644 --- a/assets/css/custom.css +++ b/assets/css/custom.css @@ -154,6 +154,18 @@ blockquote { } } -.emoji { - vertical-align: initial; +.emoji { + vertical-align: initial; +} + +.btn-login, .btn-logout { + background: none; + color: white; + border: none; +} + +.btn-login:hover, .btn-logout:hover { + background: none; + color: white; + border: none; } diff --git a/templates/base.html b/templates/base.html index 54fbc77..b0a4d1d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -37,16 +37,16 @@ {% if user.is_authenticated %}
    {% csrf_token %} -
    {% else %}
    -
    {% endif %} From 111d2043a7d3f626db578e40175af566f5bf5454 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 09 2018 00:15:20 +0000 Subject: [PATCH 8/12] Change email --- diff --git a/templates/base.html b/templates/base.html index b0a4d1d..dde8d79 100644 --- a/templates/base.html +++ b/templates/base.html @@ -76,13 +76,9 @@
    Open-Source Happiness Packets is an - open-source project by - Sasha Romijn and - Mikey Ariel. + open-source project
    - Design and artwork by Ola Sitarska. -
    - Need help? info@happinesspackets.io + Need help? fedora.happinesspackets@gmail.com 💌 diff --git a/templates/base_email.html b/templates/base_email.html index 3e619d2..5b87e57 100644 --- a/templates/base_email.html +++ b/templates/base_email.html @@ -18,12 +18,9 @@

    Open-source happiness packets is an - open-source project by - Sasha Romijn and - Mikey Ariel. - Design and artwork by Ola Sitarska. + open-source project
    - Need help? info@happinesspackets.io + Need help? fedora.happinesspackets@gmail.com

    Never want to receive email from us again?
    From 21973341c838145f5a87c4e90257396d4d76f2ce Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 10 2018 19:09:48 +0000 Subject: [PATCH 9/12] Populate logged in user details --- diff --git a/happinesspackets/messaging/auth.py b/happinesspackets/messaging/auth.py new file mode 100644 index 0000000..a76e298 --- /dev/null +++ b/happinesspackets/messaging/auth.py @@ -0,0 +1,10 @@ +from mozilla_django_oidc.auth import OIDCAuthenticationBackend + +class OIDC(OIDCAuthenticationBackend): + def create_user(self, claims): + user = super(MyOIDCAB, self).create_user(claims) + user.first_name = claims.get('name', '') + user.username = claims.get('nickname', '') + user.email = claims.get('email', '') + user.save() + return user diff --git a/happinesspackets/messaging/forms.py b/happinesspackets/messaging/forms.py index 5ee57b3..0008103 100644 --- a/happinesspackets/messaging/forms.py +++ b/happinesspackets/messaging/forms.py @@ -30,7 +30,7 @@ class MessageSendForm(forms.ModelForm): class Meta: model = Message - fields = ['sender_name', 'sender_email', 'recipient_name', 'recipient_email', 'message', + fields = ['recipient_name', 'recipient_email', 'message', 'sender_named', 'sender_approved_public', 'sender_approved_public_named'] def __init__(self, *args, **kwargs): @@ -40,10 +40,6 @@ class MessageSendForm(forms.ModelForm): self.helper.label_class = 'col-md-3' self.helper.field_class = 'col-md-8' - self.fields['sender_name'].label = 'Name' - self.fields['sender_email'].label = 'Email' - self.fields['sender_email'].help_text = "We'll send you a confirmation link before sending your message out." - self.fields['sender_email'].validators = [validate_email] self.fields['recipient_name'].label = 'Name' self.fields['recipient_email'].label = 'Email' self.fields['recipient_email'].validators = [validate_email] @@ -54,7 +50,7 @@ class MessageSendForm(forms.ModelForm): self.fields['sender_approved_public_named'].help_text = "Note: We only publish information if both the sender and the recipients agree." self.helper.layout = Layout( - Fieldset('This Happiness Packet is from...', 'sender_name', 'sender_email', 'hp'), + # Fieldset('This Happiness Packet is from...', 'sender_name', 'sender_email', 'hp'), Fieldset("Send this Happiness Packet to...", 'recipient_name', 'recipient_email'), Fieldset("Your message is...", 'message'), Fieldset("Privacy and permissions", 'sender_named', 'sender_approved_public', 'sender_approved_public_named'), diff --git a/happinesspackets/messaging/views.py b/happinesspackets/messaging/views.py index eacbf4f..a86bfb7 100644 --- a/happinesspackets/messaging/views.py +++ b/happinesspackets/messaging/views.py @@ -11,6 +11,7 @@ from django.utils.decorators import method_decorator from django.utils.html import format_html from django.views.decorators.debug import sensitive_post_parameters from django.views.generic import FormView, TemplateView, UpdateView, ListView +from django.contrib.auth.mixins import LoginRequiredMixin from .forms import MessageSendForm, MessageRecipientForm from .models import Message, BLACKLIST_HMAC_SALT, BlacklistedEmail, strip_email @@ -77,8 +78,8 @@ class BlacklistEmailView(TemplateView): messages.success(self.request, message) return HttpResponseRedirect(self.success_url) - -class MessageSendView(FormView): +class MessageSendView(LoginRequiredMixin, FormView): + login_url = '/oidc/authenticate/' template_name = 'messaging/message_send_form.html' form_class = MessageSendForm @@ -89,6 +90,8 @@ class MessageSendView(FormView): def form_valid(self, form): message = form.save(commit=False) message.sender_ip = self.request.META['REMOTE_ADDR'] + message.sender_name = self.request.user.first_name + message.sender_email = self.request.user.email message.save() message.send_sender_confirmation(self.request.is_secure(), self.request.get_host()) return HttpResponseRedirect(reverse('messaging:sender_confirmation_sent')) diff --git a/happinesspackets/settings/base.py b/happinesspackets/settings/base.py index 876a6a5..f1a1367 100644 --- a/happinesspackets/settings/base.py +++ b/happinesspackets/settings/base.py @@ -116,7 +116,7 @@ INSTALLED_APPS = [ ] AUTHENTICATION_BACKENDS = ( - 'mozilla_django_oidc.auth.OIDCAuthenticationBackend', + 'happinesspackets.messaging.auth.OIDC', ) OIDC_RP_SIGN_ALGO = 'RS256' From ae1422bb321a017de1fb9f966c180bd156a9cfb7 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 21 2018 01:34:47 +0000 Subject: [PATCH 10/12] Update admins --- diff --git a/happinesspackets/messaging/auth.py b/happinesspackets/messaging/auth.py index a76e298..400d18c 100644 --- a/happinesspackets/messaging/auth.py +++ b/happinesspackets/messaging/auth.py @@ -2,7 +2,7 @@ from mozilla_django_oidc.auth import OIDCAuthenticationBackend class OIDC(OIDCAuthenticationBackend): def create_user(self, claims): - user = super(MyOIDCAB, self).create_user(claims) + user = super(OIDC, self).create_user(claims) user.first_name = claims.get('name', '') user.username = claims.get('nickname', '') user.email = claims.get('email', '') diff --git a/happinesspackets/settings/base.py b/happinesspackets/settings/base.py index f1a1367..ece8402 100644 --- a/happinesspackets/settings/base.py +++ b/happinesspackets/settings/base.py @@ -12,11 +12,13 @@ BASE_DIR = PROJECT_DIR DEBUG = False ADMINS = ( - ('Anna Philips', 'ms.annaphilips@gmail.com'), + ('Anna Philips', 'algogator@fedoraproject.org'), + ('Jona Azizaj', 'jonatoni@fedoraproject.org'), + ('Bhagyashree Uday', 'bee2502@fedoraproject.org'), ) SERVER_EMAIL = ADMINS[0][1] -DEFAULT_FROM_EMAIL = "Happiness Packets " +DEFAULT_FROM_EMAIL = "Happiness Packets " EMAIL_SUBJECT_PREFIX = "[happinesspackets] " From d927010f5041977bac12a9b86cbb9b32a9c20b69 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 26 2018 02:31:58 +0000 Subject: [PATCH 11/12] Make Name optional in user creation and remove hp --- diff --git a/happinesspackets/messaging/auth.py b/happinesspackets/messaging/auth.py index 400d18c..cf0b481 100644 --- a/happinesspackets/messaging/auth.py +++ b/happinesspackets/messaging/auth.py @@ -3,8 +3,11 @@ from mozilla_django_oidc.auth import OIDCAuthenticationBackend class OIDC(OIDCAuthenticationBackend): def create_user(self, claims): user = super(OIDC, self).create_user(claims) - user.first_name = claims.get('name', '') user.username = claims.get('nickname', '') user.email = claims.get('email', '') + try: + user.first_name = claims.get('name', '') + except: + user.first_name = user.username user.save() return user diff --git a/happinesspackets/messaging/forms.py b/happinesspackets/messaging/forms.py index 0008103..8b296e8 100644 --- a/happinesspackets/messaging/forms.py +++ b/happinesspackets/messaging/forms.py @@ -26,7 +26,7 @@ def validate_email(email): class MessageSendForm(forms.ModelForm): - hp = forms.CharField(label="do not fill", required=False) + # hp = forms.CharField(label="do not fill", required=False) class Meta: model = Message @@ -60,8 +60,8 @@ class MessageSendForm(forms.ModelForm): def clean(self): super(MessageSendForm, self).clean() - if self.cleaned_data.get('hp'): - raise forms.ValidationError('') + # if self.cleaned_data.get('hp'): + # raise forms.ValidationError('') if self.cleaned_data.get('sender_approved_public_named') and not self.cleaned_data.get('sender_approved_public'): self.add_error('sender_approved_public_named', "If you want us to publish the message including your names, " "you must also check 'I agree to publish this message and" From df8e50fffc70489d1515f16d0eedfdd6eb3ee688 Mon Sep 17 00:00:00 2001 From: Anna Philips Date: Jun 26 2018 02:32:34 +0000 Subject: [PATCH 12/12] Change footer text --- diff --git a/templates/base.html b/templates/base.html index dde8d79..945a86e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -75,8 +75,7 @@
    - Open-Source Happiness Packets is an - open-source project + Fedora Happiness Packets is a fork of Happiness Packets and part of GSoC 2018.
    Need help? fedora.happinesspackets@gmail.com 💌