[Mailman-Developers] Mailman3: creating a user from an existing address

Barry Warsaw barry at list.org
Fri Apr 25 18:06:37 CEST 2014


On Apr 25, 2014, at 04:55 PM, Aurelien Bompard wrote:

>I'm trying to create a User in Mailman 3 from an existing Address. If I were
>using the Python interface, that would be very easy: just create the user
>with no address and then link the existing address to it.

So the address is currently unlinked?  And you don't want to link it to an
existing user, but to a new user you're about to create?

>However, I'm using the REST interface. In
>mailman.rest.users.AllUser.create(), there's a try/except block which
>explicitely looks for this case and raises an HTTP 400 error. Looking at the
>test_existing_user_error() test case, it's apparently to prevent creating a
>user twice, which is not my use case.  Are you OK if I hack the code to
>automatically link to an existing address while still erroring-out if the
>user already exist?  Or would it be better to allow linking to an existing
>address from the REST API?

The other way to think about it is that you might want to create the user and
link to it from the existing address resource, i.e. the AnAddress class.

Right now, you cannot get directly from the address to its linked user, if it
has one.  Look at _AddressBase._resource_as_dict() in addresses.py.

Sketching out an approach:

 - The address resource would gain a `user` key if there is a linked user.
   This would be a url to the user resource.  If the address is unlinked, then
   there would be no such key.

 - AnAddress would gain a /user sub-resource which would either 404 if the
   address is unlinked or return the linked user's JSON data.

 - POSTing to /addresses/<email>/user would create a new user and link the
   address to it, but only if the address is not yet linked.  If it's already
   linked, you'd get a 409 Conflict error.  If the new user is created, you'd
   get 201 Created response.

Additional use cases to consider:

Q. What if the address is already linked and you want to unlink it?

A. DELETE on the /addresses/<email>/user resource

Q. What if you want to change the user the address is linked to?

A. Currently, it's two operations: DELETE the existing link as above, then see
   below.  The other option is to allow a PUT on the /addresses/<email>/user
   resource.

Q. What if you want to link the unlinked address to an existing user?

A. Maybe allow this in the POST to /addresses/<email>/user, i.e. the user
   would only be created if it doesn't yet exist.  If it gets created, you'd
   get a 201 Created, but if it's just a link operation to an existing user,
   you'd get a 200 Success response.

   It's possibly you'd want to include POST boolean that specifies whether
   creating a new user is okay or not, with the appropriate response codes in
   the false case.

-Barry


More information about the Mailman-Developers mailing list