diff options
| author | J08nY | 2017-06-28 18:04:57 +0200 |
|---|---|---|
| committer | J08nY | 2017-06-28 18:04:57 +0200 |
| commit | b1840f94aa5eea39709eb127250f664b716c76e0 (patch) | |
| tree | d6b74b973c204b602e219dfd73b21d97b981171e /src/mailman_pgp/model | |
| parent | 47eea2be6a86f81ba075df632305c1dfeecce50c (diff) | |
| download | mailman-pgp-b1840f94aa5eea39709eb127250f664b716c76e0.tar.gz mailman-pgp-b1840f94aa5eea39709eb127250f664b716c76e0.tar.zst mailman-pgp-b1840f94aa5eea39709eb127250f664b716c76e0.zip | |
Diffstat (limited to 'src/mailman_pgp/model')
| -rw-r--r-- | src/mailman_pgp/model/address.py | 31 | ||||
| -rw-r--r-- | src/mailman_pgp/model/list.py | 12 |
2 files changed, 42 insertions, 1 deletions
diff --git a/src/mailman_pgp/model/address.py b/src/mailman_pgp/model/address.py index c552c4a..a6aaf3c 100644 --- a/src/mailman_pgp/model/address.py +++ b/src/mailman_pgp/model/address.py @@ -16,7 +16,7 @@ # this program. If not, see <http://www.gnu.org/licenses/>. """Model for PGP enabled addresses.""" - +import os from os.path import exists, isfile, join from mailman.database.types import SAUnicode @@ -64,6 +64,23 @@ class PGPAddress(Base): self._key, _ = PGPKey.from_file(self.key_path) return self._key + @key.setter + def key(self, new_key): + """ + + :param new_key: + :type new_key: PGPKey + """ + if self.key_fingerprint is not None: + try: + os.remove(self.key_path) + except FileNotFoundError: + pass + self.key_fingerprint = str(new_key.fingerprint) + with open(self.key_path, 'w') as out: + out.write(str(new_key)) + self._key = new_key + @property def key_path(self): """ @@ -86,3 +103,15 @@ class PGPAddress(Base): if self._address is None: self._address = getUtility(IUserManager).get_address(self.email) return self._address + + @staticmethod + def for_address(address): + """ + + :param address: + :return: + :rtype: PGPAddress|None + """ + if address is None: + return None + return PGPAddress.query().filter_by(email=address.email).first() diff --git a/src/mailman_pgp/model/list.py b/src/mailman_pgp/model/list.py index 66f9af3..f8efdd4 100644 --- a/src/mailman_pgp/model/list.py +++ b/src/mailman_pgp/model/list.py @@ -141,3 +141,15 @@ class PGPMailingList(Base): """ return join(config.pgp.keydir_config['list_keydir'], self.list_id + '.asc') + + @staticmethod + def for_list(mlist): + """ + + :param mlist: + :return: + :rtype: PGPMailingList|None + """ + if mlist is None: + return None + return PGPMailingList.query().filter_by(list_id=mlist.list_id).first() |
