diff --git a/src/postorius/forms.py b/src/postorius/forms.py index 665d5ba..d8e9e34 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -23,6 +23,15 @@ from postorius.fieldset_forms import FieldsetForm +ACTION_CHOICES = ( + ("hold", _("Hold for moderation")), + ("reject", _("Reject (with notification)")), + ("discard", _("Discard (no notification)")), + ("accept", _("Accept immediately (bypass other rules)")), + ("defer", _("Default processing")), + ) + + class ListOfStringsField(forms.Field): widget = forms.widgets.Textarea @@ -222,12 +231,6 @@ """ List messages acceptance settings. """ - action_choices = ( - ("hold", _("Hold for moderation")), - ("reject", _("Reject (with notification)")), - ("discard", _("Discard (no notification)")), - ("accept", _("Accept immediately (bypass other rules)")), - ("defer", _("Default processing"))) acceptable_aliases = ListOfStringsField( label=_("Acceptable aliases"), required=False, @@ -255,18 +258,19 @@ error_messages={ 'required': _("Please choose a default member action.")}, required=True, - choices=action_choices, + choices=ACTION_CHOICES, help_text=_( 'Default action to take when a member posts to the list. ' 'Hold -- This holds the message for approval by the list ' - 'moderators.' + 'moderators. ' 'Reject -- this automatically rejects the message by sending a ' 'bounce notice to the post\'s author. The text of the bounce ' 'notice can be configured by you. ' 'Discard -- this simply discards the message, with no notice ' 'sent to the post\'s author. ' - 'Accept --accepts any postings to the list by default. ' - 'Defer -- Defers any postings to the list by default. ')) + 'Accept -- accepts any postings without any further checks. ' + 'Defer -- default processing, run additional checks and accept ' + 'the message. ')) default_nonmember_action = forms.ChoiceField( widget=forms.RadioSelect(), label=_('Default action to take when a non-member posts to the' @@ -274,7 +278,7 @@ error_messages={ 'required': _("Please choose a default non-member action.")}, required=True, - choices=action_choices, + choices=ACTION_CHOICES, help_text=_( 'When a post from a non-member is received, the message\'s sender ' 'is matched against the list of explicitly accepted, held, ' @@ -708,6 +712,31 @@ "delivery_mode", "delivery_status"]] +class MemberModeration(FieldsetForm): + """ + Form handling the member's moderation_action. + """ + moderation_action = forms.ChoiceField( + widget=forms.Select(), + label=_('Moderation'), + error_messages={ + 'required': _("Please choose a moderation action.")}, + required=True, + choices=ACTION_CHOICES, + help_text=_( + 'Default action to take when this member posts to the list. ' + 'Hold -- This holds the message for approval by the list ' + 'moderators. ' + 'Reject -- this automatically rejects the message by sending a ' + 'bounce notice to the post\'s author. The text of the bounce ' + 'notice can be configured by you. ' + 'Discard -- this simply discards the message, with no notice ' + 'sent to the post\'s author. ' + 'Accept -- accepts any postings without any further checks. ' + 'Defer -- default processing, run additional checks and accept ' + 'the message. ')) + + class UserNew(FieldsetForm): """ diff --git a/src/postorius/templates/postorius/lists/memberoptions.html b/src/postorius/templates/postorius/lists/memberoptions.html index eff7aa1..0e1c497 100644 --- a/src/postorius/templates/postorius/lists/memberoptions.html +++ b/src/postorius/templates/postorius/lists/memberoptions.html @@ -17,7 +17,17 @@ {% else %}
{% render_form_horizontal preferences_form 3 8 'Save changes' %} +
+
+
Administration options
+
+
+ {% render_form_horizontal moderation_form 3 8 'Save changes' %} + +
+
+
{% endif %} {% endblock main %} diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 873e81f..3d90b69 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -108,30 +108,56 @@ member_prefs = mm_member.preferences except Mailman404Error: return render(request, template_name, {'nolists': 'true'}) + initial_moderation = dict([ + (key, getattr(mm_member, key)) for key in MemberModeration.base_fields + ]) if request.method == 'POST': - preferences_form = UserPreferences( - request.POST, initial=member_prefs) - if preferences_form.is_valid(): - if not preferences_form.has_changed(): - messages.info(request, - _("No change to the member's preferences.")) - return redirect('list_member_options', list_id, email) - for key in preferences_form.fields.keys(): - member_prefs[key] = preferences_form.cleaned_data[key] - try: - member_prefs.save() - except HTTPError as e: - messages.error(request, e.msg) - else: - messages.success(request, - _("The member's preferences have been updated.")) - return redirect('list_member_options', list_id, email) + if request.POST.get("formname") == 'preferences': + moderation_form = MemberModeration(initial=initial_moderation) + preferences_form = UserPreferences( + request.POST, initial=member_prefs) + if preferences_form.is_valid(): + if not preferences_form.has_changed(): + messages.info(request, + _("No change to the member's preferences.")) + return redirect('list_member_options', list_id, email) + for key in preferences_form.fields.keys(): + member_prefs[key] = preferences_form.cleaned_data[key] + try: + member_prefs.save() + except HTTPError as e: + messages.error(request, e.msg) + else: + messages.success(request, + _("The member's preferences have been updated.")) + return redirect('list_member_options', list_id, email) + elif request.POST.get("formname") == 'moderation': + preferences_form = UserPreferences(initial=member_prefs) + moderation_form = MemberModeration( + request.POST, initial=initial_moderation) + if moderation_form.is_valid(): + if not moderation_form.has_changed(): + messages.info(request, + _("No change to the member's moderation.")) + return redirect('list_member_options', list_id, email) + for key in moderation_form.fields.keys(): + setattr(mm_member, key, moderation_form.cleaned_data[key]) + try: + mm_member.save() + except HTTPError as e: + messages.error(request, e.msg) + else: + messages.success(request, + _("The member's moderation settings have been updated.")) + return redirect('list_member_options', list_id, email) else: preferences_form = UserPreferences(initial=member_prefs) + moderation_form = MemberModeration(initial=initial_moderation) return render(request, template_name, { 'mm_member': mm_member, 'list': mm_list, 'preferences_form': preferences_form, + 'moderation_form': moderation_form, })