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
 
6
 
7
 from tracim.models.auth import User
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
 class UserApi(object):
10
 class UserApi(object):
16
 
11
 
53
         if do_save:
48
         if do_save:
54
             self.save(user)
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
     def user_with_email_exists(self, email: str):
51
     def user_with_email_exists(self, email: str):
65
         try:
52
         try:
66
             self.get_one_by_email(email)
53
             self.get_one_by_email(email)
67
             return True
54
             return True
55
+        # TODO - G.M - 09-04-2018 - Better exception
68
         except:
56
         except:
69
             return False
57
             return False
70
 
58
 
115
         #     calendar_class=UserCalendar,
103
         #     calendar_class=UserCalendar,
116
         #     related_object_id=created_user.user_id,
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
 # based on this tutorial : https://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/auth/basic.html  # nopep8
21
 # based on this tutorial : https://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/auth/basic.html  # nopep8
22
 BASIC_AUTH_WEBUI_REALM = "tracim"
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
 def get_user(request: Request) -> typing.Optional[User]:
25
 def get_user(request: Request) -> typing.Optional[User]:
36
     """
26
     """
108
     return permissions
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
 class Root(object):
112
 class Root(object):
112
     """
113
     """
113
     Root of all Pyramid requests, used to store global acl
114
     Root of all Pyramid requests, used to store global acl

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

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

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

9
 
9
 
10
 def get_locale():
10
 def get_locale():
11
     # TODO - G.M - 27-03-2018 - [i18n] Reconnect true internationalization
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
     class K(object):
11
     class K(object):
12
         def __init__(self, obj, *args):
12
         def __init__(self, obj, *args):
13
             self.obj = obj
13
             self.obj = obj
14
+
14
         def __lt__(self, other):
15
         def __lt__(self, other):
15
             return mycmp(self.obj, other.obj) < 0
16
             return mycmp(self.obj, other.obj) < 0
17
+
16
         def __gt__(self, other):
18
         def __gt__(self, other):
17
             return mycmp(self.obj, other.obj) > 0
19
             return mycmp(self.obj, other.obj) > 0
20
+
18
         def __eq__(self, other):
21
         def __eq__(self, other):
19
             return mycmp(self.obj, other.obj) == 0
22
             return mycmp(self.obj, other.obj) == 0
23
+
20
         def __le__(self, other):
24
         def __le__(self, other):
21
             return mycmp(self.obj, other.obj) <= 0
25
             return mycmp(self.obj, other.obj) <= 0
26
+
22
         def __ge__(self, other):
27
         def __ge__(self, other):
23
             return mycmp(self.obj, other.obj) >= 0
28
             return mycmp(self.obj, other.obj) >= 0
29
+
24
         def __ne__(self, other):
30
         def __ne__(self, other):
25
             return mycmp(self.obj, other.obj) != 0
31
             return mycmp(self.obj, other.obj) != 0
32
+
26
     return K
33
     return K
27
 
34
 
35
+
28
 def current_date_for_filename() -> str:
36
 def current_date_for_filename() -> str:
29
     """
37
     """
30
     ISO8601 current date, adapted to be used in filename (for
38
     ISO8601 current date, adapted to be used in filename (for
32
     :return: current date as string like "2018-03-19T15.49.27.246592"
40
     :return: current date as string like "2018-03-19T15.49.27.246592"
33
     """
41
     """
34
     # INFO - G.M - 19-03-2018 - As ':' is in transform_to_bdd method in
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
     # a character which will not change in bdd.
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
     password = synonym('_password', descriptor=property(_get_password,
212
     password = synonym('_password', descriptor=property(_get_password,
213
                                                         _set_password))
213
                                                         _set_password))
214
 
214
 
215
-
216
     def validate_password(self, cleartext_password: str) -> bool:
215
     def validate_password(self, cleartext_password: str) -> bool:
217
         """
216
         """
218
         Check the password against existing credentials.
217
         Check the password against existing credentials.

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

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

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

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

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

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