Projet

Général

Profil

0001-auth_fc-always-fill-user_info-on-FcAccount-creation-.patch

Benjamin Dauvergne, 09 avril 2021 17:06

Télécharger (3,62 ko)

Voir les différences:

Subject: [PATCH] auth_fc: always fill user_info on FcAccount creation (#49797)

 src/authentic2_auth_fc/backends.py |  6 +++++-
 src/authentic2_auth_fc/models.py   |  5 ++++-
 src/authentic2_auth_fc/views.py    | 16 ++++++++++++++--
 3 files changed, 23 insertions(+), 4 deletions(-)
src/authentic2_auth_fc/backends.py
61 61
                user.save()
62 62
                try:
63 63
                    models.FcAccount.objects.create(
64
                        user=user, sub=sub, order=0, token=json.dumps(kwargs['token'])
64
                        user=user,
65
                        sub=sub,
66
                        order=0,
67
                        token=json.dumps(kwargs['token']),
68
                        user_info=json.dumps(user_info or {}),
65 69
                    )
66 70
                except IntegrityError:
67 71
                    # uniqueness check failed, as the user is new, it can only means that the sub is not unique
src/authentic2_auth_fc/models.py
102 102
        return json.loads(self.token)
103 103

  
104 104
    def get_user_info(self):
105
        return json.loads(self.user_info)
105
        if self.user_info:
106
            return json.loads(self.user_info)
107
        else:
108
            return {}
106 109

  
107 110
    def __str__(self):
108 111
        user_info = self.get_user_info()
src/authentic2_auth_fc/views.py
398 398
            # Prevent to add a link with an FC account already linked with another user.
399 399
            try:
400 400
                self.fc_account, created = models.FcAccount.objects.get_or_create(
401
                    sub=self.sub, user=request.user, order=0, defaults={'token': json.dumps(self.token)}
401
                    sub=self.sub,
402
                    user=request.user,
403
                    order=0,
404
                    defaults={
405
                        'token': json.dumps(self.token),
406
                        'user_info': json.dumps(self.user_info),
407
                    },
402 408
                )
403 409
            except IntegrityError:
404 410
                # unique index check failed, find why.
......
450 456
                    if not user.fc_accounts.exists():
451 457
                        try:
452 458
                            self.fc_account, created = models.FcAccount.objects.get_or_create(
453
                                defaults={'token': json.dumps(self.token)}, sub=self.sub, user=user, order=0
459
                                defaults={
460
                                    'token': json.dumps(self.token),
461
                                    'user_info': json.dumps(self.user_info),
462
                                },
463
                                sub=self.sub,
464
                                user=user,
465
                                order=0,
454 466
                            )
455 467
                        except IntegrityError:
456 468
                            # unique index check failed, find why.
457
-