1 # Copyright (C) 2007-2023 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <https://www.gnu.org/licenses/>.
18 """Interface describing the basics of a user."""
20 from mailman
.interfaces
.address
import AddressError
21 from public
import public
22 from zope
.interface
import Attribute
, Interface
26 class UnverifiedAddressError(AddressError
):
27 """Unverified address cannot be used as a user's preferred address."""
31 class PasswordChangeEvent
:
32 """Event which gets triggered when a user changes their password."""
34 def __init__(self
, user
):
38 return '<{} {}>'.format(
39 self
.__class
__.__name
__, self
.user
.display_name
)
43 class IUser(Interface
):
46 display_name
= Attribute(
47 """This user's display name.""")
50 """This user's password information.""")
53 """The user's unique, random identifier as a UUID.""")
55 created_on
= Attribute(
56 """The date and time at which this user was created.""")
58 addresses
= Attribute(
59 """An iterator over all the `IAddresses` controlled by this user.""")
61 preferred_address
= Attribute(
62 """The user's preferred `IAddress`. This must be validated.""")
64 memberships
= Attribute(
65 """A roster of this user's memberships.""")
67 is_server_owner
= Attribute(
68 """Boolean flag indicating whether the user is a server owner.""")
70 def register(email
, display_name
=None):
71 """Register the given email address and link it to this user.
73 :param email: The text email address to register.
75 :param display_name: The user's display name. If not given the empty
77 :type display_name: str
78 :return: The address object linked to the user. If the associated
79 address object already existed (unlinked to a user) then the
80 `display_name` parameter is ignored.
82 :raises AddressAlreadyLinkedError: if this `IAddress` is already
83 linked to another user.
87 """Link this user to the given IAddress.
89 Raises AddressAlreadyLinkedError if this IAddress is already linked to
94 """Unlink this IAddress from the user.
96 Raises AddressNotLinkedError if this address is not linked to this
97 user, either because it's not linked to any user or it's linked to
102 """Determine whether this user controls the given email address.
104 :param email: The text email address to register.
106 :return: True if the user controls the given email address.
110 preferences
= Attribute(
111 """This user's preferences.""")
114 """Merge the given user to ourself.
116 All IAddresses linked to `user` are relinked to ourself. A
117 memberships associated with `user` are changed to be memberships
118 with ourself. See `IPreferences.absorb()`.
120 The user's `display_name`, `password`, and `is_server_owner` settings
121 are absorbed into ours, but only if ours is unset and the given user's
124 After being absorbed, the given user and its preferences are
127 It is not an error if `user` is ourself, but it is a no-op.
129 :param user: The user to merge into ourself.
131 :raises TypeError: if `user` is not a user.