| 292 | def checkGroupPQuota(self, groupname, printername) : |
| 293 | """Checks the group quota on a printer and deny or accept the job.""" |
| 294 | printerid = self.storage.getPrinterId(printername) |
| 295 | groupid = self.storage.getGroupId(groupname) |
| 296 | limitby = self.storage.getGroupLimitBy(groupid) |
| 297 | if limitby == "balance" : |
| 298 | balance = self.storage.getGroupBalance(groupid) |
| 299 | if balance is None : |
| 300 | policy = self.config.getPrinterPolicy(printername) |
| 301 | if policy in [None, "ALLOW"] : |
| 302 | action = "POLICY_ALLOW" |
| 303 | else : |
| 304 | action = "POLICY_DENY" |
| 305 | self.logger.log_message(_("Unable to find group %s's account balance, applying default policy (%s) for printer %s") % (groupname, action, printername)) |
| 306 | else : |
| 307 | # TODO : there's no warning (no account balance soft limit) |
| 308 | if balance <= 0.0 : |
| 309 | action = "DENY" |
| 310 | else : |
| 311 | action = "ALLOW" |
| 312 | else : |
| 313 | quota = self.storage.getGroupPQuota(groupid, printerid) |
| 314 | if quota is None : |
| 315 | # Unknown group or printer or combination |
| 316 | policy = self.config.getPrinterPolicy(printername) |
| 317 | if policy in [None, "ALLOW"] : |
| 318 | action = "POLICY_ALLOW" |
| 319 | else : |
| 320 | action = "POLICY_DENY" |
| 321 | self.logger.log_message(_("Unable to match group %s on printer %s, applying default policy (%s)") % (groupname, printername, action)) |
| 322 | else : |
| 323 | pagecounter = quota["pagecounter"] |
| 324 | softlimit = quota["softlimit"] |
| 325 | hardlimit = quota["hardlimit"] |
| 326 | datelimit = quota["datelimit"] |
| 327 | if softlimit is not None : |
| 328 | if pagecounter < softlimit : |
| 329 | action = "ALLOW" |
| 330 | else : |
| 331 | if hardlimit is None : |
| 332 | # only a soft limit, this is equivalent to having only a hard limit |
| 333 | action = "DENY" |
| 334 | else : |
| 335 | if softlimit <= pagecounter < hardlimit : |
| 336 | now = DateTime.now() |
| 337 | if datelimit is not None : |
| 338 | datelimit = DateTime.ISO.ParseDateTime(datelimit) |
| 339 | else : |
| 340 | datelimit = now + self.config.getGraceDelay(printername) |
| 341 | self.storage.setGroupDateLimit(groupid, printerid, datelimit) |
| 342 | if now < datelimit : |
| 343 | action = "WARN" |
| 344 | else : |
| 345 | action = "DENY" |
| 346 | else : |
| 347 | action = "DENY" |
| 348 | else : |
| 349 | if hardlimit is not None : |
| 350 | # no soft limit, only a hard one. |
| 351 | if pagecounter < hardlimit : |
| 352 | action = "ALLOW" |
| 353 | else : |
| 354 | action = "DENY" |
| 355 | else : |
| 356 | # Both are unset, no quota, i.e. accounting only |
| 357 | action = "ALLOW" |
| 358 | return action |
| 359 | |
360 | | raise PyKotaToolError, _("Group quotas are currently not implemented.") |
| 438 | admin = self.config.getAdmin(pname) |
| 439 | adminmail = self.config.getAdminMail(pname) |
| 440 | mailto = self.config.getMailTo(pname) |
| 441 | action = self.checkGroupPQuota(groupname, pname) |
| 442 | groupmembers = self.storage.getGroupMembersNames(groupname) |
| 443 | if action.startswith("POLICY_") : |
| 444 | action = action[7:] |
| 445 | if action == "DENY" : |
| 446 | adminmessage = _("Print Quota exceeded for group %s on printer %s") % (groupname, pname) |
| 447 | self.logger.log_message(adminmessage) |
| 448 | if mailto in [ "BOTH", "ADMIN" ] : |
| 449 | self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) |
| 450 | for username in groupmembers : |
| 451 | if mailto in [ "BOTH", "USER" ] : |
| 452 | self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You are not allowed to print anymore because\nyour group Print Quota is exceeded on printer %s.") % pname) |
| 453 | elif action == "WARN" : |
| 454 | adminmessage = _("Print Quota soft limit exceeded for group %s on printer %s") % (groupname, pname) |
| 455 | self.logger.log_message(adminmessage) |
| 456 | if mailto in [ "BOTH", "ADMIN" ] : |
| 457 | self.sendMessageToAdmin(adminmail, _("Print Quota"), adminmessage) |
| 458 | for username in groupmembers : |
| 459 | if mailto in [ "BOTH", "USER" ] : |
| 460 | self.sendMessageToUser(admin, adminmail, username, _("Print Quota Exceeded"), _("You will soon be forbidden to print anymore because\nyour group Print Quota is almost reached on printer %s.") % pname) |
| 461 | return action |