diff options
| author | J08nY | 2017-06-22 19:12:04 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-22 19:12:04 +0200 |
| commit | 5014e7a75f02f8c707847122ff43b37064247a43 (patch) | |
| tree | 19bda52a1507fa7fe09e051ccee0129aace62d85 /src/mailman_pgp/model | |
| parent | 429234b8db28ed6aadf21a3ccfce7eaf7065be71 (diff) | |
| download | mailman-pgp-5014e7a75f02f8c707847122ff43b37064247a43.tar.gz mailman-pgp-5014e7a75f02f8c707847122ff43b37064247a43.tar.zst mailman-pgp-5014e7a75f02f8c707847122ff43b37064247a43.zip | |
Diffstat (limited to 'src/mailman_pgp/model')
| -rw-r--r-- | src/mailman_pgp/model/address.py | 8 | ||||
| -rw-r--r-- | src/mailman_pgp/model/base.py | 9 | ||||
| -rw-r--r-- | src/mailman_pgp/model/list.py | 15 |
3 files changed, 23 insertions, 9 deletions
diff --git a/src/mailman_pgp/model/address.py b/src/mailman_pgp/model/address.py index 60c6e2f..1dc3840 100644 --- a/src/mailman_pgp/model/address.py +++ b/src/mailman_pgp/model/address.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. -"""""" +"""Model for PGP enabled addresses.""" from os.path import exists, isfile, join @@ -29,6 +29,8 @@ from mailman_pgp.model.base import Base class PGPAddress(Base): + """A PGP enabled address.""" + __tablename__ = 'pgp_addresses' id = Column(Integer, primary_key=True) @@ -46,6 +48,8 @@ class PGPAddress(Base): @property def key(self): + if self.key_fingerprint is None: + return None if self._key is None: if exists(self.key_path) and isfile(self.key_path): self._key, _ = PGPKey.from_file(self.key_path) @@ -53,5 +57,7 @@ class PGPAddress(Base): @property def key_path(self): + if self.key_fingerprint is None: + return None return join(config.pgp.keydir_config['user_keydir'], self.key_fingerprint + '.asc') diff --git a/src/mailman_pgp/model/base.py b/src/mailman_pgp/model/base.py index 646bb7d..f5d8e77 100644 --- a/src/mailman_pgp/model/base.py +++ b/src/mailman_pgp/model/base.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. -"""""" +"""Base class for all models.""" from public import public from sqlalchemy.ext.declarative import as_declarative @@ -26,9 +26,16 @@ from mailman_pgp.database import query @public @as_declarative() class Base: + """Custom declarative base.""" @classmethod def query(cls): + """ + A query helper. + + :return: A query on class. + :rtype: sqlalchemy.orm.query.Query + """ return query(cls) diff --git a/src/mailman_pgp/model/list.py b/src/mailman_pgp/model/list.py index 84dd1a8..e1de7cc 100644 --- a/src/mailman_pgp/model/list.py +++ b/src/mailman_pgp/model/list.py @@ -15,18 +15,18 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. -"""""" +"""Model for PGP enabled mailing lists.""" from os.path import exists, isfile, join -from mailman.config import config as mailman_config from mailman.database.types import Enum, SAUnicode from mailman.interfaces.action import Action -from mailman.model.mailinglist import MailingList +from mailman.interfaces.listmanager import IListManager from pgpy import PGPKey from public import public from sqlalchemy import Boolean, Column, Integer from sqlalchemy.orm import reconstructor +from zope.component import getUtility from mailman_pgp.config import config from mailman_pgp.model.base import Base @@ -35,6 +35,8 @@ from mailman_pgp.pgp.keygen import ListKeyGenerator @public class PGPMailingList(Base): + """A PGP enabled mailing list.""" + __tablename__ = 'pgp_lists' id = Column(Integer, primary_key=True) @@ -76,10 +78,9 @@ class PGPMailingList(Base): @property def mlist(self): - if self._mlist is not None: - return self._mlist - return mailman_config.db.store.query(MailingList).filter_by( - _list_id=self.list_id).first() + if self._mlist is None: + self._mlist = getUtility(IListManager).get_by_list_id(self.list_id) + return self._mlist @property def key(self): |
