| 453 | def _checkUserPQuota(self, userpquota) : |
| 454 | """Checks the user quota on a printer and deny or accept the job.""" |
| 455 | # then we check the user's own quota |
| 456 | # if we get there we are sure that policy is not EXTERNAL |
| 457 | user = userpquota.User |
| 458 | printer = userpquota.Printer |
| 459 | self.logdebug("Checking user %s's quota on printer %s" % (user.Name, printer.Name)) |
| 460 | (policy, dummy) = self.config.getPrinterPolicy(userpquota.Printer.Name) |
| 461 | if not userpquota.Exists : |
| 462 | # Unknown userquota |
| 463 | if policy == "ALLOW" : |
| 464 | action = "POLICY_ALLOW" |
| 465 | else : |
| 466 | action = "POLICY_DENY" |
| 467 | self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action)) |
| 468 | else : |
| 469 | pagecounter = int(userpquota.PageCounter or 0) |
| 470 | if userpquota.SoftLimit is not None : |
| 471 | softlimit = int(userpquota.SoftLimit) |
| 472 | if pagecounter < softlimit : |
| 473 | action = "ALLOW" |
| 474 | else : |
| 475 | if userpquota.HardLimit is None : |
| 476 | # only a soft limit, this is equivalent to having only a hard limit |
| 477 | action = "DENY" |
| 478 | else : |
| 479 | hardlimit = int(userpquota.HardLimit) |
| 480 | if softlimit <= pagecounter < hardlimit : |
| 481 | now = DateTime.now() |
| 482 | if userpquota.DateLimit is not None : |
| 483 | datelimit = DateTime.ISO.ParseDateTime(userpquota.DateLimit) |
| 484 | else : |
| 485 | datelimit = now + self.config.getGraceDelay(printer.Name) |
| 486 | userpquota.setDateLimit(datelimit) |
| 487 | if now < datelimit : |
| 488 | action = "WARN" |
| 489 | else : |
| 490 | action = "DENY" |
| 491 | else : |
| 492 | action = "DENY" |
| 493 | else : |
| 494 | if userpquota.HardLimit is not None : |
| 495 | # no soft limit, only a hard one. |
| 496 | hardlimit = int(userpquota.HardLimit) |
| 497 | if pagecounter < hardlimit : |
| 498 | action = "ALLOW" |
| 499 | else : |
| 500 | action = "DENY" |
| 501 | else : |
| 502 | # Both are unset, no quota, i.e. accounting only |
| 503 | action = "ALLOW" |
| 504 | return action |
| 505 | |
530 | | if not userpquota.Exists : |
531 | | # Unknown userquota |
532 | | if policy == "ALLOW" : |
533 | | action = "POLICY_ALLOW" |
534 | | else : |
535 | | action = "POLICY_DENY" |
536 | | self.logger.log_message(_("Unable to match user %s on printer %s, applying default policy (%s)") % (user.Name, printer.Name, action)) |
| 596 | # Then check the user quota on current printer and all its parents. |
| 597 | policyallowed = 0 |
| 598 | for upquota in [ userpquota ] + userpquota.ParentPrintersUserPQuota : |
| 599 | action = self._checkUserPQuota(upquota) |
| 600 | if action in ("DENY", "POLICY_DENY") : |
| 601 | return action |
| 602 | elif action == "WARN" : |
| 603 | warned = 1 |
| 604 | elif action == "POLICY_ALLOW" : |
| 605 | policyallowed = 1 |
| 606 | if warned : |
| 607 | return "WARN" |
| 608 | elif policyallowed : |
| 609 | return "POLICY_ALLOW" |
538 | | pagecounter = int(userpquota.PageCounter or 0) |
539 | | if userpquota.SoftLimit is not None : |
540 | | softlimit = int(userpquota.SoftLimit) |
541 | | if pagecounter < softlimit : |
542 | | action = "ALLOW" |
543 | | else : |
544 | | if userpquota.HardLimit is None : |
545 | | # only a soft limit, this is equivalent to having only a hard limit |
546 | | action = "DENY" |
547 | | else : |
548 | | hardlimit = int(userpquota.HardLimit) |
549 | | if softlimit <= pagecounter < hardlimit : |
550 | | now = DateTime.now() |
551 | | if userpquota.DateLimit is not None : |
552 | | datelimit = DateTime.ISO.ParseDateTime(userpquota.DateLimit) |
553 | | else : |
554 | | datelimit = now + self.config.getGraceDelay(printer.Name) |
555 | | userpquota.setDateLimit(datelimit) |
556 | | if now < datelimit : |
557 | | action = "WARN" |
558 | | else : |
559 | | action = "DENY" |
560 | | else : |
561 | | action = "DENY" |
562 | | else : |
563 | | if userpquota.HardLimit is not None : |
564 | | # no soft limit, only a hard one. |
565 | | hardlimit = int(userpquota.HardLimit) |
566 | | if pagecounter < hardlimit : |
567 | | action = "ALLOW" |
568 | | else : |
569 | | action = "DENY" |
570 | | else : |
571 | | # Both are unset, no quota, i.e. accounting only |
572 | | action = "ALLOW" |
573 | | return action |
574 | | |
| 611 | return "ALLOW" |
| 612 | |