1
1
# -*- coding: utf-8 -*-
2
2
3
+ from datetime import date
4
+ from datetime import datetime
3
5
from imio .helpers .cache import get_cachekey_volatile
4
6
from plone import api
5
7
from plone .memoize import ram as pmram
13
15
import os
14
16
15
17
16
- _ = MessageFactory (' imio.helpers' )
17
- logger = logging .getLogger (' imio.helpers' )
18
+ _ = MessageFactory (" imio.helpers" )
19
+ logger = logging .getLogger (" imio.helpers" )
18
20
21
+ HAS_PLONE_4 = api .env .plone_version ().startswith ("4" )
22
+ HAS_PLONE_5 = api .env .plone_version ().startswith ("5" )
23
+ HAS_PLONE_5_1 = api .env .plone_version () > "5.1"
24
+ HAS_PLONE_5_2 = api .env .plone_version () > "5.2"
19
25
HAS_PLONE_5_AND_MORE = int (api .env .plone_version ()[0 ]) >= 5
20
26
PLONE_MAJOR_VERSION = int (api .env .plone_version ()[0 ])
21
27
28
+ EMPTY_TITLE = "No value"
29
+ EMPTY_STRING = "__empty_string__"
30
+ EMPTY_DATE = date (1950 , 1 , 1 )
31
+ EMPTY_DATETIME = datetime (1950 , 1 , 1 , 12 , 0 )
32
+
22
33
23
34
def GroupsTool__getGroupsForPrincipal_cachekey (method , self , principal ):
24
35
req = getRequest ()
25
36
if req is None :
26
37
raise pmram .DontCache
27
- date = get_cachekey_volatile (' _users_groups_value' )
38
+ date = get_cachekey_volatile (" _users_groups_value" )
28
39
return date , principal and principal .getId ()
29
40
30
41
31
42
def GroupAwareRoleManager__getRolesForPrincipal_cachekey (method , self , principal , request = None ):
32
43
req = request or getRequest ()
33
44
# if req is None:
34
45
# raise pmram.DontCache
35
- date = get_cachekey_volatile ('_users_groups_value' )
36
- return (date , principal and principal .getId (), repr (req ), req and (req .get ('__ignore_direct_roles__' , False ),
37
- req .get ('__ignore_group_roles__' , False )) or (None , None ))
46
+ date = get_cachekey_volatile ("_users_groups_value" )
47
+ return (
48
+ date ,
49
+ principal and principal .getId (),
50
+ repr (req ),
51
+ req and (req .get ("__ignore_direct_roles__" , False ), req .get ("__ignore_group_roles__" , False )) or (None , None ),
52
+ )
38
53
39
54
40
55
def PluggableAuthService__getGroupsForPrincipal_cachekey (method , self , principal , request = None , ** kwargs ):
41
56
req = request or getRequest ()
42
57
if req is None :
43
58
raise pmram .DontCache
44
59
try :
45
- date = get_cachekey_volatile (' _users_groups_value' )
60
+ date = get_cachekey_volatile (" _users_groups_value" )
46
61
except api .portal .CannotGetPortalError :
47
62
raise pmram .DontCache
48
63
return date , principal and principal .getId ()
@@ -53,18 +68,18 @@ def PluggableAuthService__findUser_cachekey(method, self, plugins, user_id, name
53
68
if req is None :
54
69
raise pmram .DontCache
55
70
try :
56
- date = get_cachekey_volatile (' _users_groups_value' )
71
+ date = get_cachekey_volatile (" _users_groups_value" )
57
72
except api .portal .CannotGetPortalError :
58
73
raise pmram .DontCache
59
- return date , repr (plugins ), user_id , name , str (req and req ._debug or '' )
74
+ return date , repr (plugins ), user_id , name , str (req and req ._debug or "" )
60
75
61
76
62
77
def PluggableAuthService__verifyUser_cachekey (method , self , plugins , user_id = None , login = None ):
63
78
req = getRequest ()
64
79
if req is None :
65
80
raise pmram .DontCache
66
81
67
- date = get_cachekey_volatile (' _users_groups_value' )
82
+ date = get_cachekey_volatile (" _users_groups_value" )
68
83
return date , repr (plugins ), user_id , login
69
84
70
85
@@ -73,12 +88,12 @@ def GroupsTool_getGroupById_cachekey(method, self, group_id):
73
88
if req is None :
74
89
raise pmram .DontCache
75
90
76
- date = get_cachekey_volatile (' _users_groups_value' )
91
+ date = get_cachekey_volatile (" _users_groups_value" )
77
92
return date , group_id
78
93
79
94
80
- if os .getenv (' decorate_acl_methods' , ' Nope' ) in (' True' , ' true' ):
81
- logger .info (' DECORATING various acl related methods with cache' )
95
+ if os .getenv (" decorate_acl_methods" , " Nope" ) in (" True" , " true" ):
96
+ logger .info (" DECORATING various acl related methods with cache" )
82
97
decorator = pmram .cache (GroupsTool__getGroupsForPrincipal_cachekey )
83
98
GroupsTool .getGroupsForPrincipal = decorator (GroupsTool .getGroupsForPrincipal )
84
99
decorator = pmram .cache (GroupAwareRoleManager__getRolesForPrincipal_cachekey )
0 commit comments