~roadmr/canonical-identity-provider/fix-deprecation-warnings-1

« back to all changes in this revision

Viewing changes to src/identityprovider/models/account.py

  • Committer: Tom Wardill
  • Date: 2018-02-14 14:05:59 UTC
  • mfrom: (1602 work)
  • mto: (1597.1.44 django-1.10)
  • mto: This revision was merged to the branch mainline in revision 1603.
  • Revision ID: tom.wardill@canonical.com-20180214140559-ow5txzwy46nopws2
Merge flake8 changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
from django.contrib.auth.signals import user_logged_in
16
16
from django.core.exceptions import ValidationError
17
17
from django.core.urlresolvers import reverse
18
 
from django.db import models, IntegrityError
 
18
from django.db import IntegrityError, models
19
19
from django.utils.functional import cached_property
 
20
from django.utils.timezone import datetime, now, timedelta
20
21
from django.utils.translation import ugettext_lazy as _
21
22
from django.utils.timezone import datetime, now, timedelta
22
23
from oauth_backend.models import Consumer as V1Consumer, Token as V1Token
34
35
    generate_random_string_len_70,
35
36
    get_object_or_none,
36
37
)
37
 
 
38
38
from identityprovider.validators import Errors, get_password_validator
39
39
from webservices.launchpad import get_lp_username
40
40
 
60
60
    account.last_login = now()
61
61
    # there's no ned to save, as property handler does that
62
62
 
 
63
 
63
64
user_logged_in.connect(update_account_last_login)
64
65
 
65
66
 
201
202
 
202
203
    objects = AccountManager.from_queryset(AccountQuerySet)()
203
204
 
204
 
    OWNS_OR_IN_ANY_TEAM = """SELECT team.id
 
205
    IN_ANY_TEAM = """SELECT team.id
205
206
    FROM lp_person AS person
206
207
    JOIN lp_openididentifier ON person.account = lp_openididentifier.account
207
208
    JOIN lp_person AS team ON team.name = ANY(%s)
208
 
    LEFT OUTER JOIN lp_teamparticipation ON lp_teamparticipation.team = team.id
209
 
    WHERE lp_openididentifier.identifier = %s
210
 
    AND (lp_teamparticipation.person = person.id
211
 
         OR team.teamowner = person.id);
 
209
    JOIN lp_teamparticipation ON (lp_teamparticipation.team = team.id AND
 
210
                                  lp_teamparticipation.person = person.id)
 
211
    WHERE lp_openididentifier.identifier = %s;
212
212
    """
213
213
 
214
214
    class Meta:
361
361
                        email = emails[0]
362
362
 
363
363
                self._preferredemail = email
364
 
            except:
 
364
            except Exception:
365
365
                # no error in preferred email should raise, as this breaks
366
366
                # login completely
367
367
                logger.exception(
407
407
            team.name if isinstance(team, Person) else team
408
408
            for team in teams]
409
409
        teams = Person.objects.raw(
410
 
            self.OWNS_OR_IN_ANY_TEAM,
411
 
            params=(team_names, self.openid_identifier))
 
410
            self.IN_ANY_TEAM, params=(team_names, self.openid_identifier))
412
411
        result = len(list(teams)) > 0
413
412
        return result
414
413