diff options
| author | Barry Warsaw | 2016-04-01 15:14:51 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2016-04-01 15:14:51 -0400 |
| commit | f7e9e4698bdd4cee39c9eb485296cbbfa32369a9 (patch) | |
| tree | 6dc8557009cbddb4e416faecc329b38b1cc0ad0b /src/mailman/database/alembic | |
| parent | afdd3b6deb32cd8cfdad291aba173a63064514f8 (diff) | |
| download | mailman-f7e9e4698bdd4cee39c9eb485296cbbfa32369a9.tar.gz mailman-f7e9e4698bdd4cee39c9eb485296cbbfa32369a9.tar.zst mailman-f7e9e4698bdd4cee39c9eb485296cbbfa32369a9.zip | |
Allow fall backs for moderation actions.
The `moderation_action` for members and nonmember can now be ``None``
which signals falling back to the appropriate list default action,
e.g. `default_member_action` and `default_nonmember_action`. Given by
Aurélien Bompard.
Closes #189
Diffstat (limited to 'src/mailman/database/alembic')
| -rw-r--r-- | src/mailman/database/alembic/versions/7b254d88f122_members_and_list_moderation_action.py | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/mailman/database/alembic/versions/7b254d88f122_members_and_list_moderation_action.py b/src/mailman/database/alembic/versions/7b254d88f122_members_and_list_moderation_action.py index 09aedc640..c393528d9 100644 --- a/src/mailman/database/alembic/versions/7b254d88f122_members_and_list_moderation_action.py +++ b/src/mailman/database/alembic/versions/7b254d88f122_members_and_list_moderation_action.py @@ -1,13 +1,12 @@ -"""Members and list moderation action +"""Members and list moderation action. Revision ID: 7b254d88f122 Revises: d4fbb4fd34ca Create Date: 2016-02-10 11:31:04.233619 -This is a data-only migration. If a member has the same moderation action as +This is a data-only migration. If a member has the same moderation action as the mailing list's default, then set its moderation action to None and use the fallback to the list's default. - """ @@ -19,7 +18,7 @@ from mailman.interfaces.action import Action from mailman.interfaces.member import MemberRole -# revision identifiers, used by Alembic. +# Revision identifiers, used by Alembic. revision = '7b254d88f122' down_revision = 'd4fbb4fd34ca' @@ -49,21 +48,24 @@ members_query = member_table.select().where(sa.or_( )) +# list-id -> {property-name -> action} +# +# where property-name will be either default_member_action or +# default_nonmember_action. DEFAULT_ACTION_CACHE = {} +MISSING = object() def _get_default_action(connection, member): list_id = member['list_id'] - propname = 'default_{}_action'.format(member['role'].name) - try: - action = DEFAULT_ACTION_CACHE[list_id][propname] - except KeyError: + property_name = 'default_{}_action'.format(member['role'].name) + list_mapping = DEFAULT_ACTION_CACHE.setdefault(list_id, {}) + action = list_mapping.get(property_name, MISSING) + if action is MISSING: mailing_list = connection.execute(mailinglist_table.select().where( mailinglist_table.c.list_id == list_id)).fetchone() - action = mailing_list[propname] - if list_id not in DEFAULT_ACTION_CACHE: - DEFAULT_ACTION_CACHE[list_id] = {} - DEFAULT_ACTION_CACHE[list_id][propname] = action + action = mailing_list[property_name] + list_mapping[property_name] = action return action @@ -72,7 +74,7 @@ def upgrade(): for member in connection.execute(members_query).fetchall(): default_action = _get_default_action(connection, member) # If the (non)member's moderation action is the same as the mailing - # list's default, then set it to None. The moderation rule will + # list's default, then set it to None. The moderation rule will # fallback to the list's default. if member['moderation_action'] == default_action: connection.execute(member_table.update().where( |
