diff --git a/src/postorius/forms.py b/src/postorius/forms.py index a264266..a926796 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -155,7 +155,7 @@ (False, _("Hide this list in list index")))) description = forms.CharField( label=_('Description'), - required=True) + required=False) def __init__(self, domain_choices, *args, **kwargs): super(ListNew, self).__init__(*args, **kwargs) @@ -604,6 +604,7 @@ 'on the list of all lists')) description = forms.CharField( label=_('Description'), + required=False, help_text=_( 'This description is used when the mailing list is listed with ' 'other mailing lists, or in headers, and so forth. It should be ' @@ -617,16 +618,19 @@ widget=forms.Textarea()) display_name = forms.CharField( label=_('Display name'), + required=False, help_text=_('Display name is the name shown in the web interface.') ) if get_complete_version() < (1, 9): subject_prefix = forms.CharField( label=_('Subject prefix'), + required=False, ) else: subject_prefix = forms.CharField( label=_('Subject prefix'), strip=False, + required=False, ) diff --git a/src/postorius/tests/fixtures/vcr_cassettes/ListSettingsTest.test_list_identity_allow_empty_prefix_and_desc.yaml b/src/postorius/tests/fixtures/vcr_cassettes/ListSettingsTest.test_list_identity_allow_empty_prefix_and_desc.yaml new file mode 100644 index 0000000..d4de9aa --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/ListSettingsTest.test_list_identity_allow_empty_prefix_and_desc.yaml @@ -0,0 +1,359 @@ +interactions: +- request: + body: !!python/unicode 'mail_host=example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/domains/example.com'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"description": null, "http_etag": "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", + "mail_host": "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com"}'} + headers: + content-length: ['172'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: !!python/unicode 'fqdn_listname=foo%40example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/lists + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/lists/foo.example.com'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: !!python/unicode 'list_id=foo.example.com&role=owner&subscriber=owner%40example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/members/4'] + status: {code: 201, message: Created} +- request: + body: !!python/unicode 'list_id=foo.example.com&role=moderator&subscriber=moderator%40example.com' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'POST' + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + content-type: [application/json; charset=UTF-8] + location: ['http://localhost:9001/3.0/members/5'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": + true, "admin_notify_mchanges": false, "administrivia": true, "advertised": + true, "allow_list_posts": true, "anonymous_list": false, "archive_policy": + "public", "autorespond_owner": "none", "autorespond_postings": "none", "autorespond_requests": + "none", "autoresponse_grace_period": "90d", "autoresponse_owner_text": "", + "autoresponse_postings_text": "", "autoresponse_request_text": "", "bounces_address": + "foo-bounces@example.com", "collapse_alternatives": true, "convert_html_to_plaintext": + false, "created_at": "2005-08-01T07:49:23", "default_member_action": "defer", + "default_nonmember_action": "hold", "description": "", "digest_footer_uri": + "", "digest_header_uri": "", "digest_last_sent_at": null, "digest_send_periodic": + true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", + "digests_enabled": true, "display_name": "Foo", "filter_content": false, "first_strip_reply_to": + false, "footer_uri": "", "fqdn_listname": "foo@example.com", "goodbye_message_uri": + "", "header_uri": "", "http_etag": "\"e752899e2a568ccaad1d891e72c137a4cbc82d5d\"", + "include_rfc2369_headers": true, "info": "", "join_address": "foo-join@example.com", + "last_post_at": null, "leave_address": "foo-leave@example.com", "list_name": + "foo", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "foo-owner@example.com", + "post_id": 1, "posting_address": "foo@example.com", "posting_pipeline": "default-posting-pipeline", + "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": + "foo-request@example.com", "send_welcome_message": true, "subject_prefix": + "[Foo] ", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": + ""}'} + headers: + content-length: ['1789'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": + true, "admin_notify_mchanges": false, "administrivia": true, "advertised": + true, "allow_list_posts": true, "anonymous_list": false, "archive_policy": + "public", "autorespond_owner": "none", "autorespond_postings": "none", "autorespond_requests": + "none", "autoresponse_grace_period": "90d", "autoresponse_owner_text": "", + "autoresponse_postings_text": "", "autoresponse_request_text": "", "bounces_address": + "foo-bounces@example.com", "collapse_alternatives": true, "convert_html_to_plaintext": + false, "created_at": "2005-08-01T07:49:23", "default_member_action": "defer", + "default_nonmember_action": "hold", "description": "", "digest_footer_uri": + "", "digest_header_uri": "", "digest_last_sent_at": null, "digest_send_periodic": + true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", + "digests_enabled": true, "display_name": "Foo", "filter_content": false, "first_strip_reply_to": + false, "footer_uri": "", "fqdn_listname": "foo@example.com", "goodbye_message_uri": + "", "header_uri": "", "http_etag": "\"e752899e2a568ccaad1d891e72c137a4cbc82d5d\"", + "include_rfc2369_headers": true, "info": "", "join_address": "foo-join@example.com", + "last_post_at": null, "leave_address": "foo-leave@example.com", "list_name": + "foo", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "foo-owner@example.com", + "post_id": 1, "posting_address": "foo@example.com", "posting_pipeline": "default-posting-pipeline", + "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": + "foo-request@example.com", "send_welcome_message": true, "subject_prefix": + "[Foo] ", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": + ""}'} + headers: + content-length: ['1789'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: !!python/unicode 'display_name=&subject_prefix=' + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded'] + method: !!python/unicode 'PATCH' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com + response: + body: {string: !!python/unicode '{"display_name": "", "fqdn_listname": "foo@example.com", + "http_etag": "\"804365ad54f1009e0542f8c06e35586a7c53067f\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['291'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": + true, "admin_notify_mchanges": false, "administrivia": true, "advertised": + true, "allow_list_posts": true, "anonymous_list": false, "archive_policy": + "public", "autorespond_owner": "none", "autorespond_postings": "none", "autorespond_requests": + "none", "autoresponse_grace_period": "90d", "autoresponse_owner_text": "", + "autoresponse_postings_text": "", "autoresponse_request_text": "", "bounces_address": + "foo-bounces@example.com", "collapse_alternatives": true, "convert_html_to_plaintext": + false, "created_at": "2005-08-01T07:49:23", "default_member_action": "defer", + "default_nonmember_action": "hold", "description": "", "digest_footer_uri": + "", "digest_header_uri": "", "digest_last_sent_at": null, "digest_send_periodic": + true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", + "digests_enabled": true, "display_name": "", "filter_content": false, "first_strip_reply_to": + false, "footer_uri": "", "fqdn_listname": "foo@example.com", "goodbye_message_uri": + "", "header_uri": "", "http_etag": "\"a72e55f425f88527d245e4536c1dae1a072a3171\"", + "include_rfc2369_headers": true, "info": "", "join_address": "foo-join@example.com", + "last_post_at": null, "leave_address": "foo-leave@example.com", "list_name": + "foo", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "foo-owner@example.com", + "post_id": 1, "posting_address": "foo@example.com", "posting_pipeline": "default-posting-pipeline", + "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": + "foo-request@example.com", "send_welcome_message": true, "subject_prefix": + "", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": + ""}'} + headers: + content-length: ['1780'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo.example.com + response: + body: {string: !!python/unicode '{"display_name": "", "fqdn_listname": "foo@example.com", + "http_etag": "\"804365ad54f1009e0542f8c06e35586a7c53067f\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['291'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/lists/foo@example.com/config + response: + body: {string: !!python/unicode '{"acceptable_aliases": [], "admin_immed_notify": + true, "admin_notify_mchanges": false, "administrivia": true, "advertised": + true, "allow_list_posts": true, "anonymous_list": false, "archive_policy": + "public", "autorespond_owner": "none", "autorespond_postings": "none", "autorespond_requests": + "none", "autoresponse_grace_period": "90d", "autoresponse_owner_text": "", + "autoresponse_postings_text": "", "autoresponse_request_text": "", "bounces_address": + "foo-bounces@example.com", "collapse_alternatives": true, "convert_html_to_plaintext": + false, "created_at": "2005-08-01T07:49:23", "default_member_action": "defer", + "default_nonmember_action": "hold", "description": "", "digest_footer_uri": + "", "digest_header_uri": "", "digest_last_sent_at": null, "digest_send_periodic": + true, "digest_size_threshold": 30.0, "digest_volume_frequency": "monthly", + "digests_enabled": true, "display_name": "", "filter_content": false, "first_strip_reply_to": + false, "footer_uri": "", "fqdn_listname": "foo@example.com", "goodbye_message_uri": + "", "header_uri": "", "http_etag": "\"a72e55f425f88527d245e4536c1dae1a072a3171\"", + "include_rfc2369_headers": true, "info": "", "join_address": "foo-join@example.com", + "last_post_at": null, "leave_address": "foo-leave@example.com", "list_name": + "foo", "mail_host": "example.com", "moderator_password": null, "next_digest_number": + 1, "no_reply_address": "noreply@example.com", "owner_address": "foo-owner@example.com", + "post_id": 1, "posting_address": "foo@example.com", "posting_pipeline": "default-posting-pipeline", + "reply_goes_to_list": "no_munging", "reply_to_address": "", "request_address": + "foo-request@example.com", "send_welcome_message": true, "subject_prefix": + "", "subscription_policy": "confirm", "volume": 1, "welcome_message_uri": + ""}'} + headers: + content-length: ['1780'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode '{"entries": [{"description": null, "http_etag": + "\"d150abd34fabbcef42a2c654bfac81aa04ea4d6f\"", "mail_host": "example.com", + "self_link": "http://localhost:9001/3.0/domains/example.com"}], "http_etag": + "\"2ec9679269ad1f741705a62db0162f5585ae5c3c\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['277'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'GET' + uri: http://localhost:9001/3.0/users + response: + body: {string: !!python/unicode '{"entries": [{"created_on": "2005-08-01T07:49:23", + "http_etag": "\"bb1c2e6094a96b17e2d5dbf487291f7667f69f75\"", "is_server_owner": + false, "self_link": "http://localhost:9001/3.0/users/3", "user_id": 3}, {"created_on": + "2005-08-01T07:49:23", "http_etag": "\"c1dcbf16536eb2e2151441f4bce2989ab1dab30b\"", + "is_server_owner": false, "self_link": "http://localhost:9001/3.0/users/4", + "user_id": 4}, {"created_on": "2005-08-01T07:49:23", "http_etag": "\"637c12d15eb0203c9ffac9ea2d5ac8605d18e38d\"", + "is_server_owner": false, "self_link": "http://localhost:9001/3.0/users/5", + "user_id": 5}], "http_etag": "\"a05cdb95d5f49c1a8d1c561c6836ef388371f682\"", + "start": 0, "total_size": 3}'} + headers: + content-length: ['673'] + content-type: [application/json; charset=UTF-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/users/3 + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/users/4 + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode 'DELETE' + uri: http://localhost:9001/3.0/users/5 + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +version: 1 diff --git a/src/postorius/tests/mailman_api_tests/test_list_settings.py b/src/postorius/tests/mailman_api_tests/test_list_settings.py index 784f70e..5c4c891 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_settings.py +++ b/src/postorius/tests/mailman_api_tests/test_list_settings.py @@ -133,7 +133,7 @@ self.assertEqual(response.status_code, 200) form = response.context["form"] self.assertEqual( - form.initial['first_strip_reply_to'], False) + form.initial['first_strip_reply_to'], 'False') post_data = dict( (key, unicode(self.foo_list.settings[key])) for key in form.fields) @@ -144,3 +144,21 @@ # Get a new list object to avoid caching m_list = List.objects.get(fqdn_listname='foo.example.com') self.assertEqual(m_list.settings['first_strip_reply_to'], True) + + def test_list_identity_allow_empty_prefix_and_desc(self): + self.assertEqual(self.foo_list.settings['subject_prefix'], '[Foo] ') + self.assertEqual(self.foo_list.settings['description'], '') + self.client.login(username='testsu', password='testpass') + url = reverse('list_settings', + args=('foo.example.com', 'list_identity')) + response = self.client.post(url, { + 'subject_prefix': '', + 'description': '', + 'advertised': 'True', + }) + self.assertRedirects(response, url) + self.assertHasSuccessMessage(response) + # Get a new list object to avoid caching + m_list = List.objects.get(fqdn_listname='foo.example.com') + self.assertEqual(m_list.settings['subject_prefix'], '') + self.assertEqual(m_list.settings['description'], '') diff --git a/src/postorius/views/list.py b/src/postorius/views/list.py index 936bbb7..a620762 100644 --- a/src/postorius/views/list.py +++ b/src/postorius/views/list.py @@ -527,7 +527,9 @@ form.cleaned_data['listname']) mailing_list.add_owner(form.cleaned_data['list_owner']) list_settings = mailing_list.settings - list_settings["description"] = form.cleaned_data['description'] + if form.cleaned_data['description']: + list_settings["description"] = \ + form.cleaned_data['description'] list_settings["advertised"] = form.cleaned_data['advertised'] list_settings.save() messages.success(request, _("List created")) @@ -684,10 +686,10 @@ list_settings = m_list.settings except (MailmanApiError, HTTPError): return utils.render_api_error(request) + initial_data = dict( + (key, unicode(value)) for key, value in list_settings.items()) # List settings are grouped an processed in different forms. if request.method == 'POST': - initial_data = dict( - (key, unicode(value)) for key, value in list_settings.items()) form = form_class(request.POST, mlist=m_list, initial=initial_data) if form.is_valid(): try: @@ -702,7 +704,7 @@ messages.error(request, _('An error occured: %s') % e.reason) return redirect('list_settings', m_list.list_id, visible_section) else: - form = form_class(initial=dict(list_settings), mlist=m_list) + form = form_class(initial=initial_data, mlist=m_list) return render(request, template, { 'form': form,