288 | | quota = self.storage.getUserPQuota(userid, printerid) |
289 | | if quota is None : |
290 | | # Unknown user or printer or combination |
291 | | policy = self.config.getPrinterPolicy(printername) |
292 | | if policy in [None, "ALLOW"] : |
293 | | action = "POLICY_ALLOW" |
| 293 | limitby = self.storage.getUserLimitBy(userid) |
| 294 | if limitby == "balance" : |
| 295 | balance = self.storage.getUserBalance(userid) |
| 296 | if balance is None : |
| 297 | policy = self.config.getPrinterPolicy(printername) |
| 298 | if policy in [None, "ALLOW"] : |
| 299 | action = "POLICY_ALLOW" |
| 300 | else : |
| 301 | action = "POLICY_DENY" |
| 302 | self.logger.log_message(_("Unable to find user %s's account balance, applying default policy (%s) for printer %s") % (username, action, printername)) |
295 | | action = "POLICY_DENY" |
296 | | self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action)) |
297 | | else : |
298 | | pagecounter = quota["pagecounter"] |
299 | | softlimit = quota["softlimit"] |
300 | | hardlimit = quota["hardlimit"] |
301 | | datelimit = quota["datelimit"] |
302 | | if softlimit is not None : |
303 | | if pagecounter < softlimit : |
| 304 | # TODO : there's no warning (no account balance soft limit) |
| 305 | if balance <= 0.0 : |
| 306 | action = "DENY" |
| 307 | else : |
306 | | if hardlimit is None : |
307 | | # only a soft limit, this is equivalent to having only a hard limit |
308 | | action = "DENY" |
| 317 | action = "POLICY_DENY" |
| 318 | self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (username, printername, action)) |
| 319 | else : |
| 320 | pagecounter = quota["pagecounter"] |
| 321 | softlimit = quota["softlimit"] |
| 322 | hardlimit = quota["hardlimit"] |
| 323 | datelimit = quota["datelimit"] |
| 324 | if softlimit is not None : |
| 325 | if pagecounter < softlimit : |
| 326 | action = "ALLOW" |
310 | | if softlimit <= pagecounter < hardlimit : |
311 | | now = DateTime.now() |
312 | | if datelimit is not None : |
313 | | datelimit = DateTime.ISO.ParseDateTime(datelimit) |
314 | | else : |
315 | | datelimit = now + self.config.getGraceDelay(printername) |
316 | | self.storage.setUserDateLimit(userid, printerid, datelimit) |
317 | | if now < datelimit : |
318 | | action = "WARN" |
319 | | else : |
| 328 | if hardlimit is None : |
| 329 | # only a soft limit, this is equivalent to having only a hard limit |
| 330 | action = "DENY" |
| 331 | else : |
| 332 | if softlimit <= pagecounter < hardlimit : |
| 333 | now = DateTime.now() |
| 334 | if datelimit is not None : |
| 335 | datelimit = DateTime.ISO.ParseDateTime(datelimit) |
| 336 | else : |
| 337 | datelimit = now + self.config.getGraceDelay(printername) |
| 338 | self.storage.setUserDateLimit(userid, printerid, datelimit) |
| 339 | if now < datelimit : |
| 340 | action = "WARN" |
| 341 | else : |
| 342 | action = "DENY" |
| 343 | else : |