Hi all,
I want to update some list member's display_name either with mailman shell or mailmanclient. These mostly aren't users in Postorius so I only want to operate on the subscribed list member. I've tried everything I can find in the docs and am stuck.
I've tried using user_manager.get_user()
and then updating user.display_name
followed by a commit()
but it doesn't seem to persist the change.
The absorb_existing
flag for mailmanclient's User.add_address()
looks promising but the docs read "It will import the existing user into the current one, not overwriting any previously set value." which in some cases, the member already has a display_name set. I haven't tried this yet.
I'd appreciate any help pointing in the right direction.
Thanks, Nick
I believe I figured it out.
I was updating user.display_name
when the name I was seeing in Postorius was user.addresses[0].display_name
.
Here are all of the steps for anyone looking to solve the same thing:
from mailman.interfaces.usermanager import IUserManager from zope.component import getUtility from mailman.testing.documentation import dump_list user_manager = getUtility(IUserManager)
u = user_manager.get_user('aperson@example.com') u.addresses[0].display_name = "Anne" commit()
On 1/16/19 7:24 AM, Nick Wynja wrote:
I believe I figured it out.
I was updating
user.display_name
when the name I was seeing in Postorius wasuser.addresses[0].display_name
.Here are all of the steps for anyone looking to solve the same thing:
If you are using mailman shell, the next 2 are not necessary
from mailman.interfaces.usermanager import IUserManager from zope.component import getUtility
IUserManager and getUtility are already in the namespace created when mailman shell starts.
And this one
from mailman.testing.documentation import dump_list
isn't needed here.
user_manager = getUtility(IUserManager)
u = user_manager.get_user('aperson@example.com') u.addresses[0].display_name = "Anne" commit()
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
If you are using mailman shell, the next 2 are not necessary
from mailman.interfaces.usermanager import IUserManager from zope.component import getUtility
IUserManager and getUtility are already in the namespace created when mailman shell starts.
Got it. Thanks, Mark. Is this the right place in the source to see what's imported when mailman shell starts? https://gitlab.com/mailman/mailman/blob/master/src/mailman/commands/cli_with...
On Wed, Jan 16, 2019, at 9:04 AM, Nick Wynja wrote:
If you are using mailman shell, the next 2 are not necessary
from mailman.interfaces.usermanager import IUserManager from zope.component import getUtility
IUserManager and getUtility are already in the namespace created when mailman shell starts.
Got it. Thanks, Mark. Is this the right place in the source to see what's imported when mailman shell starts? https://gitlab.com/mailman/mailman/blob/master/src/mailman/commands/cli_with...
https://gitlab.com/mailman/mailman/blob/master/src/mailman/commands/cli_with...
This is the right place to see the imports injected into the 'mailman shell' environment.
-- thanks, Abhilash Raj (maxking)
On 1/16/19 9:06 AM, Abhilash Raj wrote:
https://gitlab.com/mailman/mailman/blob/master/src/mailman/commands/cli_with...
This is the right place to see the imports injected into the 'mailman shell' environment.
Or you can just do
mailman shell
dir()
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
user_manager = getUtility(IUserManager) u = user_manager.get_user('aperson@example.com') u.addresses[0].display_name = "Anne" commit()
It seems this method updates the display_name for the user across all lists. Is there a way to update just a single instance of "member" of a list rather than the site-wide user?
I've tried this:
mailman shell -l test@example.com
mem = m.members.get_member('a@example.com') mem <Member: a@example.com on test@example.com as MemberRole.member> mem.display_name 'Anne' mem.display_name = "Anne P" Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: can't set attribute
On 1/17/19 8:45 AM, Nick Wynja wrote:
user_manager = getUtility(IUserManager) u = user_manager.get_user('aperson@example.com') u.addresses[0].display_name = "Anne" commit()
It seems this method updates the display_name for the user across all lists. Is there a way to update just a single instance of "member" of a list rather than the site-wide user?
I've tried this:
mailman shell -l test@example.com
mem = m.members.get_member('a@example.com') mem <Member: a@example.com on test@example.com as MemberRole.member> mem.display_name 'Anne' mem.display_name = "Anne P" Traceback (most recent call last): File "<console>", line 1, in <module> AttributeError: can't set attribute
That's because mem.display_name is a "calculated" attribute.
The definition of the IMember class says
display_name = Attribute( """The best match of the member's display name. This will be `subscriber.display_name` if available, which means it will either be the display name of the address or user that's subscribed. If unavailable, and the address is the subscriber, then the linked user's display name is given, if available. When all else fails, the empty string is returned. """)
and
subscriber = Attribute( """The object representing how this member is subscribed. This will be an ``IAddress`` if the user is subscribed via an explicit address, otherwise if the the user is subscribed via their preferred address, it will be an ``IUser``. """)
So there is no member display_name per se. The display_name is the display_name of the associated IUser or IAddress, and these are global.
The bottom line is there is not a way to update just a single instance of "member" of a list rather than the site-wide user or address?
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
On 01/17/19 at 14:43, Mark Sapiro <mark@msapiro.net> wrote:
So there is no member display_name per se. The display_name is the display_name of the associated IUser or IAddress, and these are global.
The bottom line is there is not a way to update just a single instance of "member" of a list rather than the site-wide user or address?
I see; understood. Thanks for explaining.
Hi Mark,
I would like to know if there is a way to update the display_name of the member in a mailing list via REST API?
Having tried updating the display_name of a user but did not seem to work. The display_name did change, but the mailing list still displaying the old name.
Thank you!
On 7/8/20 11:08 AM, rongxinliu@cs50.harvard.edu wrote:
Hi Mark,
I'm not the only developer on this list.
I would like to know if there is a way to update the display_name of the member in a mailing list via REST API?
Having tried updating the display_name of a user but did not seem to work. The display_name did change, but the mailing list still displaying the old name.
By "the mailing list still displaying the old name" do you mean the membership list in Postorius or something else? And to what REST endpoint did you post the display_name?
The bottom line is a user can have multiple display names. Each user has a User record with a display_name attribute, one or more 'addresses', one of which is it's preferred_address. Each one of the addresses is an Address record with it's own email address and display_name.
Now, a member of a list can be either a User or an Address. If it's a User, its display_name is that of the user and it's email address is that of the preferred_address, but if it's an Address, its email and display_name are those of the Address.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
participants (5)
-
Abhilash Raj
-
Mark Sapiro
-
Nick Wynja
-
Nick Wynja
-
rongxinliu@cs50.harvard.edu