Skip to content

Commit

Permalink
- OIDC 1.0 compliancy / notifications fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Jun 6, 2018
1 parent e7ddf9a commit 117bbdc
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 25 deletions.
2 changes: 0 additions & 2 deletions geonode/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ def user_info(request):
"groups": groups
})

print(" >>>>>>>>>>>>>>>>>>>>>>>>>> user_info %s " % user_info)

response = HttpResponse(
user_info,
content_type="application/json"
Expand Down
3 changes: 3 additions & 0 deletions geonode/base/fixtures/default_oauth_apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"pk": 1001,
"fields": {
"skip_authorization": true,
"created": "2018-05-31T10:00:31.661Z",
"updated": "2018-05-31T11:30:31.245Z",
"algorithm": "RS256",
"redirect_uris": "http://localhost:8080/geoserver/index.html\nhttp://localhost/geoserver/index.html",
"name": "GeoServer",
"authorization_grant_type": "authorization-code",
Expand Down
3 changes: 3 additions & 0 deletions geonode/base/fixtures/default_oauth_apps_docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"pk": 1001,
"fields": {
"skip_authorization": true,
"created": "2018-05-31T10:00:31.661Z",
"updated": "2018-05-31T11:30:31.245Z",
"algorithm": "RS256",
"redirect_uris": "http://geonode/geoserver",
"name": "GeoServer",
"authorization_grant_type": "authorization-code",
Expand Down
1 change: 1 addition & 0 deletions geonode/people/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def render_mail(self, template_prefix, email, context):
slug__in=user.groupmember_set.filter().values_list("group__slug", flat=True))
enhanced_context = context.copy()
enhanced_context.update({
"username": user.username,
"inviter_name": full_name or str(user),
"inviter_first_name": user.first_name or str(user),
"inviter_id": user.id,
Expand Down
44 changes: 42 additions & 2 deletions geonode/people/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,29 @@
#
#########################################################################

from uuid import uuid4

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.contrib.auth.models import AbstractUser, UserManager
from django.contrib.sites.models import Site
from django.db.models import signals
from django.conf import settings

from taggit.managers import TaggableManager

from geonode.base.enumerations import COUNTRIES
from geonode.groups.models import GroupProfile
from geonode.notifications_helper import send_notification
# from geonode.notifications_helper import send_notification

from allauth.account.signals import user_signed_up
from allauth.socialaccount.signals import social_account_added
# from account.models import EmailAddress

from .utils import format_address
from .signals import (update_user_email_addresses,
notify_admins_new_signup)
from .languages import LANGUAGES
from .timezones import TIMEZONES

Expand Down Expand Up @@ -174,7 +182,28 @@ def _notify_account_activated(self):
"""Notify user that its account has been activated by a staff member"""
became_active = self.is_active and not self._previous_active_state
if became_active and self.last_login is None:
send_notification(users=(self,), label="account_active")
try:
# send_notification(users=(self,), label="account_active")

from invitations.adapters import get_invitations_adapter
current_site = Site.objects.get_current()
ctx = {
'username': self.username,
'current_site': current_site,
'site_name': current_site.name,
'email': self.email,
'inviter': self,
}

email_template = 'pinax/notifications/account_active/account_active'

get_invitations_adapter().send_mail(
email_template,
self.email,
ctx)
except BaseException:
import traceback
traceback.print_exc()


def get_anonymous_user_instance(Profile):
Expand All @@ -194,4 +223,15 @@ def profile_post_save(instance, sender, **kwargs):
return


""" Connect relevant signals to their corresponding handlers. """
social_account_added.connect(
update_user_email_addresses,
dispatch_uid=str(uuid4()),
weak=False
)
user_signed_up.connect(
notify_admins_new_signup,
dispatch_uid=str(uuid4()),
weak=False
)
signals.post_save.connect(profile_post_save, sender=Profile)
21 changes: 2 additions & 19 deletions geonode/people/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@

import logging

from uuid import uuid4

from allauth.account.signals import user_signed_up
from allauth.socialaccount.signals import social_account_added

from allauth.account.models import EmailAddress
from django.contrib.auth import get_user_model
from django.db import IntegrityError
from django.db.models import Q

from geonode.notifications_helper import send_notification

Expand All @@ -57,22 +53,9 @@ def update_user_email_addresses(sender, **kwargs):


def notify_admins_new_signup(sender, **kwargs):
staff = get_user_model().objects.filter(is_staff=True)
staff = get_user_model().objects.filter(Q(is_active=True) & (Q(is_staff=True) | Q(is_superuser=True)))
send_notification(
users=staff,
label="account_approve",
extra_context={"from_user": kwargs["user"]}
)


""" Connect relevant signals to their corresponding handlers. """
social_account_added.connect(
update_user_email_addresses,
dispatch_uid=str(uuid4()),
weak=False
)
user_signed_up.connect(
notify_admins_new_signup,
dispatch_uid=str(uuid4()),
weak=False
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% load i18n %}

{% trans "Your account has been approved and is now active." %} ({{ username }})

{% trans "You can use the login form at" %}: http://{{ current_site.name }}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% load i18n %}{% trans "Welcome at" %} {{ current_site.name }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n %}

{% trans "Your account has been approved and is now active." %}:
{% trans "Your account has been approved and is now active." %}

{% trans "You can use the login form at" %}: http://{{ current_site }}
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ django-reversion<=2.0.13 # python-django-reversion (2.0.13 in our ppa)
django-suit<=0.2.26 # python-django-suit (0.2.26 in our ppa)
django-tastypie<=0.14.0 # python-django-tastypie (0.14.0 in our ppa)
django-invitations<=1.9.2 # python-django-invitations (1.9.2 in our ppa)
django-oauth-toolkit==1.1.2 # python-django-oauth-toolkit (0.12.0 in our ppa)
geonode-oauth-toolkit==1.1.2b0 # python-django-oauth-toolkit (0.12.0 in our ppa)
# djangorestframework<=3.7.7 # TODO
# djangorestframework-gis<=0.12 # TODO
# drf-nested-routers==0.90.0 # python-drf-nested-routers (0.90.0 in our ppa)
# drf-openapi==1.3.0 # python-drf-openapi (1.3.0 in our ppa)
oauthlib==2.1.0 # python-oauthlib (2.0.6 in our ppa) FIXME
requests-oauthlib==1.0.0

# geopython dependencies
pyproj>=1.9.5,<=1.9.5.1 # python-pyproj (1.9.5.1)
Expand Down
3 changes: 3 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def _prepare_oauth_fixture():
"pk": 1001,
"fields": {
"skip_authorization": True,
"created": "2018-05-31T10:00:31.661Z",
"updated": "2018-05-31T11:30:31.245Z",
"algorithm": "RS256",
"redirect_uris": "http://{0}:{1}/geoserver/index.html".format(
pub_ip, pub_port
),
Expand Down

0 comments on commit 117bbdc

Please sign in to comment.