VirtualMailManager/handler.py
branchv0.7.x
changeset 681 4cab983479db
parent 676 2bc11dada296
child 686 5f4abdab738e
equal deleted inserted replaced
680:5365af94a8ec 681:4cab983479db
   449                                       smtp=self._cfg.dget('domain.smtp')))
   449                                       smtp=self._cfg.dget('domain.smtp')))
   450         dom.set_directory(self._cfg.dget('misc.base_directory'))
   450         dom.set_directory(self._cfg.dget('misc.base_directory'))
   451         dom.save()
   451         dom.save()
   452         self._make_domain_dir(dom)
   452         self._make_domain_dir(dom)
   453 
   453 
   454     def domain_quotalimit(self, domainname, bytes_, messages=0, force=None):
   454     def domain_quotalimit(self, domainname, bytes_, messages=0, force=False):
   455         """Wrapper around Domain.update_quotalimit()."""
   455         """Wrapper around Domain.update_quotalimit()."""
   456         if not all(isinstance(i, int) for i in (bytes_, messages)):
   456         if not all(isinstance(i, int) for i in (bytes_, messages)):
   457             raise TypeError("'bytes_' and 'messages' have to be "
   457             raise TypeError("'bytes_' and 'messages' have to be "
   458                             "integers or longs.")
   458                             "integers or longs.")
   459         if force is not None and force != 'force':
   459         assert isinstance(force, bool)
   460             raise DomainError(_("Invalid argument: '%s'") % force,
       
   461                               INVALID_ARGUMENT)
       
   462         dom = self._get_domain(domainname)
   460         dom = self._get_domain(domainname)
   463         quotalimit = QuotaLimit(self._dbh, bytes=bytes_, messages=messages)
   461         quotalimit = QuotaLimit(self._dbh, bytes=bytes_, messages=messages)
   464         if force is None:
   462         dom.update_quotalimit(quotalimit, force)
   465             dom.update_quotalimit(quotalimit)
   463 
   466         else:
   464     def domain_services(self, domainname, force=False, *services):
   467             dom.update_quotalimit(quotalimit, force=True)
       
   468 
       
   469     def domain_services(self, domainname, force=None, *services):
       
   470         """Wrapper around Domain.update_serviceset()."""
   465         """Wrapper around Domain.update_serviceset()."""
       
   466         assert isinstance(force, bool)
   471         kwargs = dict.fromkeys(SERVICES, False)
   467         kwargs = dict.fromkeys(SERVICES, False)
   472         if force is not None and force != 'force':
       
   473             raise DomainError(_("Invalid argument: '%s'") % force,
       
   474                               INVALID_ARGUMENT)
       
   475         for service in set(services):
   468         for service in set(services):
   476             if service not in SERVICES:
   469             if service not in SERVICES:
   477                 raise DomainError(_("Unknown service: '%s'") % service,
   470                 raise DomainError(_("Unknown service: '%s'") % service,
   478                                   UNKNOWN_SERVICE)
   471                                   UNKNOWN_SERVICE)
   479             kwargs[service] = True
   472             kwargs[service] = True
   480 
   473 
   481         dom = self._get_domain(domainname)
   474         dom = self._get_domain(domainname)
   482         serviceset = ServiceSet(self._dbh, **kwargs)
   475         serviceset = ServiceSet(self._dbh, **kwargs)
   483         dom.update_serviceset(serviceset, (True, False)[not force])
   476         dom.update_serviceset(serviceset, force)
   484 
   477 
   485     def domain_transport(self, domainname, transport, force=None):
   478     def domain_transport(self, domainname, transport, force=False):
   486         """Wrapper around Domain.update_transport()"""
   479         """Wrapper around Domain.update_transport()"""
   487         if force is not None and force != 'force':
   480         assert isinstance(force, bool)
   488             raise DomainError(_("Invalid argument: '%s'") % force,
       
   489                               INVALID_ARGUMENT)
       
   490         dom = self._get_domain(domainname)
   481         dom = self._get_domain(domainname)
   491         trsp = Transport(self._dbh, transport=transport)
   482         trsp = Transport(self._dbh, transport=transport)
   492         if force is None:
   483         dom.update_transport(trsp, force)
   493             dom.update_transport(trsp)
       
   494         else:
       
   495             dom.update_transport(trsp, force=True)
       
   496 
   484 
   497     def domain_note(self, domainname, note):
   485     def domain_note(self, domainname, note):
   498         """Wrapper around Domain.update_note()"""
   486         """Wrapper around Domain.update_note()"""
   499         dom = self._get_domain(domainname)
   487         dom = self._get_domain(domainname)
   500         dom.update_note(note)
   488         dom.update_note(note)