root / pykota / trunk / pykota / storages / pgstorage.py @ 1179

Revision 1179, 24.2 kB (checked in by jalet, 21 years ago)

Bug fix wrt no user/group name command line argument to edpykota

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[1021]1# PyKota
[1144]2# -*- coding: ISO-8859-15 -*-
[1021]3#
4# PyKota : Print Quotas for CUPS and LPRng
5#
6# (c) 2003 Jerome Alet <alet@librelogiciel.com>
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20#
21# $Id$
22#
23# $Log$
[1179]24# Revision 1.21  2003/11/12 13:06:38  jalet
25# Bug fix wrt no user/group name command line argument to edpykota
26#
[1156]27# Revision 1.20  2003/10/09 21:25:26  jalet
28# Multiple printer names or wildcards can be passed on the command line
29# separated with commas.
30# Beta phase.
31#
[1149]32# Revision 1.19  2003/10/08 07:01:20  jalet
33# Job history can be disabled.
34# Some typos in README.
35# More messages in setup script.
36#
[1144]37# Revision 1.18  2003/10/07 09:07:30  jalet
38# Character encoding added to please latest version of Python
39#
[1137]40# Revision 1.17  2003/10/06 13:12:28  jalet
41# More work on caching
42#
[1136]43# Revision 1.16  2003/10/03 18:01:49  jalet
44# Nothing interesting...
45#
[1133]46# Revision 1.15  2003/10/03 12:27:03  jalet
47# Several optimizations, especially with LDAP backend
48#
[1131]49# Revision 1.14  2003/10/03 08:57:55  jalet
50# Caching mechanism now caches all that's cacheable.
51#
[1130]52# Revision 1.13  2003/10/02 20:23:18  jalet
53# Storage caching mechanism added.
54#
[1115]55# Revision 1.12  2003/08/17 14:20:25  jalet
56# Bug fix by Oleg Biteryakov
57#
[1113]58# Revision 1.11  2003/07/29 20:55:17  jalet
59# 1.14 is out !
60#
[1087]61# Revision 1.10  2003/07/16 21:53:08  jalet
62# Really big modifications wrt new configuration file's location and content.
63#
[1085]64# Revision 1.9  2003/07/14 17:20:15  jalet
65# Bug in postgresql storage when modifying the prices for a printer
66#
[1084]67# Revision 1.8  2003/07/14 14:18:17  jalet
68# Wrong documentation strings
69#
[1079]70# Revision 1.7  2003/07/09 20:17:07  jalet
71# Email field added to PostgreSQL schema
72#
[1068]73# Revision 1.6  2003/07/07 11:49:24  jalet
74# Lots of small fixes with the help of PyChecker
75#
[1067]76# Revision 1.5  2003/07/07 08:33:19  jalet
77# Bug fix due to a typo in LDAP code
78#
[1051]79# Revision 1.4  2003/06/30 13:54:21  jalet
80# Sorts by user / group name
81#
[1041]82# Revision 1.3  2003/06/25 14:10:01  jalet
83# Hey, it may work (edpykota --reset excepted) !
84#
[1024]85# Revision 1.2  2003/06/12 21:09:57  jalet
86# wrongly placed code.
87#
[1021]88# Revision 1.1  2003/06/10 16:37:54  jalet
89# Deletion of the second user which is not needed anymore.
90# Added a debug configuration field in /etc/pykota.conf
91# All queries can now be sent to the logger in debug mode, this will
92# greatly help improve performance when time for this will come.
93#
94#
95#
96#
97
[1130]98from pykota.storage import PyKotaStorageError,BaseStorage,StorageObject,StorageUser,StorageGroup,StoragePrinter,StorageLastJob,StorageUserPQuota,StorageGroupPQuota
[1021]99
100try :
101    import pg
102except ImportError :   
103    import sys
104    # TODO : to translate or not to translate ?
105    raise PyKotaStorageError, "This python version (%s) doesn't seem to have the PygreSQL module installed correctly." % sys.version.split()[0]
106
[1130]107class Storage(BaseStorage) :
[1021]108    def __init__(self, pykotatool, host, dbname, user, passwd) :
109        """Opens the PostgreSQL database connection."""
[1130]110        BaseStorage.__init__(self, pykotatool)
[1021]111        try :
112            (host, port) = host.split(":")
113            port = int(port)
114        except ValueError :   
115            port = -1         # Use PostgreSQL's default tcp/ip port (5432).
116       
117        try :
118            self.database = pg.connect(host=host, port=port, dbname=dbname, user=user, passwd=passwd)
119        except pg.error, msg :
120            raise PyKotaStorageError, msg
121        else :   
[1024]122            self.closed = 0
[1130]123            self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user))
[1021]124           
[1113]125    def close(self) :   
[1021]126        """Closes the database connection."""
127        if not self.closed :
128            self.database.close()
129            self.closed = 1
[1130]130            self.tool.logdebug("Database closed.")
[1021]131       
[1041]132    def beginTransaction(self) :   
133        """Starts a transaction."""
134        self.database.query("BEGIN;")
[1130]135        self.tool.logdebug("Transaction begins...")
[1041]136       
137    def commitTransaction(self) :   
138        """Commits a transaction."""
139        self.database.query("COMMIT;")
[1130]140        self.tool.logdebug("Transaction committed.")
[1041]141       
142    def rollbackTransaction(self) :     
143        """Rollbacks a transaction."""
144        self.database.query("ROLLBACK;")
[1130]145        self.tool.logdebug("Transaction aborted.")
[1041]146       
147    def doSearch(self, query) :
148        """Does a search query."""
[1021]149        query = query.strip()   
150        if not query.endswith(';') :   
151            query += ';'
152        try :
[1130]153            self.tool.logdebug("QUERY : %s" % query)
[1021]154            result = self.database.query(query)
155        except pg.error, msg :   
156            raise PyKotaStorageError, msg
157        else :   
[1041]158            if (result is not None) and (result.ntuples() > 0) : 
159                return result.dictresult()
160           
161    def doModify(self, query) :
162        """Does a (possibly multiple) modify query."""
163        query = query.strip()   
164        if not query.endswith(';') :   
165            query += ';'
166        try :
[1130]167            self.tool.logdebug("QUERY : %s" % query)
[1041]168            result = self.database.query(query)
169        except pg.error, msg :   
170            raise PyKotaStorageError, msg
[1068]171        else :   
172            return result
[1041]173           
[1021]174    def doQuote(self, field) :
175        """Quotes a field for use as a string in SQL queries."""
176        if type(field) == type(0.0) : 
177            typ = "decimal"
178        elif type(field) == type(0) :   
179            typ = "int"
180        else :   
181            typ = "text"
182        return pg._quote(field, typ)
183       
[1179]184    def getAllUsersNames(self) :   
185        """Extracts all user names."""
186        usernames = []
187        result = self.doSearch("SELECT username FROM users;")
188        if result :
189            usernames = [record["username"] for record in result]
190        return usernames
191       
192    def getAllGroupsNames(self) :   
193        """Extracts all group names."""
194        groupnames = []
195        result = self.doSearch("SELECT groupname FROM groups;")
196        if result :
197            groupnames = [record["groupname"] for record in result]
198        return groupnames
199       
[1130]200    def getUserFromBackend(self, username) :   
[1041]201        """Extracts user information given its name."""
202        user = StorageUser(self, username)
203        result = self.doSearch("SELECT * FROM users WHERE username=%s LIMIT 1" % self.doQuote(username))
204        if result :
205            fields = result[0]
206            user.ident = fields.get("id")
207            user.LimitBy = fields.get("limitby")
208            user.AccountBalance = fields.get("balance")
209            user.LifeTimePaid = fields.get("lifetimepaid")
[1067]210            user.Email = fields.get("email")
[1041]211            user.Exists = 1
212        return user
213       
[1130]214    def getGroupFromBackend(self, groupname) :   
[1041]215        """Extracts group information given its name."""
216        group = StorageGroup(self, groupname)
217        result = self.doSearch("SELECT * FROM groups WHERE groupname=%s LIMIT 1" % self.doQuote(groupname))
218        if result :
219            fields = result[0]
220            group.ident = fields.get("id")
221            group.LimitBy = fields.get("limitby")
222            result = self.doSearch("SELECT SUM(balance) AS balance, SUM(lifetimepaid) AS lifetimepaid FROM users WHERE id IN (SELECT userid FROM groupsmembers WHERE groupid=%s)" % self.doQuote(group.ident))
223            if result :
224                fields = result[0]
225                group.AccountBalance = fields.get("balance")
226                group.LifeTimePaid = fields.get("lifetimepaid")
227            group.Exists = 1
228        return group
229       
[1130]230    def getPrinterFromBackend(self, printername) :       
[1041]231        """Extracts printer information given its name."""
232        printer = StoragePrinter(self, printername)
233        result = self.doSearch("SELECT * FROM printers WHERE printername=%s LIMIT 1" % self.doQuote(printername))
234        if result :
235            fields = result[0]
236            printer.ident = fields.get("id")
237            printer.PricePerJob = fields.get("priceperjob")
238            printer.PricePerPage = fields.get("priceperpage")
239            printer.LastJob = self.getPrinterLastJob(printer)
240            printer.Exists = 1
241        return printer   
242       
[1130]243    def getUserPQuotaFromBackend(self, user, printer) :       
[1041]244        """Extracts a user print quota."""
245        userpquota = StorageUserPQuota(self, user, printer)
246        if user.Exists :
247            result = self.doSearch("SELECT id, lifepagecounter, pagecounter, softlimit, hardlimit, datelimit FROM userpquota WHERE userid=%s AND printerid=%s" % (self.doQuote(user.ident), self.doQuote(printer.ident)))
248            if result :
249                fields = result[0]
250                userpquota.ident = fields.get("id")
251                userpquota.PageCounter = fields.get("pagecounter")
252                userpquota.LifePageCounter = fields.get("lifepagecounter")
253                userpquota.SoftLimit = fields.get("softlimit")
254                userpquota.HardLimit = fields.get("hardlimit")
255                userpquota.DateLimit = fields.get("datelimit")
256                userpquota.Exists = 1
257        return userpquota
258       
[1130]259    def getGroupPQuotaFromBackend(self, group, printer) :       
[1041]260        """Extracts a group print quota."""
261        grouppquota = StorageGroupPQuota(self, group, printer)
262        if group.Exists :
263            result = self.doSearch("SELECT id, softlimit, hardlimit, datelimit FROM grouppquota WHERE groupid=%s AND printerid=%s" % (self.doQuote(group.ident), self.doQuote(printer.ident)))
264            if result :
265                fields = result[0]
266                grouppquota.ident = fields.get("id")
267                grouppquota.SoftLimit = fields.get("softlimit")
268                grouppquota.HardLimit = fields.get("hardlimit")
269                grouppquota.DateLimit = fields.get("datelimit")
270                result = self.doSearch("SELECT SUM(lifepagecounter) AS lifepagecounter, SUM(pagecounter) AS pagecounter FROM userpquota WHERE printerid=%s AND userid IN (SELECT userid FROM groupsmembers WHERE groupid=%s)" % (self.doQuote(printer.ident), self.doQuote(group.ident)))
271                if result :
272                    fields = result[0]
273                    grouppquota.PageCounter = fields.get("pagecounter")
274                    grouppquota.LifePageCounter = fields.get("lifepagecounter")
275                grouppquota.Exists = 1
276        return grouppquota
277       
[1130]278    def getPrinterLastJobFromBackend(self, printer) :       
[1041]279        """Extracts a printer's last job information."""
280        lastjob = StorageLastJob(self, printer)
281        result = self.doSearch("SELECT jobhistory.id, jobid, userid, username, pagecounter, jobsize, jobdate FROM jobhistory, users WHERE printerid=%s AND userid=users.id ORDER BY jobdate DESC LIMIT 1" % self.doQuote(printer.ident))
282        if result :
283            fields = result[0]
284            lastjob.ident = fields.get("id")
285            lastjob.JobId = fields.get("jobid")
286            lastjob.User = self.getUser(fields.get("username"))
287            lastjob.PrinterPageCounter = fields.get("pagecounter")
288            lastjob.JobSize = fields.get("jobsize")
289            lastjob.JobAction = fields.get("action")
290            lastjob.JobDate = fields.get("jobdate")
291            lastjob.Exists = 1
292        return lastjob
[1130]293           
[1137]294    def getGroupMembersFromBackend(self, group) :       
[1130]295        """Returns the group's members list."""
296        groupmembers = []
297        result = self.doSearch("SELECT * FROM groupsmembers JOIN users ON groupsmembers.userid=users.id WHERE groupid=%s" % self.doQuote(group.ident))
298        if result :
299            for record in result :
300                user = StorageUser(self, record.get("username"))
301                user.ident = record.get("userid")
302                user.LimitBy = record.get("limitby")
303                user.AccountBalance = record.get("balance")
304                user.LifeTimePaid = record.get("lifetimepaid")
305                user.Email = record.get("email")
306                user.Exists = 1
307                groupmembers.append(user)
[1131]308                self.cacheEntry("USERS", user.Name, user)
[1130]309        return groupmembers       
310       
[1137]311    def getUserGroupsFromBackend(self, user) :       
312        """Returns the user's groups list."""
313        groups = []
314        result = self.doSearch("SELECT groupname FROM groupsmembers JOIN groups ON groupsmembers.groupid=groups.id WHERE userid=%s" % self.doQuote(user.ident))
315        if result :
316            for record in result :
317                groups.append(self.getGroup(record.get("groupname")))
318        return groups       
319       
[1021]320    def getMatchingPrinters(self, printerpattern) :
[1041]321        """Returns the list of all printers for which name matches a certain pattern."""
322        printers = []
[1021]323        # We 'could' do a SELECT printername FROM printers WHERE printername LIKE ...
324        # but we don't because other storages semantics may be different, so every
325        # storage should use fnmatch to match patterns and be storage agnostic
[1041]326        result = self.doSearch("SELECT * FROM printers")
327        if result :
328            for record in result :
[1156]329                if self.tool.matchString(record["printername"], printerpattern.split(",")) :
[1041]330                    printer = StoragePrinter(self, record["printername"])
331                    printer.ident = record.get("id")
332                    printer.PricePerJob = record.get("priceperjob")
333                    printer.PricePerPage = record.get("priceperpage")
334                    printer.LastJob = self.getPrinterLastJob(printer)
335                    printer.Exists = 1
336                    printers.append(printer)
[1131]337                    self.cacheEntry("PRINTERS", printer.Name, printer)
[1041]338        return printers       
[1021]339       
[1136]340    def getPrinterUsersAndQuotas(self, printer, names=["*"]) :       
[1041]341        """Returns the list of users who uses a given printer, along with their quotas."""
342        usersandquotas = []
[1079]343        result = self.doSearch("SELECT users.id as uid,username,balance,lifetimepaid,limitby,email,userpquota.id,lifepagecounter,pagecounter,softlimit,hardlimit,datelimit FROM users JOIN userpquota ON users.id=userpquota.userid AND printerid=%s ORDER BY username ASC" % self.doQuote(printer.ident))
[1041]344        if result :
345            for record in result :
[1136]346                if self.tool.matchString(record.get("username"), names) :
[1133]347                    user = StorageUser(self, record.get("username"))
[1041]348                    user.ident = record.get("uid")
349                    user.LimitBy = record.get("limitby")
350                    user.AccountBalance = record.get("balance")
351                    user.LifeTimePaid = record.get("lifetimepaid")
[1079]352                    user.Email = record.get("email") 
[1041]353                    user.Exists = 1
354                    userpquota = StorageUserPQuota(self, user, printer)
355                    userpquota.ident = record.get("id")
356                    userpquota.PageCounter = record.get("pagecounter")
357                    userpquota.LifePageCounter = record.get("lifepagecounter")
358                    userpquota.SoftLimit = record.get("softlimit")
359                    userpquota.HardLimit = record.get("hardlimit")
360                    userpquota.DateLimit = record.get("datelimit")
361                    userpquota.Exists = 1
362                    usersandquotas.append((user, userpquota))
[1131]363                    self.cacheEntry("USERS", user.Name, user)
364                    self.cacheEntry("USERPQUOTAS", "%s@%s" % (user.Name, printer.Name), userpquota)
[1041]365        return usersandquotas
366               
[1136]367    def getPrinterGroupsAndQuotas(self, printer, names=["*"]) :       
[1041]368        """Returns the list of groups which uses a given printer, along with their quotas."""
369        groupsandquotas = []
[1051]370        result = self.doSearch("SELECT groupname FROM groups JOIN grouppquota ON groups.id=grouppquota.groupid AND printerid=%s ORDER BY groupname ASC" % self.doQuote(printer.ident))
[1041]371        if result :
372            for record in result :
[1136]373                if self.tool.matchString(record.get("groupname"), names) :
[1133]374                    group = self.getGroup(record.get("groupname"))
[1041]375                    grouppquota = self.getGroupPQuota(group, printer)
376                    groupsandquotas.append((group, grouppquota))
377        return groupsandquotas
[1021]378       
379    def addPrinter(self, printername) :       
[1041]380        """Adds a printer to the quota storage, returns it."""
381        self.doModify("INSERT INTO printers (printername) VALUES (%s)" % self.doQuote(printername))
382        return self.getPrinter(printername)
[1021]383       
[1041]384    def addUser(self, user) :       
[1021]385        """Adds a user to the quota storage, returns its id."""
[1087]386        self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy), self.doQuote(user.AccountBalance), self.doQuote(user.LifeTimePaid), self.doQuote(user.Email)))
[1041]387        return self.getUser(user.Name)
[1021]388       
[1041]389    def addGroup(self, group) :       
[1021]390        """Adds a group to the quota storage, returns its id."""
[1041]391        self.doModify("INSERT INTO groups (groupname, limitby) VALUES (%s, %s)" % (self.doQuote(group.Name), self.doQuote(group.LimitBy)))
392        return self.getGroup(group.Name)
393
394    def addUserToGroup(self, user, group) :   
395        """Adds an user to a group."""
[1068]396        result = self.doSearch("SELECT COUNT(*) AS mexists FROM groupsmembers WHERE groupid=%s AND userid=%s" % (self.doQuote(group.ident), self.doQuote(user.ident)))
[1021]397        try :
[1068]398            mexists = int(result[0].get("mexists"))
399        except (IndexError, TypeError) :   
[1041]400            mexists = 0
401        if not mexists :   
402            self.doModify("INSERT INTO groupsmembers (groupid, userid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(user.ident)))
403           
404    def addUserPQuota(self, user, printer) :
405        """Initializes a user print quota on a printer."""
406        self.doModify("INSERT INTO userpquota (userid, printerid) VALUES (%s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident)))
407        return self.getUserPQuota(user, printer)
[1021]408       
[1041]409    def addGroupPQuota(self, group, printer) :
410        """Initializes a group print quota on a printer."""
411        self.doModify("INSERT INTO grouppquota (groupid, printerid) VALUES (%s, %s)" % (self.doQuote(group.ident), self.doQuote(printer.ident)))
412        return self.getGroupPQuota(group, printer)
[1021]413       
[1041]414    def writePrinterPrices(self, printer) :   
415        """Write the printer's prices back into the storage."""
[1085]416        self.doModify("UPDATE printers SET priceperpage=%s, priceperjob=%s WHERE id=%s" % (self.doQuote(printer.PricePerPage), self.doQuote(printer.PricePerJob), self.doQuote(printer.ident)))
[1021]417       
[1041]418    def writeUserLimitBy(self, user, limitby) :   
419        """Sets the user's limiting factor."""
420        self.doModify("UPDATE users SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(user.ident)))
[1021]421       
[1041]422    def writeGroupLimitBy(self, group, limitby) :   
423        """Sets the group's limiting factor."""
424        self.doModify("UPDATE groups SET limitby=%s WHERE id=%s" % (self.doQuote(limitby), self.doQuote(group.ident)))
[1021]425       
[1041]426    def writeUserPQuotaDateLimit(self, userpquota, datelimit) :   
427        """Sets the date limit permanently for a user print quota."""
[1115]428        self.doModify("UPDATE userpquota SET datelimit=%s WHERE id=%s" % (self.doQuote(datelimit), self.doQuote(userpquota.ident)))
[1041]429           
430    def writeGroupPQuotaDateLimit(self, grouppquota, datelimit) :   
431        """Sets the date limit permanently for a group print quota."""
[1115]432        self.doModify("UPDATE grouppquota SET datelimit=%s WHERE id=%s" % (self.doQuote(datelimit), self.doQuote(grouppquota.ident)))
[1021]433       
[1041]434    def writeUserPQuotaPagesCounters(self, userpquota, newpagecounter, newlifepagecounter) :   
435       """Sets the new page counters permanently for a user print quota."""
436       self.doModify("UPDATE userpquota SET pagecounter=%s,lifepagecounter=%s WHERE id=%s" % (self.doQuote(newpagecounter), self.doQuote(newlifepagecounter), self.doQuote(userpquota.ident)))
437       
438    def writeUserAccountBalance(self, user, newbalance, newlifetimepaid=None) :   
439       """Sets the new account balance and eventually new lifetime paid."""
440       if newlifetimepaid is not None :
441           self.doModify("UPDATE users SET balance=%s, lifetimepaid=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(newlifetimepaid), self.doQuote(user.ident)))
442       else :   
443           self.doModify("UPDATE users SET balance=%s WHERE id=%s" % (self.doQuote(newbalance), self.doQuote(user.ident)))
444           
445    def writeLastJobSize(self, lastjob, jobsize) :       
446        """Sets the last job's size permanently."""
447        self.doModify("UPDATE jobhistory SET jobsize=%s WHERE id=%s" % (self.doQuote(jobsize), self.doQuote(lastjob.ident)))
[1021]448       
[1041]449    def writeJobNew(self, printer, user, jobid, pagecounter, action, jobsize=None) :   
450        """Adds a job in a printer's history."""
[1149]451        if (not self.disablehistory) or (not printer.LastJob.Exists) :
452            if jobsize is not None :
453                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action, jobsize) VALUES (%s, %s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize)))
454            else :   
455                self.doModify("INSERT INTO jobhistory (userid, printerid, jobid, pagecounter, action) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(user.ident), self.doQuote(printer.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action)))
456        else :       
457            # here we explicitly want to reset jobsize to NULL if needed
458            self.doModify("UPDATE jobhistory SET userid=%s, jobid=%s, pagecounter=%s, action=%s, jobsize=%s, jobdate=now() WHERE id=%s;" % (self.doQuote(user.ident), self.doQuote(jobid), self.doQuote(pagecounter), self.doQuote(action), self.doQuote(jobsize), self.doQuote(printer.LastJob.ident)))
[1041]459           
460    def writeUserPQuotaLimits(self, userpquota, softlimit, hardlimit) :
461        """Sets soft and hard limits for a user quota."""
462        self.doModify("UPDATE userpquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(userpquota.ident)))
[1021]463       
[1041]464    def writeGroupPQuotaLimits(self, grouppquota, softlimit, hardlimit) :
[1084]465        """Sets soft and hard limits for a group quota on a specific printer."""
[1041]466        self.doModify("UPDATE grouppquota SET softlimit=%s, hardlimit=%s, datelimit=NULL WHERE id=%s" % (self.doQuote(softlimit), self.doQuote(hardlimit), self.doQuote(grouppquota.ident)))
467
468    def deleteUser(self, user) :   
[1021]469        """Completely deletes an user from the Quota Storage."""
470        # TODO : What should we do if we delete the last person who used a given printer ?
[1041]471        # TODO : we can't reassign the last job to the previous one, because next user would be
472        # TODO : incorrectly charged (overcharged).
473        for q in [ 
474                    "DELETE FROM groupsmembers WHERE userid=%s" % self.doQuote(user.ident),
475                    "DELETE FROM jobhistory WHERE userid=%s" % self.doQuote(user.ident),
476                    "DELETE FROM userpquota WHERE userid=%s" % self.doQuote(user.ident),
477                    "DELETE FROM users WHERE id=%s" % self.doQuote(user.ident),
478                  ] :
479            self.doModify(q)
[1021]480       
[1041]481    def deleteGroup(self, group) :   
482        """Completely deletes a group from the Quota Storage."""
483        for q in [
484                   "DELETE FROM groupsmembers WHERE groupid=%s" % self.doQuote(group.ident),
485                   "DELETE FROM grouppquota WHERE groupid=%s" % self.doQuote(group.ident),
486                   "DELETE FROM groups WHERE id=%s" % self.doQuote(group.ident),
487                 ] : 
488            self.doModify(q)
[1021]489       
Note: See TracBrowser for help on using the browser.