|
12 | 12 | from Acquisition import Implicit |
13 | 13 | from App.config import getConfiguration |
14 | 14 | from eea.ldapadmin import ldap_config |
15 | | -from eea.ldapadmin.ui_common import nfp_for_country |
| 15 | +from eea.ldapadmin.ldap_config import _get_ldap_agent |
| 16 | +from eea.ldapadmin.logic_common import _is_authenticated |
16 | 17 | from eea.userseditor.permissions import EIONET_EDIT_USERS |
| 18 | +from eea.userseditor.users_editor import load_template |
17 | 19 | from ldap import SCOPE_BASE |
18 | 20 | from OFS.PropertyManager import PropertyManager |
19 | 21 | from OFS.SimpleItem import SimpleItem |
20 | 22 | from persistent.mapping import PersistentMapping |
21 | 23 | from Products.PageTemplates.PageTemplateFile import PageTemplateFile |
22 | | -from z3c.pt.pagetemplate import PageTemplateFile as ChameleonTemplate |
23 | 24 |
|
24 | 25 | cfg = getConfiguration() |
25 | 26 | if hasattr(cfg, 'environment'): |
@@ -47,33 +48,6 @@ def manage_add_userdetails(parent, tool_id, REQUEST=None): |
47 | 48 | REQUEST.RESPONSE.redirect(parent.absolute_url() + '/manage_workspace') |
48 | 49 |
|
49 | 50 |
|
50 | | -def _is_authenticated(request): |
51 | | - """_is_authenticated. |
52 | | -
|
53 | | - :param request: |
54 | | - """ |
55 | | - return 'Authenticated' in request.AUTHENTICATED_USER.getRoles() |
56 | | - |
57 | | - |
58 | | -def load_template(name, context=None, _memo={}): |
59 | | - """load_template. |
60 | | -
|
61 | | - :param name: |
62 | | - :param context: |
63 | | - :param _memo: |
64 | | - """ |
65 | | - if name not in _memo: |
66 | | - tpl = ChameleonTemplate(name) |
67 | | - |
68 | | - if context is not None: |
69 | | - bound = tpl.bind(context) |
70 | | - _memo[name] = bound |
71 | | - else: |
72 | | - _memo[name] = tpl |
73 | | - |
74 | | - return _memo[name] |
75 | | - |
76 | | - |
77 | 51 | zope2_wrapper = PageTemplateFile('zpt/zope2_wrapper.zpt', globals()) |
78 | 52 | plone5_wrapper = PageTemplateFile('zpt/plone5_wrapper.zpt', globals()) |
79 | 53 |
|
@@ -179,22 +153,6 @@ def can_edit_users(self): |
179 | 153 |
|
180 | 154 | return bool(user.has_permission(EIONET_EDIT_USERS, self.context)) |
181 | 155 |
|
182 | | - def can_edit_user(self): |
183 | | - """ Check if the authenticated user has permission to edit this |
184 | | - particular user. (meaning has general edit permission or |
185 | | - the authenticated user is NFP in the country of the user's |
186 | | - organisation).""" |
187 | | - if self.can_edit_users(): |
188 | | - return True |
189 | | - uid = self.context.REQUEST.AUTHENTICATED_USER.getId() |
190 | | - nfp_country = nfp_for_country(self.context) |
191 | | - if nfp_country: |
192 | | - agent = self.context._get_ldap_agent() |
193 | | - for org in agent.orgs_for_user(uid): |
194 | | - if agent.org_info(org[0])['country'] == nfp_country: |
195 | | - return True |
196 | | - return False |
197 | | - |
198 | 156 | def can_view_roles(self): |
199 | 157 | """can_view_roles.""" |
200 | 158 | if not self.is_authenticated(): |
@@ -223,22 +181,6 @@ def network_name(self): |
223 | 181 | return NETWORK_NAME |
224 | 182 |
|
225 | 183 |
|
226 | | -def logged_in_user(request): |
227 | | - """logged_in_user. |
228 | | -
|
229 | | - :param request: |
230 | | - """ |
231 | | - user_id = '' |
232 | | - |
233 | | - if _is_authenticated(request): |
234 | | - user = request.get('AUTHENTICATED_USER', '') |
235 | | - |
236 | | - if user: |
237 | | - user_id = user.getId() |
238 | | - |
239 | | - return user_id |
240 | | - |
241 | | - |
242 | 184 | class UserDetails(SimpleItem): |
243 | 185 | """UserDetails.""" |
244 | 186 |
|
@@ -278,20 +220,8 @@ def __init__(self, config={}): |
278 | 220 | self._config = PersistentMapping(config) |
279 | 221 |
|
280 | 222 | def _get_ldap_agent(self, bind=True, secondary=False): |
281 | | - """_get_ldap_agent. |
282 | | -
|
283 | | - :param bind: |
284 | | - :param secondary: bind with alternate credentials for different |
285 | | - permissions |
286 | | - """ |
287 | | - agent = ldap_config.ldap_agent_with_config(self._config, bind, |
288 | | - secondary=secondary) |
289 | | - try: |
290 | | - agent._author = logged_in_user(self.REQUEST) |
291 | | - except AttributeError: |
292 | | - agent._author = "System user" |
293 | | - |
294 | | - return agent |
| 223 | + """ get the ldap agent """ |
| 224 | + return _get_ldap_agent(self, bind, secondary) |
295 | 225 |
|
296 | 226 | def _prepare_user_page(self, uid): |
297 | 227 | """Shared by index_html and simple_profile""" |
|
0 commit comments