28
28
from zope.interface import implements
30
from mailman.config import config
30
from mailman.database.transaction import dbconnection
31
31
from mailman.interfaces.address import ExistingAddressError
32
32
from mailman.interfaces.usermanager import IUserManager
33
33
from mailman.model.address import Address
51
def delete_user(self, user):
52
def delete_user(self, store, user):
52
53
"""See `IUserManager`."""
53
config.db.store.remove(user)
55
def get_user(self, email):
57
def get_user(self, store, email):
56
58
"""See `IUserManager`."""
57
addresses = config.db.store.find(Address, email=email.lower())
59
addresses = store.find(Address, email=email.lower())
58
60
if addresses.count() == 0:
60
62
return addresses.one().user
62
def get_user_by_id(self, user_id):
65
def get_user_by_id(self, store, user_id):
63
66
"""See `IUserManager`."""
64
users = config.db.store.find(User, _user_id=user_id)
67
users = store.find(User, _user_id=user_id)
65
68
if users.count() == 0:
74
def users(self, store):
71
75
"""See `IUserManager`."""
72
for user in config.db.store.find(User):
76
for user in store.find(User):
75
def create_address(self, email, display_name=None):
80
def create_address(self, store, email, display_name=None):
76
81
"""See `IUserManager`."""
77
addresses = config.db.store.find(Address, email=email.lower())
82
addresses = store.find(Address, email=email.lower())
78
83
if addresses.count() == 1:
79
84
found = addresses[0]
80
85
raise ExistingAddressError(found.original_email)
85
90
# constructor will do the right thing.
86
91
address = Address(email, display_name)
87
92
address.preferences = Preferences()
88
config.db.store.add(address)
91
def delete_address(self, address):
97
def delete_address(self, store, address):
92
98
"""See `IUserManager`."""
93
99
# If there's a user controlling this address, it has to first be
94
100
# unlinked before the address can be deleted.
96
102
address.user.unlink(address)
97
config.db.store.remove(address)
103
store.remove(address)
99
def get_address(self, email):
106
def get_address(self, store, email):
100
107
"""See `IUserManager`."""
101
addresses = config.db.store.find(Address, email=email.lower())
108
addresses = store.find(Address, email=email.lower())
102
109
if addresses.count() == 0:
104
111
return addresses.one()
115
def addresses(self, store):
108
116
"""See `IUserManager`."""
109
for address in config.db.store.find(Address):
117
for address in store.find(Address):
122
def members(self, store):
114
123
"""See `IUserManager."""
115
for member in config.db.store.find(Member):
124
for member in store.find(Member):