瀏覽代碼

Cleans up following PEP8 rules

Adrien Panay 7 年之前
父節點
當前提交
0de820c46d
共有 1 個文件被更改,包括 11 次插入10 次删除
  1. 11 10
      tracim/tracim/lib/auth/internal.py

+ 11 - 10
tracim/tracim/lib/auth/internal.py 查看文件

@@ -1,7 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from typing import Dict
3 3
 
4
-from sqlalchemy import and_
5 4
 from tg.configuration.auth import TGAuthMetadata
6 5
 
7 6
 from tracim.lib.auth.base import Auth
@@ -13,19 +12,18 @@ class InternalAuth(Auth):
13 12
     name = 'internal'
14 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 17
         super().feed_config()
22 18
         self._config['sa_auth'].user_class = User
23 19
         self._config['auth_backend'] = 'sqlalchemy'
24 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 25
 class InternalApplicationAuthMetadata(TGAuthMetadata):
26
+
29 27
     def __init__(self, sa_auth):
30 28
         self.sa_auth = sa_auth
31 29
 
@@ -36,7 +34,7 @@ class InternalApplicationAuthMetadata(TGAuthMetadata):
36 34
             allow_auth_token: bool = False,
37 35
     ) -> str:
38 36
         """
39
-        Authenticates using given credentials.
37
+        Authenticate using given credentials.
40 38
 
41 39
         Checks password first then auth token if allowed.
42 40
         :param environ:
@@ -60,8 +58,11 @@ class InternalApplicationAuthMetadata(TGAuthMetadata):
60 58
         return result
61 59
 
62 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 67
     def get_groups(self, identity, userid):
67 68
         return [g.group_name for g in identity['user'].groups]