Browse Source

comment + cleaning currentUser old code

Guénaël Muller 7 years ago
parent
commit
a06ce49993

+ 1 - 74
tracim/lib/core/user.py View File

@@ -6,11 +6,6 @@ import typing as typing
6 6
 
7 7
 from tracim.models.auth import User
8 8
 
9
-# TODO - G.M -28-03-2018 - [CurrentUser][auth]
10
-#  Check if "current user" stuff is always needed for tracimv2
11
-# CURRENT_USER_WEB = 'WEB'
12
-# CURRENT_USER_WSGIDAV = 'WSGIDAV'
13
-
14 9
 
15 10
 class UserApi(object):
16 11
 
@@ -53,18 +48,11 @@ class UserApi(object):
53 48
         if do_save:
54 49
             self.save(user)
55 50
 
56
-        if email and self._user and user.user_id==self._user.user_id:
57
-            pass
58
-            # this is required for the _session to keep on being up-to-date
59
-            # TODO - G.M - 28-03-2018 -
60
-            # [CurrentUser] Check for pyramid equivalent
61
-            # tg.request.identity['repoze.who.userid'] = email
62
-            # tg.auth_force_login(email)
63
-
64 51
     def user_with_email_exists(self, email: str):
65 52
         try:
66 53
             self.get_one_by_email(email)
67 54
             return True
55
+        # TODO - G.M - 09-04-2018 - Better exception
68 56
         except:
69 57
             return False
70 58
 
@@ -115,64 +103,3 @@ class UserApi(object):
115 103
         #     calendar_class=UserCalendar,
116 104
         #     related_object_id=created_user.user_id,
117 105
         # )
118
-
119
-
120
-# TODO - G.M - 28-03-2018 - [CurrentUser][auth] Check for pyramid equivalent
121
-# class CurrentUserGetterInterface(object):
122
-#     def get_current_user(self) -> typing.Union[None, User]:
123
-#         raise NotImplementedError()
124
-#
125
-#
126
-# class BaseCurrentUserGetter(CurrentUserGetterInterface):
127
-#     def __init__(self) -> None:
128
-#         self.api = UserApi(None)
129
-
130
-
131
-# class WebCurrentUserGetter(BaseCurrentUserGetter):
132
-#     def get_current_user(self) -> typing.Union[None, User]:
133
-#         # HACK - D.A. - 2015-09-02
134
-#         # In tests, the tg.request.identity may not be set
135
-#         # (this is a buggy case, but for now this is how the software is;)
136
-#         if tg.request is not None:
137
-#             if hasattr(tg.request, 'identity'):
138
-#                 if tg.request.identity is not None:
139
-#                     return self.api.get_one_by_email(
140
-#                         tg.request.identity['repoze.who.userid'],
141
-#                     )
142
-#
143
-#         return None
144
-
145
-# TODO - G.M - 28-03-2018 - [Webdav] Reenable Webdav stuff
146
-# class WsgidavCurrentUserGetter(BaseCurrentUserGetter):
147
-#     def get_current_user(self) -> typing.Union[None, User]:
148
-#         if hasattr(cherrypy.request, 'current_user_email'):
149
-#             return self.api.get_one_by_email(
150
-#                 cherrypy.request.current_user_email,
151
-#             )
152
-#
153
-#         return None
154
-
155
-
156
-# class CurrentUserGetterApi(object):
157
-#     thread_local = threading.local()
158
-#     matches = {
159
-#         CURRENT_USER_WEB: WebCurrentUserGetter,
160
-#         CURRENT_USER_WSGIDAV: WsgidavCurrentUserGetter,
161
-#     }
162
-#     default = CURRENT_USER_WEB
163
-#
164
-#     @classmethod
165
-#     def get_current_user(cls) -> User:
166
-#         try:
167
-#             return cls.thread_local.getter.get_current_user()
168
-#         except AttributeError:
169
-#             return cls.factory(cls.default).get_current_user()
170
-#
171
-#     @classmethod
172
-#     def set_thread_local_getter(cls, name) -> None:
173
-#         if not hasattr(cls.thread_local, 'getter'):
174
-#             cls.thread_local.getter = cls.factory(name)
175
-#
176
-#     @classmethod
177
-#     def factory(cls, name: str) -> CurrentUserGetterInterface:
178
-#         return cls.matches[name]()

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

@@ -21,16 +21,6 @@ from tracim.lib.core.userworkspace import RoleApi
21 21
 # based on this tutorial : https://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/auth/basic.html  # nopep8
22 22
 BASIC_AUTH_WEBUI_REALM = "tracim"
23 23
 
24
-# Global Permissions
25
-ADMIN_PERM = 'admin'
26
-MANAGE_GLOBAL_PERM = 'manage_global'
27
-USER_PERM = 'user'
28
-# Workspace-specific permission
29
-READ_PERM = 'read'
30
-CONTRIBUTE_PERM = 'contribute'
31
-MANAGE_CONTENT_PERM = 'manage_content'
32
-MANAGE_WORKSPACE_PERM = 'manage_workspace'
33
-
34 24
 
