summaryrefslogtreecommitdiff
path: root/src/mailman/rest/users.py
diff options
context:
space:
mode:
authorBarry Warsaw2011-04-04 14:32:17 -0400
committerBarry Warsaw2011-04-04 14:32:17 -0400
commit17887e4d1e56915647e1d395e18573db2b9ea3ba (patch)
tree8dc9f275e878539040ee25857593570aca1ec113 /src/mailman/rest/users.py
parentcd18f50624f33a9556492168933d5fe088d51a04 (diff)
downloadmailman-17887e4d1e56915647e1d395e18573db2b9ea3ba.tar.gz
mailman-17887e4d1e56915647e1d395e18573db2b9ea3ba.tar.zst
mailman-17887e4d1e56915647e1d395e18573db2b9ea3ba.zip
More fleshing out of the users REST API.
* Add a 'uid factory' which allows us to return predictable unique ids for various testing purposes, e.g. user ids. This should work even in the case of cross-subprocess uid generation. * REST access to individual users, or the set of all users. * User objects now have a created_on attribute. * Users can be created through the web, but must have an email address. * Add a [devmode] 'testing' variable for communicating to qrunner subprocesses that we're running in testing mode. This allows us to coordinate factories and such in the qrunner processes. * layers.is_testing() for more consistent API. * Give AddressError a .address attribute for better diagnostics.
Diffstat (limited to '')
-rw-r--r--src/mailman/rest/users.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py
index cf66a6d4e..b8972f3f5 100644
--- a/src/mailman/rest/users.py
+++ b/src/mailman/rest/users.py
@@ -29,8 +29,10 @@ __all__ = [
from restish import http, resource
from zope.component import getUtility
+from mailman.interfaces.address import ExistingAddressError
from mailman.interfaces.usermanager import IUserManager
-from mailman.rest.helpers import CollectionMixin, etag
+from mailman.rest.helpers import CollectionMixin, etag, path_to
+from mailman.rest.validator import Validator
@@ -46,6 +48,7 @@ class _UserBase(resource.Resource, CollectionMixin):
real_name=user.real_name,
password=user.password,
user_id=user.user_id,
+ created_on=user.created_on,
)
def _get_collection(self, request):
@@ -63,6 +66,30 @@ class AllUsers(_UserBase):
resource = self._make_collection(request)
return http.ok([], etag(resource))
+ @resource.POST()
+ def create(self, request):
+ """Create a new user."""
+ try:
+ validator = Validator(email=unicode,
+ real_name=unicode,
+ password=unicode,
+ _optional=('real_name', 'password'))
+ arguments = validator(request)
+ except ValueError as error:
+ return http.bad_request([], str(error))
+ # We can't pass the 'password' argument to the user creation method,
+ # so strip that out (if it exists), then create the user, adding the
+ # password after the fact if successful.
+ password = arguments.pop('password', None)
+ try:
+ user = getUtility(IUserManager).create_user(**arguments)
+ except ExistingAddressError as error:
+ return http.bad_request([], b'Address already exists {0}'.format(
+ error.email))
+ # XXX ignore password for now.
+ location = path_to('users/{0}'.format(user.user_id))
+ return http.created(location, [], None)
+
class AUser(_UserBase):