Revision 7233d542
b/snf-astakos-app/astakos/im/activation_backends.py | ||
---|---|---|
41 | 41 |
send_activation, send_account_creation_notification, activate |
42 | 42 |
) |
43 | 43 |
from astakos.im.settings import ( |
44 |
INVITATIONS_ENABLED, MODERATION_ENABLED, RE_USER_EMAIL_PATTERNS
|
|
44 |
INVITATIONS_ENABLED, RE_USER_EMAIL_PATTERNS |
|
45 | 45 |
) |
46 |
from astakos.im import settings as astakos_settings |
|
46 | 47 |
from astakos.im.forms import * |
47 | 48 |
|
48 | 49 |
import astakos.im.messages as astakos_messages |
... | ... | |
102 | 103 |
if provider == request.POST.get('provider', ''): |
103 | 104 |
initial_data = request.POST |
104 | 105 |
return globals()[formclass](initial_data, instance=instance, request=request) |
105 |
|
|
106 |
|
|
106 | 107 |
def handle_activation( |
107 | 108 |
self, user, activation_template_name='im/activation_email.txt', |
108 | 109 |
greeting_template_name='im/welcome_email.txt', |
... | ... | |
119 | 120 |
try: |
120 | 121 |
if user.is_active: |
121 | 122 |
return RegistationCompleted() |
122 |
|
|
123 |
|
|
123 | 124 |
if self._is_preaccepted(user): |
124 | 125 |
if user.email_verified: |
125 | 126 |
activate(user, greeting_template_name) |
... | ... | |
196 | 197 |
return True |
197 | 198 |
invitation = self.invitation |
198 | 199 |
if not invitation: |
199 |
return False
|
|
200 |
return not astakos_settings.MODERATION_ENABLED
|
|
200 | 201 |
if invitation.username == user.email and not invitation.is_consumed: |
201 | 202 |
invitation.consume() |
202 | 203 |
return True |
... | ... | |
212 | 213 |
def _is_preaccepted(self, user): |
213 | 214 |
if super(SimpleBackend, self)._is_preaccepted(user): |
214 | 215 |
return True |
215 |
if MODERATION_ENABLED: |
|
216 |
if astakos_settings.MODERATION_ENABLED:
|
|
216 | 217 |
return False |
217 | 218 |
return True |
218 | 219 |
|
... | ... | |
236 | 237 |
class RegistationCompleted(ActivationResult): |
237 | 238 |
def __init__(self): |
238 | 239 |
message = _(astakos_messages.REGISTRATION_COMPLETED) |
239 |
super(RegistationCompleted, self).__init__(message) |
|
240 |
super(RegistationCompleted, self).__init__(message) |
b/snf-astakos-app/astakos/im/tests.py | ||
---|---|---|
339 | 339 |
settings.ADMINS = (('admin', 'support@cloud.grnet.gr'),) |
340 | 340 |
settings.SERVER_EMAIL = 'no-reply@grnet.gr' |
341 | 341 |
|
342 |
def test_invitations(self): |
|
343 |
return |
|
342 |
def test_no_moderation(self): |
|
343 |
astakos_settings.MODERATION_ENABLED = False |
|
344 |
r = self.client.get("/im/signup") |
|
345 |
self.assertEqual(r.status_code, 200) |
|
346 |
|
|
347 |
data = {'email':'kpap@grnet.gr', 'password1':'password', |
|
348 |
'password2':'password', 'first_name': 'Kostas', |
|
349 |
'last_name': 'Mitroglou', 'provider': 'local'} |
|
350 |
r = self.client.post("/im/signup", data) |
|
351 |
self.assertEqual(AstakosUser.objects.count(), 1) |
|
352 |
user = AstakosUser.objects.get(username="kpap@grnet.gr", |
|
353 |
email="kpap@grnet.gr") |
|
354 |
self.assertEqual(user.username, 'kpap@grnet.gr') |
|
355 |
self.assertEqual(user.has_auth_provider('local'), True) |
|
356 |
self.assertFalse(user.is_active) |
|
357 |
|
|
358 |
# user (not admin) gets notified |
|
359 |
self.assertEqual(len(get_mailbox('support@cloud.grnet.gr')), 0) |
|
360 |
self.assertEqual(len(get_mailbox('kpap@grnet.gr')), 1) |
|
361 |
astakos_settings.MODERATION_ENABLED = True |
|
344 | 362 |
|
345 | 363 |
def test_local_provider(self): |
364 |
astakos_settings.MODERATION_ENABLED = True |
|
346 | 365 |
r = self.client.get("/im/signup") |
347 | 366 |
self.assertEqual(r.status_code, 200) |
348 | 367 |
|
... | ... | |
356 | 375 |
self.assertEqual(user.username, 'kpap@grnet.gr') |
357 | 376 |
self.assertEqual(user.has_auth_provider('local'), True) |
358 | 377 |
self.assertFalse(user.is_active) |
378 |
self.assertFalse(user.email_verified) |
|
379 |
self.assertFalse(user.activation_sent) |
|
359 | 380 |
|
360 | 381 |
# admin gets notified |
361 | 382 |
self.assertEqual(len(get_mailbox('support@cloud.grnet.gr')), 1) |
Also available in: Unified diff