35 25
 def get_user(request: Request) -> typing.Optional[User]:
36 26
     """
@@ -108,6 +98,17 @@ def check_credentials(
108 98
     return permissions
109 99
 
110 100
 
101
+# Global Permissions
102
+ADMIN_PERM = 'admin'
103
+MANAGE_GLOBAL_PERM = 'manage_global'
104
+USER_PERM = 'user'
105
+# Workspace-specific permission
106
+READ_PERM = 'read'
107
+CONTRIBUTE_PERM = 'contribute'
108
+MANAGE_CONTENT_PERM = 'manage_content'
109
+MANAGE_WORKSPACE_PERM = 'manage_workspace'
110
+
111
+
111 112
 class Root(object):
112 113
     """
113 114
     Root of all Pyramid requests, used to store global acl

+ 3 - 0
tracim/lib/utils/logger.py View File

@@ -3,6 +3,9 @@ import logging
3 3
 
4 4
 
5 5
 class Logger(object):
6
+    """
7
+    Global logger
8
+    """
6 9
     TPL = '[{cls}] {msg}'
7 10
 
8 11
     def __init__(self, logger_name):

+ 1 - 1
tracim/lib/utils/translation.py View File

@@ -9,4 +9,4 @@ def fake_translator(text: str):
9 9
 
10 10
 def get_locale():
11 11
     # TODO - G.M - 27-03-2018 - [i18n] Reconnect true internationalization
12
-    return default_locale('LC_TIME')
12
+    return default_locale('LC_TIME')

+ 10 - 2
tracim/lib/utils/utils.py View File

@@ -11,20 +11,28 @@ def cmp_to_key(mycmp):
11 11
     class K(object):
12 12
         def __init__(self, obj, *args):
13 13
             self.obj = obj
14
+
14 15
         def __lt__(self, other):
15 16
             return mycmp(self.obj, other.obj) < 0
17
+
16 18
         def __gt__(self, other):
17 19
             return mycmp(self.obj, other.obj) > 0
20
+
18 21
         def __eq__(self, other):
19 22
             return mycmp(self.obj, other.obj) == 0
23
+
20 24
         def __le__(self, other):
21 25
             return mycmp(self.obj, other.obj) <= 0
26
+
22 27
         def __ge__(self, other):
23 28
             return mycmp(self.obj, other.obj) >= 0
29
+
24 30
         def __ne__(self, other):
25 31
             return mycmp(self.obj, other.obj) != 0
32
+
26 33
     return K
27 34
 
35
+
28 36
 def current_date_for_filename() -> str:
29 37
     """
30 38
     ISO8601 current date, adapted to be used in filename (for
@@ -32,6 +40,6 @@ def current_date_for_filename() -> str:
32 40
     :return: current date as string like "2018-03-19T15.49.27.246592"
33 41
     """
34 42
     # INFO - G.M - 19-03-2018 - As ':' is in transform_to_bdd method in
35
-    # webdav utils, it may cause trouble. So, it should be replaced to
43
+    # webdav utils, it may cause trouble. So, it should be replaced to
36 44
     # a character which will not change in bdd.
37
-    return datetime.datetime.now().isoformat().replace(':', '.')
45
+    return datetime.datetime.now().isoformat().replace(':', '.')

+ 0 - 1
tracim/models/auth.py View File

@@ -212,7 +212,6 @@ class User(DeclarativeBase):
212 212
     password = synonym('_password', descriptor=property(_get_password,
213 213
                                                         _set_password))
214 214
 
215
-
216 215
     def validate_password(self, cleartext_password: str) -> bool:
217 216
         """
218 217
         Check the password against existing credentials.

+ 1 - 1
tracim/views/__init__.py View File

@@ -1 +1 @@
1
-# -*- coding: utf-8 -*-
1
+# -*- coding: utf-8 -*-

+ 1 - 1
tracim/views/example_api/__init__.py View File

@@ -1 +1 @@
1
-# -*- coding: utf-8 -*-
1
+# -*- coding: utf-8 -*-

+ 1 - 1
tracim/views/example_api/schema.py View File

@@ -22,7 +22,7 @@ class UserSchema(marshmallow.Schema):
22 22
     id = marshmallow.fields.Int(required=True)
23 23
     username = marshmallow.fields.String(
24 24
         required=True,
25
-        validate = marshmallow.validate.Regexp(regex='[\w-]+'),
25
+        validate=marshmallow.validate.Regexp(regex='[\w-]+'),
26 26
     )
27 27
     email_address = marshmallow.fields.Email(required=True)
28 28
     first_name = marshmallow.fields.String(required=True)