Changeset 1018 for pykota/trunk/pykota/storages/ldapstorage.py
- Timestamp:
- 06/06/03 22:49:15 (21 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/storages/ldapstorage.py
r1017 r1018 21 21 # 22 22 # $Log$ 23 # Revision 1.3 2003/06/06 20:49:15 jalet 24 # Very latest schema. UNTESTED. 25 # 23 26 # Revision 1.2 2003/06/06 14:21:08 jalet 24 27 # New LDAP schema. … … 86 89 def getPrinterId(self, printername) : 87 90 """Returns a printerid given a printername.""" 88 result = self.doSearch("(&(objectClass=pykotaPrinter)( pykotaPrinterName=%s))" % printername, ["pykotaPrinterName"])91 result = self.doSearch("(&(objectClass=pykotaPrinter)(|(pykotaPrinterName=%s)(cn=%s)))" % (printername, printername), ["pykotaPrinterName"]) 89 92 if result : 90 93 return result[0][0] … … 92 95 def getPrinterPrices(self, printerid) : 93 96 """Returns a printer prices per page and per job given a printerid.""" 94 result = self.doSearch(" pykotaPrinterName=*", ["pykotaPricePerPage", "pykotaPricePerJob"], base=printerid)97 result = self.doSearch("(|(pykotaPrinterName=*)(cn=*))", ["pykotaPricePerPage", "pykotaPricePerJob"], base=printerid, scope=ldap.SCOPE_BASE) 95 98 if result : 96 99 return (float(result[0][1]["pykotaPricePerPage"][0]), float(result[0][1]["pykotaPricePerJob"][0])) … … 102 105 def getUserId(self, username) : 103 106 """Returns a userid given a username.""" 104 result = self.doSearch("(&(objectClass=pykotaAccount)( pykotaUserName=%s))" % username, ["uid"])107 result = self.doSearch("(&(objectClass=pykotaAccount)(|(pykotaUserName=%s)(uid=%s)))" % (username, username), ["uid"]) 105 108 if result : 106 109 return result[0][0] … … 108 111 def getGroupId(self, groupname) : 109 112 """Returns a groupid given a grupname.""" 110 result = self.doSearch("(&(objectClass=pykotaGroup)( pykotaGroupName=%s))" % groupname, ["cn"])113 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(cn=%s)))" % (groupname, groupname), ["cn"]) 111 114 if result is not None : 112 115 (groupid, dummy) = result[0] … … 120 123 """Returns the list of userids and usernames which uses a given printer.""" 121 124 # first get the printer's name from the id 122 result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) 123 if result : 124 printername = result[0][1]["pykotaPrinterName"][0] 125 result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", "cn"], base=printerid, scope=ldap.SCOPE_BASE) 126 if result : 127 fields = result[0][1] 128 printername = (fields.get("pykotaPrinterName") or fields.get("cn"))[0] 125 129 result = self.doSearch("(&(objectClass=pykotaUserPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaUserName"]) 126 130 if result : … … 130 134 """Returns the list of groups which uses a given printer.""" 131 135 # first get the printer's name from the id 132 result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName"], base=printerid, scope=ldap.SCOPE_BASE) 133 if result : 134 printername = result[0][1]["pykotaPrinterName"][0] 136 result = self.doSearch("objectClass=pykotaPrinter", ["pykotaPrinterName", "cn"], base=printerid, scope=ldap.SCOPE_BASE) 137 if result : 138 fields = result[0][1] 139 printername = (fields.get("pykotaPrinterName") or fields.get("cn"))[0] 135 140 result = self.doSearch("(&(objectClass=pykotaGroupPQuota)(pykotaPrinterName=%s))" % printername, ["pykotaGroupName"]) 136 141 if result : … … 139 144 def getGroupMembersNames(self, groupname) : 140 145 """Returns the list of user's names which are member of this group.""" 141 result = self.doSearch("(&(objectClass=pykotaGroup)(pykotaGroupName=%s))" % groupname, ["memberUid"]) 142 if result : 143 return result[0][1]["memberUid"] 146 result = self.doSearch("(&(objectClass=pykotaGroup)(|(pykotaGroupName=%s)(cn=%s)))" % (groupname, groupname), ["memberUid", "uniqueMember", "member"]) 147 if result : 148 fields = result[0][1] 149 return fields.get("memberUid") or fields.get("uniqueMember") or fields.get("member") 144 150 145 151 def getUserGroupsNames(self, userid) : … … 177 183 if result : 178 184 username = result[0][1]["pykotaUserName"][0] 179 result = self.doSearch("(&(objectClass=pykotaAccountBalance)( pykotaUserName=%s))" % username, ["pykotaBalance", "pykotaLifeTimePaid"])185 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(uid=%s)))" % (username, username), ["pykotaBalance", "pykotaLifeTimePaid"]) 180 186 if result : 181 187 fields = result[0][1] … … 185 191 """Returns the current account balance for a given user id.""" 186 192 # first get the user's name from the user id 187 result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName"], base=userid, scope=ldap.SCOPE_BASE) 188 if result : 189 username = result[0][1]["pykotaUserName"][0] 190 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(pykotaUserName=%s))" % username, ["pykotaBalance", "pykotaLifeTimePaid"]) 193 result = self.doSearch("objectClass=pykotaAccount", ["pykotaUserName", "uid"], base=userid, scope=ldap.SCOPE_BASE) 194 if result : 195 fields = result[0][1] 196 username = (fields.get("pykotaUserName") or fields.get("uid"))[0] 197 result = self.doSearch("(&(objectClass=pykotaAccountBalance)(|(pykotaUserName=%s)(uid=%s)))" % (username, username), ["pykotaBalance", "pykotaLifeTimePaid"]) 191 198 if result : 192 199 fields = result[0][1]