equal
deleted
inserted
replaced
22 |
22 |
23 class CWUser(AnyEntity): |
23 class CWUser(AnyEntity): |
24 id = 'CWUser' |
24 id = 'CWUser' |
25 fetch_attrs, fetch_order = fetch_config(['login', 'firstname', 'surname']) |
25 fetch_attrs, fetch_order = fetch_config(['login', 'firstname', 'surname']) |
26 fetch_unrelated_order = fetch_order |
26 fetch_unrelated_order = fetch_order |
27 |
27 |
28 # used by repository to check if the user can log in or not |
28 # used by repository to check if the user can log in or not |
29 AUTHENTICABLE_STATES = ('activated',) |
29 AUTHENTICABLE_STATES = ('activated',) |
30 |
30 |
31 # low level utilities ##################################################### |
31 # low level utilities ##################################################### |
32 def __init__(self, *args, **kwargs): |
32 def __init__(self, *args, **kwargs): |
35 super(CWUser, self).__init__(*args, **kwargs) |
35 super(CWUser, self).__init__(*args, **kwargs) |
36 if groups is not None: |
36 if groups is not None: |
37 self._groups = groups |
37 self._groups = groups |
38 if properties is not None: |
38 if properties is not None: |
39 self._properties = properties |
39 self._properties = properties |
40 |
40 |
41 @property |
41 @property |
42 def groups(self): |
42 def groups(self): |
43 try: |
43 try: |
44 return self._groups |
44 return self._groups |
45 except AttributeError: |
45 except AttributeError: |
46 self._groups = set(g.name for g in self.in_group) |
46 self._groups = set(g.name for g in self.in_group) |
47 return self._groups |
47 return self._groups |
48 |
48 |
49 @property |
49 @property |
50 def properties(self): |
50 def properties(self): |
51 try: |
51 try: |
52 return self._properties |
52 return self._properties |
53 except AttributeError: |
53 except AttributeError: |
62 except KeyError: |
62 except KeyError: |
63 pass |
63 pass |
64 except ValueError: |
64 except ValueError: |
65 self.warning('incorrect value for eproperty %s of user %s', key, self.login) |
65 self.warning('incorrect value for eproperty %s of user %s', key, self.login) |
66 return self.vreg.property_value(key) |
66 return self.vreg.property_value(key) |
67 |
67 |
68 def matching_groups(self, groups): |
68 def matching_groups(self, groups): |
69 """return the number of the given group(s) in which the user is |
69 """return the number of the given group(s) in which the user is |
70 |
70 |
71 :type groups: str or iterable(str) |
71 :type groups: str or iterable(str) |
72 :param groups: a group name or an iterable on group names |
72 :param groups: a group name or an iterable on group names |
84 |
84 |
85 def is_anonymous(self): |
85 def is_anonymous(self): |
86 """ checks if user is an anonymous user""" |
86 """ checks if user is an anonymous user""" |
87 #FIXME on the web-side anonymous user is detected according |
87 #FIXME on the web-side anonymous user is detected according |
88 # to config['anonymous-user'], we don't have this info on |
88 # to config['anonymous-user'], we don't have this info on |
89 # the server side. |
89 # the server side. |
90 return self.groups == frozenset(('guests', )) |
90 return self.groups == frozenset(('guests', )) |
91 |
91 |
92 def owns(self, eid): |
92 def owns(self, eid): |
93 if hasattr(self.req, 'unsafe_execute'): |
93 if hasattr(self.req, 'unsafe_execute'): |
94 # use unsafe_execute on the repository side, in case |
94 # use unsafe_execute on the repository side, in case |
114 cachekey = 'x' |
114 cachekey = 'x' |
115 try: |
115 try: |
116 return self.req.execute(rql, kwargs, cachekey) |
116 return self.req.execute(rql, kwargs, cachekey) |
117 except Unauthorized: |
117 except Unauthorized: |
118 return False |
118 return False |
119 |
119 |
120 # presentation utilities ################################################## |
120 # presentation utilities ################################################## |
121 |
121 |
122 def name(self): |
122 def name(self): |
123 """construct a name using firstname / surname or login if not defined""" |
123 """construct a name using firstname / surname or login if not defined""" |
124 |
124 |
125 if self.firstname and self.surname: |
125 if self.firstname and self.surname: |
126 return self.req._('%(firstname)s %(surname)s') % { |
126 return self.req._('%(firstname)s %(surname)s') % { |
127 'firstname': self.firstname, 'surname' : self.surname} |
127 'firstname': self.firstname, 'surname' : self.surname} |
128 if self.firstname: |
128 if self.firstname: |
129 return self.firstname |
129 return self.firstname |