Commit 87f85fa3 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Proper MODERATION_ENABLED check when invitations are enabled

parent 72ae6397
......@@ -41,8 +41,9 @@ from astakos.im.functions import (
send_activation, send_account_creation_notification, activate
)
from astakos.im.settings import (
INVITATIONS_ENABLED, MODERATION_ENABLED, RE_USER_EMAIL_PATTERNS
INVITATIONS_ENABLED, RE_USER_EMAIL_PATTERNS
)
from astakos.im import settings as astakos_settings
from astakos.im.forms import *
import astakos.im.messages as astakos_messages
......@@ -102,7 +103,7 @@ class ActivationBackend(object):
if provider == request.POST.get('provider', ''):
initial_data = request.POST
return globals()[formclass](initial_data, instance=instance, request=request)
def handle_activation(
self, user, activation_template_name='im/activation_email.txt',
greeting_template_name='im/welcome_email.txt',
......@@ -119,7 +120,7 @@ class ActivationBackend(object):
try:
if user.is_active:
return RegistationCompleted()
if self._is_preaccepted(user):
if user.email_verified:
activate(user, greeting_template_name)
......@@ -196,7 +197,7 @@ class InvitationsBackend(ActivationBackend):
return True
invitation = self.invitation
if not invitation:
return False
return not astakos_settings.MODERATION_ENABLED
if invitation.username == user.email and not invitation.is_consumed:
invitation.consume()
return True
......@@ -212,7 +213,7 @@ class SimpleBackend(ActivationBackend):
def _is_preaccepted(self, user):
if super(SimpleBackend, self)._is_preaccepted(user):
return True
if MODERATION_ENABLED:
if astakos_settings.MODERATION_ENABLED:
return False
return True
......@@ -236,4 +237,4 @@ class NotificationSent(ActivationResult):
class RegistationCompleted(ActivationResult):
def __init__(self):
message = _(astakos_messages.REGISTRATION_COMPLETED)
super(RegistationCompleted, self).__init__(message)
\ No newline at end of file
super(RegistationCompleted, self).__init__(message)
......@@ -339,10 +339,29 @@ class LocalUserTests(TestCase):
settings.ADMINS = (('admin', 'support@cloud.grnet.gr'),)
settings.SERVER_EMAIL = 'no-reply@grnet.gr'
def test_invitations(self):
return
def test_no_moderation(self):
astakos_settings.MODERATION_ENABLED = False
r = self.client.get("/im/signup")
self.assertEqual(r.status_code, 200)
data = {'email':'kpap@grnet.gr', 'password1':'password',
'password2':'password', 'first_name': 'Kostas',
'last_name': 'Mitroglou', 'provider': 'local'}
r = self.client.post("/im/signup", data)
self.assertEqual(AstakosUser.objects.count(), 1)
user = AstakosUser.objects.get(username="kpap@grnet.gr",
email="kpap@grnet.gr")
self.assertEqual(user.username, 'kpap@grnet.gr')
self.assertEqual(user.has_auth_provider('local'), True)
self.assertFalse(user.is_active)
# user (not admin) gets notified
self.assertEqual(len(get_mailbox('support@cloud.grnet.gr')), 0)
self.assertEqual(len(get_mailbox('kpap@grnet.gr')), 1)
astakos_settings.MODERATION_ENABLED = True
def test_local_provider(self):
astakos_settings.MODERATION_ENABLED = True
r = self.client.get("/im/signup")
self.assertEqual(r.status_code, 200)
......@@ -356,6 +375,8 @@ class LocalUserTests(TestCase):
self.assertEqual(user.username, 'kpap@grnet.gr')
self.assertEqual(user.has_auth_provider('local'), True)
self.assertFalse(user.is_active)
self.assertFalse(user.email_verified)
self.assertFalse(user.activation_sent)
# admin gets notified
self.assertEqual(len(get_mailbox('support@cloud.grnet.gr')), 1)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment