Commit dfc1cff7 authored by Barry Warsaw's avatar Barry Warsaw

Add server_owners attribute to the user manager.

parent 4f1fba02
......@@ -126,3 +126,6 @@ class IUserManager(Interface):
members = Attribute(
"""An iterator of all the `IMembers` in the database.""")
server_owners = Attribute(
"""An iterator over all the `IUsers` who are server owners.""")
......@@ -201,3 +201,47 @@ The user has a single unverified address object.
>>> for address in cris.addresses:
... print(repr(address))
<Address: Cris Person <[email protected]> [not verified] at ...>
Server owners
=============
Some users are designated as *server owners*. At first there are no server
owners.
>>> len(list(user_manager.server_owners))
0
Dan is made a server owner.
>>> user_4.is_server_owner = True
>>> owners = list(user_manager.server_owners)
>>> len(owners)
1
>>> owners[0]
<User "Dan Person" (...) at ...>
Now Ben and Claire are also made server owners.
>>> user_2.is_server_owner = True
>>> user_3.is_server_owner = True
>>> owners = list(user_manager.server_owners)
>>> len(owners)
3
>>> from operator import attrgetter
>>> for user in sorted(owners, key=attrgetter('display_name')):
... print(user)
<User "Ben Person" (...) at ...>
<User "Claire Person" (...) at ...>
<User "Dan Person" (...) at ...>
Clair retires as a server owner.
>>> user_3.is_server_owner = False
>>> owners = list(user_manager.server_owners)
>>> len(owners)
2
>>> for user in sorted(owners, key=attrgetter('display_name')):
... print(user)
<User "Ben Person" (...) at ...>
<User "Dan Person" (...) at ...>
......@@ -141,4 +141,11 @@ class UserManager:
def members(self, store):
"""See `IUserManager."""
for member in store.query(Member).all():
yield member
yield member
@property
@dbconnection
def server_owners(self, store):
""" See `IUserManager."""
users = store.query(User).filter_by(is_server_owner=True)
yield from users
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment