Package ldaptor :: Package apps :: Package webui :: Module gadget
[hide private]
[frames] | no frames]

Source Code for Module ldaptor.apps.webui.gadget

  1  from zope.interface import implements 
  2  from webut.skin import iskin 
  3  from ldaptor.apps.webui import login, search, edit, add, delete, mass_change_password, change_password, move, iwebui 
  4  from ldaptor.protocols.ldap import distinguishedname 
  5  from ldaptor.apps.webui.uriquote import uriUnquote 
  6  from ldaptor import interfaces 
  7  from ldaptor.apps.webui.i18n import _ 
  8  from ldaptor.apps.webui import i18n 
  9   
 10  from nevow import rend, loaders, url, static, inevow 
 11  from formless import annotate, webform, iformless 
 12  import os 
 13   
14 -class LdaptorWebUIGadget2(rend.Page):
15 implements(iskin.ISkinnable) 16 17 title = _('Ldaptor Web Interface') 18 19 addSlash = True 20
21 - def __init__(self, baseObject):
22 super(LdaptorWebUIGadget2, self).__init__() 23 self.baseObject = baseObject
24
25 - def child_(self, context):
26 return inevow.IRequest(context).URLPath().child('search')
27
28 - def child_search(self, context):
29 return search.getSearchPage()
30
31 - def child_edit(self, context):
32 if not inevow.ISession(context).getLoggedInRoot().loggedIn: 33 return login.LoginPage([str(self.baseObject), 'edit']) 34 return edit.EditPage()
35
36 - def child_move(self, context):
37 if not inevow.ISession(context).getLoggedInRoot().loggedIn: 38 return login.LoginPage([str(self.baseObject), 'move']) 39 return move.MovePage()
40
41 - def child_add(self, context):
42 if not inevow.ISession(context).getLoggedInRoot().loggedIn: 43 return login.LoginPage([str(self.baseObject), 'add']) 44 return add.getResource(baseObject=self.baseObject, 45 request=inevow.IRequest(context))
46
47 - def child_delete(self, context):
48 if not inevow.ISession(context).getLoggedInRoot().loggedIn: 49 return login.LoginPage([str(self.baseObject), 'delete']) 50 return delete.getResource()
51
52 - def child_mass_change_password(self, context):
53 if not inevow.ISession(context).getLoggedInRoot().loggedIn: 54 return login.LoginPage([str(self.baseObject), 'mass_change_password']) 55 return mass_change_password.MassPasswordChangePage( 56 baseObject=self.baseObject)
57
58 - def child_change_password(self, context):
59 if not inevow.ISession(context).getLoggedInRoot().loggedIn: 60 return login.LoginPage([str(self.baseObject), 'change_password']) 61 return change_password.getResource()
62
63 -class LDAPDN(annotate.String):
64 - def coerce(self, *a, **kw):
65 val = super(LDAPDN, self).coerce(*a, **kw) 66 try: 67 dn = distinguishedname.DistinguishedName(stringValue=val) 68 except distinguishedname.InvalidRelativeDistinguishedName, e: 69 raise annotate.InputError, \ 70 "%r is not a valid LDAP DN: %s" % (val, e) 71 return dn
72
73 -class LdaptorWebUIGadget(rend.Page):
74 implements(iskin.ISkinnable) 75 76 title = _('Ldaptor Web Interface') 77 78 addSlash = True 79 80 docFactory = loaders.xmlfile( 81 'basedn.xhtml', 82 templateDir=os.path.split(os.path.abspath(__file__))[0]) 83
84 - def __init__(self, loggedIn, config):
85 super(LdaptorWebUIGadget, self).__init__() 86 self.loggedIn = loggedIn 87 self.config = config
88
89 - def getBindingNames(self, ctx):
90 return ['go']
91
92 - def bind_go(self, ctx):
93 return annotate.MethodBinding( 94 'go', 95 annotate.Method(arguments=[ 96 annotate.Argument('ctx', annotate.Context()), 97 annotate.Argument('baseDN', LDAPDN( 98 label=_('Base DN'), 99 description=_("The top-level LDAP DN you want" 100 " to browse, e.g. dc=example,dc=com"))), 101 ], 102 label=_('Go')), 103 action=_('Go'))
104
105 - def go(self, ctx, baseDN):
106 u = url.URL.fromContext(ctx) 107 u = u.child(str(baseDN)) 108 return u
109
110 - def render_form(self, context, data):
111 return webform.renderForms()
112
113 - def locateChild(self, ctx, segments):
114 ret = super(LdaptorWebUIGadget, self).locateChild(ctx, segments) 115 if ret != rend.NotFound: 116 return ret 117 118 path = segments[0] 119 unquoted=uriUnquote(path) 120 try: 121 dn = distinguishedname.DistinguishedName(stringValue=unquoted) 122 except distinguishedname.InvalidRelativeDistinguishedName, e: 123 # TODO There's no way to throw a FormException at this stage. 124 u = url.URL.fromContext(ctx) 125 126 # TODO protect against guard bug, see 127 # http://divmod.org/users/roundup.twistd/nevow/issue74 128 u = u.child('') 129 130 # TODO freeform_post!configurableName!methodName 131 u.add('basedn', path) 132 return u, [] 133 134 r=LdaptorWebUIGadget2(baseObject=dn) 135 ctx.remember(self.config, interfaces.ILDAPConfig) 136 ctx.remember(dn, iwebui.ICurrentDN) 137 return r, segments[1:]
138 139 render_i18n = i18n.render()
140