Browse Source

Cleans up following PEP8 rules

Adrien Panay 7 years ago
parent
commit
0de820c46d
1 changed files with 11 additions and 10 deletions
  1. 11 10
      tracim/tracim/lib/auth/internal.py

+ 11 - 10
tracim/tracim/lib/auth/internal.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 from typing import Dict
2
 from typing import Dict
3
 
3
 
4
-from sqlalchemy import and_
5
 from tg.configuration.auth import TGAuthMetadata
4
 from tg.configuration.auth import TGAuthMetadata
6
 
5
 
7
 from tracim.lib.auth.base import Auth
6
 from tracim.lib.auth.base import Auth
13
     name = 'internal'
12
     name = 'internal'
14
     _internal = True
13
     _internal = True
15
 
14
 
16
-    def feed_config(self):
17
-        """
18
-        Fill config with internal (database) auth information.
19
-        :return:
20
-        """
15
+    def feed_config(self) -> None:
16
+        """Fill config with internal (database) auth information."""
21
         super().feed_config()
17
         super().feed_config()
22
         self._config['sa_auth'].user_class = User
18
         self._config['sa_auth'].user_class = User
23
         self._config['auth_backend'] = 'sqlalchemy'
19
         self._config['auth_backend'] = 'sqlalchemy'
24
         self._config['sa_auth'].dbsession = DBSession
20
         self._config['sa_auth'].dbsession = DBSession
25
-        self._config['sa_auth'].authmetadata = InternalApplicationAuthMetadata(self._config.get('sa_auth'))
21
+        self._config['sa_auth'].authmetadata = \
22
+            InternalApplicationAuthMetadata(self._config.get('sa_auth'))
26
 
23
 
27
 
24
 
28
 class InternalApplicationAuthMetadata(TGAuthMetadata):
25
 class InternalApplicationAuthMetadata(TGAuthMetadata):
26
+
29
     def __init__(self, sa_auth):
27
     def __init__(self, sa_auth):
30
         self.sa_auth = sa_auth
28
         self.sa_auth = sa_auth
31
 
29
 
36
             allow_auth_token: bool = False,
34
             allow_auth_token: bool = False,
37
     ) -> str:
35
     ) -> str:
38
         """
36
         """
39
-        Authenticates using given credentials.
37
+        Authenticate using given credentials.
40
 
38
 
41
         Checks password first then auth token if allowed.
39
         Checks password first then auth token if allowed.
42
         :param environ:
40
         :param environ:
60
         return result
58
         return result
61
 
59
 
62
     def get_user(self, identity, userid):
60
     def get_user(self, identity, userid):
63
-        return self.sa_auth.dbsession.query(self.sa_auth.user_class).filter(
64
-            and_(self.sa_auth.user_class.is_active == True, self.sa_auth.user_class.email == userid)).first()
61
+        return self.sa_auth.dbsession \
62
+            .query(self.sa_auth.user_class) \
63
+            .filter(self.sa_auth.user_class.is_active.is_(True)) \
64
+            .filter(self.sa_auth.user_class.email == userid) \
65
+            .first()
65
 
66
 
66
     def get_groups(self, identity, userid):
67
     def get_groups(self, identity, userid):
67
         return [g.group_name for g in identity['user'].groups]
68
         return [g.group_name for g in identity['user'].groups]