Gérer la fin de scolarité #9
2 changed files with 45 additions and 31 deletions
|
@ -89,7 +89,7 @@ class LongTermClipperAccountAdapter(DefaultSocialAccountAdapter):
|
||||||
def pre_social_login(self, request, sociallogin):
|
def pre_social_login(self, request, sociallogin):
|
||||||
clipper = sociallogin.account.uid
|
clipper = sociallogin.account.uid
|
||||||
try:
|
try:
|
||||||
a = SocialAccount.objects.get(provider='old_clipper',
|
a = SocialAccount.objects.get(provider='clipper_inactive',
|
||||||
uid=clipper)
|
uid=clipper)
|
||||||
# An account with that uid was registered, but potentially
|
# An account with that uid was registered, but potentially
|
||||||
# deprecated at the beginning of the year
|
# deprecated at the beginning of the year
|
||||||
|
@ -103,7 +103,6 @@ class LongTermClipperAccountAdapter(DefaultSocialAccountAdapter):
|
||||||
# But before that, we need to invalidate the email address of
|
# But before that, we need to invalidate the email address of
|
||||||
# the previous user
|
# the previous user
|
||||||
email = ldap_data.get('email')
|
email = ldap_data.get('email')
|
||||||
print(email, 'deprecate')
|
|
||||||
u_mails = EmailAddress.objects.filter(user=a.user)
|
u_mails = EmailAddress.objects.filter(user=a.user)
|
||||||
try:
|
try:
|
||||||
clipper_mail = u_mails.get(email=email)
|
clipper_mail = u_mails.get(email=email)
|
||||||
|
@ -138,7 +137,6 @@ class LongTermClipperAccountAdapter(DefaultSocialAccountAdapter):
|
||||||
return "{}@{}".format(clipper, data.get('annee', '00'))
|
return "{}@{}".format(clipper, data.get('annee', '00'))
|
||||||
|
|
||||||
def save_user(self, request, sociallogin, form=None):
|
def save_user(self, request, sociallogin, form=None):
|
||||||
print("populate user", sociallogin.account.uid)
|
|
||||||
user = sociallogin.user
|
user = sociallogin.user
|
||||||
user.set_unusable_password()
|
user.set_unusable_password()
|
||||||
|
|
||||||
|
@ -154,7 +152,6 @@ class LongTermClipperAccountAdapter(DefaultSocialAccountAdapter):
|
||||||
name_parts = (name or '').split(' ')
|
name_parts = (name or '').split(' ')
|
||||||
user_field(user, 'first_name', name_parts[0])
|
user_field(user, 'first_name', name_parts[0])
|
||||||
user_field(user, 'last_name', ' '.join(name_parts[1:]))
|
user_field(user, 'last_name', ' '.join(name_parts[1:]))
|
||||||
print(user.username, user)
|
|
||||||
|
|
||||||
# Ignore form
|
# Ignore form
|
||||||
get_account_adapter().populate_username(request, user)
|
get_account_adapter().populate_username(request, user)
|
||||||
|
|
|
@ -157,13 +157,13 @@ class LongTermClipperTests(CASTestCase):
|
||||||
_mock_ldap.reset()
|
_mock_ldap.reset()
|
||||||
|
|
||||||
def _setup_ldap(self, promo=12):
|
def _setup_ldap(self, promo=12):
|
||||||
_mock_ldap.set_return_value('search_s',
|
import ldap
|
||||||
('dc=spi,dc=ens,dc=fr,uid=test'),
|
_mock_ldap.directory['dc=spi,dc=ens,dc=fr']={
|
||||||
(
|
'uid': ['test'],
|
||||||
('cn', ('John Smith')),
|
'cn': ['John Smith'],
|
||||||
('mailRoutingAddress', ('test@clipper.ens.fr')),
|
'mailRoutingAddress' : ['test@clipper.ens.fr'],
|
||||||
('homeDirectory', ("/users/%d/phy/test/" % promo))
|
'homeDirectory': ["/users/%d/phy/test/" % promo],
|
||||||
))
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_new_connexion(self):
|
def test_new_connexion(self):
|
||||||
|
@ -180,6 +180,15 @@ class LongTermClipperTests(CASTestCase):
|
||||||
sa = list(SocialAccount.objects.all())[-1]
|
sa = list(SocialAccount.objects.all())[-1]
|
||||||
self.assertEqual(sa.user.id, u.id)
|
self.assertEqual(sa.user.id, u.id)
|
||||||
|
|
||||||
|
def test_connect_disconnect(self):
|
||||||
|
self._setup_ldap()
|
||||||
|
r0 = self.client_cas_login(self.client, provider_id="clipper", username="test")
|
||||||
|
self.assertIn("_auth_user_id", self.client.session)
|
||||||
|
self.assertIn('user', r0.context)
|
||||||
|
|
||||||
|
r1 = self.client.logout()
|
||||||
|
self.assertNotIn("_auth_user_id", self.client.session)
|
||||||
|
|
||||||
def test_second_connexion(self):
|
def test_second_connexion(self):
|
||||||
self._setup_ldap()
|
self._setup_ldap()
|
||||||
|
|
||||||
|
@ -201,34 +210,42 @@ class LongTermClipperTests(CASTestCase):
|
||||||
|
|
||||||
def test_reconnect_after_deprecation(self):
|
def test_reconnect_after_deprecation(self):
|
||||||
self._setup_ldap()
|
self._setup_ldap()
|
||||||
self.client_cas_login(self.client, provider_id="clipper", username="test")
|
r = self.client_cas_login(self.client, provider_id="clipper",
|
||||||
nsa = SocialAccount.objects.count()
|
username="test")
|
||||||
nu = User.objects.count()
|
user0 = r.context['user']
|
||||||
|
n_sa0 = SocialAccount.objects.count()
|
||||||
|
n_u0 = User.objects.count()
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
|
|
||||||
deprecate_clippers()
|
deprecate_clippers()
|
||||||
self.client_cas_login(self.client, provider_id="clipper", username="test")
|
|
||||||
|
|
||||||
sa = SocialAccount.objects.all()
|
r = self.client_cas_login(self.client, provider_id="clipper",
|
||||||
self.assertEqual(len(sa), nsa)
|
username="test")
|
||||||
u = User.objects.all()
|
user1 = r.context['user']
|
||||||
self.assertEqual(len(u), nu)
|
sa1 = list(SocialAccount.objects.all())
|
||||||
self.assertEqual(sa[-1].user.id, u[-1].id)
|
n_u1 = User.objects.count()
|
||||||
|
self.assertEqual(len(sa1), n_sa0)
|
||||||
|
self.assertEqual(n_u1, n_u0)
|
||||||
|
self.assertEqual(user1.id, user0.id)
|
||||||
|
|
||||||
def test_override_inactive_account(self):
|
def test_override_inactive_account(self):
|
||||||
self._setup_ldap(12)
|
self._setup_ldap(12)
|
||||||
self.client_cas_login(self.client, provider_id="clipper", username="test")
|
r = self.client_cas_login(self.client, provider_id="clipper",
|
||||||
nsa = SocialAccount.objects.count()
|
username="test")
|
||||||
nu = User.objects.count()
|
user0 = r.context['user']
|
||||||
|
n_sa0 = SocialAccount.objects.count()
|
||||||
|
n_u0 = User.objects.count()
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
|
|
||||||
deprecate_clippers()
|
deprecate_clippers()
|
||||||
|
|
||||||
self._setup_ldap(13)
|
self._setup_ldap(13)
|
||||||
self.client_cas_login(self.client, provider_id="clipper", username="test")
|
r = self.client_cas_login(self.client, provider_id="clipper",
|
||||||
|
username="test")
|
||||||
|
|
||||||
sa = SocialAccount.objects.all()
|
user1 = r.context['user']
|
||||||
self.assertEqual(len(sa), nsa+1)
|
sa1 = list(SocialAccount.objects.all())
|
||||||
u = User.objects.all()
|
n_u1 = User.objects.count()
|
||||||
self.assertEqual(len(u), nu+1)
|
self.assertEqual(len(sa1), n_sa0+1)
|
||||||
self.assertEqual(sa[-1].user.id, u[-1].id)
|
self.assertEqual(n_u1, n_u0+1)
|
||||||
|
self.assertNotEqual(user1.id, user0.id)
|
||||||
|
|
Loading…
Reference in a new issue