diff --git a/src/postorius/forms.py b/src/postorius/forms.py index 57c72fd..3f37460 100644 --- a/src/postorius/forms.py +++ b/src/postorius/forms.py @@ -830,6 +830,19 @@ return email +class ChangeDisplayNameForm(forms.Form): + """ + Change display name. + """ + + display_name = forms.CharField( + label=_('Display name'), + error_messages={ + 'required': _('Please enter a display name')}, + required=True + ) + + class ChangeSubscriptionForm(forms.Form): email = forms.ChoiceField() diff --git a/src/postorius/templates/postorius/user/profile.html b/src/postorius/templates/postorius/user/profile.html index 667f323..45f9c7a 100644 --- a/src/postorius/templates/postorius/user/profile.html +++ b/src/postorius/templates/postorius/user/profile.html @@ -36,6 +36,10 @@
+
+ {% render_form_horizontal name_form 2 5 'Change display name' %} + +

{% blocktrans %} You can add other addresses to your profile, diff --git a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_change_display_name.yaml b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_change_display_name.yaml new file mode 100644 index 0000000..3954393 --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_change_display_name.yaml @@ -0,0 +1,129 @@ +interactions: +- request: + body: email=les%40example.org + 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/users + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/users/30'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/users/les@example.org + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"c00fc606394cf49ec80428acaa232d09bfe0217e\"", "is_server_owner": false, + "password": "$6$rounds=609804$czHjKJQcPm5zGXNd$WvmPL9LDx0LVxsDZGT.jBnkaua0RVxfG1nYqe.0I.Zx8w8O1revKE6V2Y3ysJtWGKMXFbc18DjfIWr/1VH.IL1", + "self_link": "http://localhost:9001/3.0/users/30", "user_id": 30}'} + headers: + content-length: ['326'] + 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/users/30/addresses + response: + body: {string: !!python/unicode '{"entries": [{"email": "les@example.org", "http_etag": + "\"b93a5f58b47e659a7de9b8e690adbbd7a9a37365\"", "original_email": "les@example.org", + "registered_on": "2005-08-01T07:49:23", "self_link": "http://localhost:9001/3.0/addresses/les@example.org", + "user": "http://localhost:9001/3.0/users/30"}], "http_etag": "\"7ad219cc3e8d4c55ecfde78853d61d3e4d2057c8\"", + "start": 0, "total_size": 1}'} + headers: + content-length: ['385'] + 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/users/les@example.org + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"c00fc606394cf49ec80428acaa232d09bfe0217e\"", "is_server_owner": false, + "password": "$6$rounds=609804$czHjKJQcPm5zGXNd$WvmPL9LDx0LVxsDZGT.jBnkaua0RVxfG1nYqe.0I.Zx8w8O1revKE6V2Y3ysJtWGKMXFbc18DjfIWr/1VH.IL1", + "self_link": "http://localhost:9001/3.0/users/30", "user_id": 30}'} + headers: + content-length: ['326'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: display_name=testname + 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/users/30 + 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/30 + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "display_name": + "testname", "http_etag": "\"c779bcf5ba77ed5c9a37967ccd2c08171ece4f12\"", "is_server_owner": + false, "password": "$6$rounds=609804$czHjKJQcPm5zGXNd$WvmPL9LDx0LVxsDZGT.jBnkaua0RVxfG1nYqe.0I.Zx8w8O1revKE6V2Y3ysJtWGKMXFbc18DjfIWr/1VH.IL1", + "self_link": "http://localhost:9001/3.0/users/30", "user_id": 30}'} + headers: + content-length: ['354'] + 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 '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", + "start": 0, "total_size": 0}'} + headers: + content-length: ['90'] + 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/users + response: + body: {string: !!python/unicode '{"entries": [{"created_on": "2005-08-01T07:49:23", + "display_name": "testname", "http_etag": "\"c779bcf5ba77ed5c9a37967ccd2c08171ece4f12\"", + "is_server_owner": false, "password": "$6$rounds=609804$czHjKJQcPm5zGXNd$WvmPL9LDx0LVxsDZGT.jBnkaua0RVxfG1nYqe.0I.Zx8w8O1revKE6V2Y3ysJtWGKMXFbc18DjfIWr/1VH.IL1", + "self_link": "http://localhost:9001/3.0/users/30", "user_id": 30}], "http_etag": + "\"e634e988fcb8f7e74dc2cf53588b6b882847e38b\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['459'] + 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/30 + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +version: 1 diff --git a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_form_with_smtp_exception.yaml b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_form_with_smtp_exception.yaml index 15055cd..d5044e3 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_form_with_smtp_exception.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_form_with_smtp_exception.yaml @@ -34,13 +34,28 @@ body: {string: !!python/unicode ''} headers: content-length: ['0'] - location: ['http://localhost:9001/3.0/users/1'] + location: ['http://localhost:9001/3.0/users/31'] status: {code: 201, message: Created} - request: body: null headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET + uri: http://localhost:9001/3.0/users/31 + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"8b15a48e7aab768121255eeaa51c1cd583d03bfc\"", "is_server_owner": false, + "password": "$6$rounds=674662$y/H9BwjRxwSe.L9R$zcYWTsgjx2J/7AUQRFoACDYeqBNIrsjxuz1SLKXvQrXjutVmnM5uVhU9Riub2vz/JETHwOJly9dgjTAVuUnSU0", + "self_link": "http://localhost:9001/3.0/users/31", "user_id": 31}'} + headers: + content-length: ['326'] + 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/users/new_address@example.org response: body: {string: !!python/unicode 404 Not Found} @@ -53,21 +68,6 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET - uri: http://localhost:9001/3.0/users/1 - response: - body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": - "\"7638b81bc998c9ab658fe1a667546f1a31e4bdbf\"", "is_server_owner": false, - "password": "$6$rounds=717826$Wh5Czxm6hOIUZ6rs$0y0MQM877DONrCx6pgYVmTEztIEMV7NO7oYf8NXlhNxDT2OHNFvQppIdZdtPMXy8HAJiHRUWE1RSG26cdKOgm/", - "self_link": "http://localhost:9001/3.0/users/1", "user_id": 1}'} - headers: - content-length: ['324'] - 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 '{"http_etag": "\"32223434a0f3af4cdc4673d1fbc5bac1f6d98fd3\"", @@ -84,13 +84,13 @@ uri: http://localhost:9001/3.0/users response: body: {string: !!python/unicode '{"entries": [{"created_on": "2005-08-01T07:49:23", - "http_etag": "\"7638b81bc998c9ab658fe1a667546f1a31e4bdbf\"", "is_server_owner": - false, "password": "$6$rounds=717826$Wh5Czxm6hOIUZ6rs$0y0MQM877DONrCx6pgYVmTEztIEMV7NO7oYf8NXlhNxDT2OHNFvQppIdZdtPMXy8HAJiHRUWE1RSG26cdKOgm/", - "self_link": "http://localhost:9001/3.0/users/1", "user_id": 1}], "http_etag": - "\"ad6c7ac43730c716afad4e5c758969e91155e82d\"", "start": 0, "total_size": + "http_etag": "\"8b15a48e7aab768121255eeaa51c1cd583d03bfc\"", "is_server_owner": + false, "password": "$6$rounds=674662$y/H9BwjRxwSe.L9R$zcYWTsgjx2J/7AUQRFoACDYeqBNIrsjxuz1SLKXvQrXjutVmnM5uVhU9Riub2vz/JETHwOJly9dgjTAVuUnSU0", + "self_link": "http://localhost:9001/3.0/users/31", "user_id": 31}], "http_etag": + "\"69af0738b7dd16acdb295ee705581069cf574dc2\"", "start": 0, "total_size": 1}'} headers: - content-length: ['429'] + content-length: ['431'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -98,7 +98,7 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode DELETE - uri: http://localhost:9001/3.0/users/1 + uri: http://localhost:9001/3.0/users/31 response: body: {string: !!python/unicode ''} headers: diff --git a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_invalid_form_shows_error_msg.yaml b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_invalid_form_shows_error_msg.yaml index 9eac38f..5541615 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_invalid_form_shows_error_msg.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_invalid_form_shows_error_msg.yaml @@ -34,21 +34,21 @@ body: {string: !!python/unicode ''} headers: content-length: ['0'] - location: ['http://localhost:9001/3.0/users/2'] + location: ['http://localhost:9001/3.0/users/32'] status: {code: 201, message: Created} - request: body: null headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET - uri: http://localhost:9001/3.0/users/2 + uri: http://localhost:9001/3.0/users/32 response: body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": - "\"1a3aa88b2cd54f39cc383ee227e4fe2e5523a053\"", "is_server_owner": false, - "password": "$6$rounds=685646$vZ6MnU/EhjWMmJj/$bP0uRgUcHzu/94frX6.ypX7w2W4l/xz5zG.p3RqBiFeISayJc6G/U98lJjdsNVEGQEd6qBDK4w4rultFTkB9Z/", - "self_link": "http://localhost:9001/3.0/users/2", "user_id": 2}'} + "\"c35ee9d7f435114a9bbd393f1997d9ad90b639d0\"", "is_server_owner": false, + "password": "$6$rounds=684549$au8U5LcyUMdQO.hH$KVF7NcArszy8kOozZ2A1W/.j/Bp7H2fgI.jOY7dmzPoD0Ltauo1xEYYplGcTYKiUHg4S5BnibZuM4qFb2j7O01", + "self_link": "http://localhost:9001/3.0/users/32", "user_id": 32}'} headers: - content-length: ['324'] + content-length: ['326'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -72,13 +72,13 @@ uri: http://localhost:9001/3.0/users response: body: {string: !!python/unicode '{"entries": [{"created_on": "2005-08-01T07:49:23", - "http_etag": "\"1a3aa88b2cd54f39cc383ee227e4fe2e5523a053\"", "is_server_owner": - false, "password": "$6$rounds=685646$vZ6MnU/EhjWMmJj/$bP0uRgUcHzu/94frX6.ypX7w2W4l/xz5zG.p3RqBiFeISayJc6G/U98lJjdsNVEGQEd6qBDK4w4rultFTkB9Z/", - "self_link": "http://localhost:9001/3.0/users/2", "user_id": 2}], "http_etag": - "\"fd9719839d5a1e11cd4eef94074fa04a3fa79251\"", "start": 0, "total_size": + "http_etag": "\"c35ee9d7f435114a9bbd393f1997d9ad90b639d0\"", "is_server_owner": + false, "password": "$6$rounds=684549$au8U5LcyUMdQO.hH$KVF7NcArszy8kOozZ2A1W/.j/Bp7H2fgI.jOY7dmzPoD0Ltauo1xEYYplGcTYKiUHg4S5BnibZuM4qFb2j7O01", + "self_link": "http://localhost:9001/3.0/users/32", "user_id": 32}], "http_etag": + "\"899aca8c420cd51df18d46261f8c98622455b2dd\"", "start": 0, "total_size": 1}'} headers: - content-length: ['429'] + content-length: ['431'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -86,7 +86,7 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode DELETE - uri: http://localhost:9001/3.0/users/2 + uri: http://localhost:9001/3.0/users/32 response: body: {string: !!python/unicode ''} headers: diff --git a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_redirects_on_success.yaml b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_redirects_on_success.yaml index c66bb17..c94ae54 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_redirects_on_success.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_redirects_on_success.yaml @@ -34,13 +34,28 @@ body: {string: !!python/unicode ''} headers: content-length: ['0'] - location: ['http://localhost:9001/3.0/users/3'] + location: ['http://localhost:9001/3.0/users/33'] status: {code: 201, message: Created} - request: body: null headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET + uri: http://localhost:9001/3.0/users/33 + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"b5d85dcc5592a113aa495dea2f5243db7bf28be5\"", "is_server_owner": false, + "password": "$6$rounds=594438$yT1G.Tias7E.N2jY$uE/BBkZcOB5LOx02xsLXrS3UCpFmnKeyBlCXQZCgi1FVKMeYgZGvSIFpd3ZKA7Xu9U.79eUqvPEeSqsibuTL.1", + "self_link": "http://localhost:9001/3.0/users/33", "user_id": 33}'} + headers: + content-length: ['326'] + 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/users/new_address@example.org response: body: {string: !!python/unicode 404 Not Found} @@ -56,11 +71,11 @@ uri: http://localhost:9001/3.0/users/les@example.org response: body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": - "\"b7d63e692f1cdb815f6c198d5b41e094e1e32397\"", "is_server_owner": false, - "password": "$6$rounds=680355$VVIdbVOFYg8D/HoG$8Vp4V1NpbM38RfUMkH3Ayycip/zSx8K/TfKsLxwL3pEzAsLxM5Aqzqm0NiLotVPb34dTiaVVVuGmzEZHeCa/1.", - "self_link": "http://localhost:9001/3.0/users/3", "user_id": 3}'} + "\"b5d85dcc5592a113aa495dea2f5243db7bf28be5\"", "is_server_owner": false, + "password": "$6$rounds=594438$yT1G.Tias7E.N2jY$uE/BBkZcOB5LOx02xsLXrS3UCpFmnKeyBlCXQZCgi1FVKMeYgZGvSIFpd3ZKA7Xu9U.79eUqvPEeSqsibuTL.1", + "self_link": "http://localhost:9001/3.0/users/33", "user_id": 33}'} headers: - content-length: ['324'] + content-length: ['326'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -68,15 +83,15 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET - uri: http://localhost:9001/3.0/users/3/addresses + uri: http://localhost:9001/3.0/users/33/addresses response: body: {string: !!python/unicode '{"entries": [{"email": "les@example.org", "http_etag": - "\"de6a1923a224a2af2efb15b0f894f44ac33d012b\"", "original_email": "les@example.org", + "\"379ec109323fbcf8c99b28f734e5e82c47913e9b\"", "original_email": "les@example.org", "registered_on": "2005-08-01T07:49:23", "self_link": "http://localhost:9001/3.0/addresses/les@example.org", - "user": "http://localhost:9001/3.0/users/3"}], "http_etag": "\"7c3754cdddaac7ec96cbb665ae89ac8dcab5ebad\"", + "user": "http://localhost:9001/3.0/users/33"}], "http_etag": "\"4c1fece179275aa8a7d45ffca3d441378da3ecd1\"", "start": 0, "total_size": 1}'} headers: - content-length: ['384'] + content-length: ['385'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -87,11 +102,11 @@ uri: http://localhost:9001/3.0/users/les@example.org response: body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": - "\"b7d63e692f1cdb815f6c198d5b41e094e1e32397\"", "is_server_owner": false, - "password": "$6$rounds=680355$VVIdbVOFYg8D/HoG$8Vp4V1NpbM38RfUMkH3Ayycip/zSx8K/TfKsLxwL3pEzAsLxM5Aqzqm0NiLotVPb34dTiaVVVuGmzEZHeCa/1.", - "self_link": "http://localhost:9001/3.0/users/3", "user_id": 3}'} + "\"b5d85dcc5592a113aa495dea2f5243db7bf28be5\"", "is_server_owner": false, + "password": "$6$rounds=594438$yT1G.Tias7E.N2jY$uE/BBkZcOB5LOx02xsLXrS3UCpFmnKeyBlCXQZCgi1FVKMeYgZGvSIFpd3ZKA7Xu9U.79eUqvPEeSqsibuTL.1", + "self_link": "http://localhost:9001/3.0/users/33", "user_id": 33}'} headers: - content-length: ['324'] + content-length: ['326'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -115,13 +130,13 @@ uri: http://localhost:9001/3.0/users response: body: {string: !!python/unicode '{"entries": [{"created_on": "2005-08-01T07:49:23", - "http_etag": "\"b7d63e692f1cdb815f6c198d5b41e094e1e32397\"", "is_server_owner": - false, "password": "$6$rounds=680355$VVIdbVOFYg8D/HoG$8Vp4V1NpbM38RfUMkH3Ayycip/zSx8K/TfKsLxwL3pEzAsLxM5Aqzqm0NiLotVPb34dTiaVVVuGmzEZHeCa/1.", - "self_link": "http://localhost:9001/3.0/users/3", "user_id": 3}], "http_etag": - "\"db11dbb16d9121822c3c6fda76e5ed1f5b98a7d2\"", "start": 0, "total_size": + "http_etag": "\"b5d85dcc5592a113aa495dea2f5243db7bf28be5\"", "is_server_owner": + false, "password": "$6$rounds=594438$yT1G.Tias7E.N2jY$uE/BBkZcOB5LOx02xsLXrS3UCpFmnKeyBlCXQZCgi1FVKMeYgZGvSIFpd3ZKA7Xu9U.79eUqvPEeSqsibuTL.1", + "self_link": "http://localhost:9001/3.0/users/33", "user_id": 33}], "http_etag": + "\"1d709ba6c10a9838e7f3583a084bb1e2e8c7acf5\"", "start": 0, "total_size": 1}'} headers: - content-length: ['429'] + content-length: ['431'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -129,7 +144,7 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode DELETE - uri: http://localhost:9001/3.0/users/3 + uri: http://localhost:9001/3.0/users/33 response: body: {string: !!python/unicode ''} headers: diff --git a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_shows_success_message.yaml b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_shows_success_message.yaml index e99f398..d7d3ffb 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_shows_success_message.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_post_valid_form_shows_success_message.yaml @@ -34,13 +34,28 @@ body: {string: !!python/unicode ''} headers: content-length: ['0'] - location: ['http://localhost:9001/3.0/users/4'] + location: ['http://localhost:9001/3.0/users/34'] status: {code: 201, message: Created} - request: body: null headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET + uri: http://localhost:9001/3.0/users/34 + response: + body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": + "\"5cd50a95563331af2dc6b22c77423258f4025629\"", "is_server_owner": false, + "password": "$6$rounds=692048$z/XmBc5wTRIOUnMq$76ov81e/l795odjZAhtsUqJ.Q5Qqg2jPQdGcFajp7lP21MT/k1RY8pgW6KzobvDXkRsFk8grz107eqvt.Tmzk1", + "self_link": "http://localhost:9001/3.0/users/34", "user_id": 34}'} + headers: + content-length: ['326'] + 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/users/new_address@example.org response: body: {string: !!python/unicode 404 Not Found} @@ -56,11 +71,11 @@ uri: http://localhost:9001/3.0/users/les@example.org response: body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": - "\"38608862753852e1594b0569ca9f829ba203f02d\"", "is_server_owner": false, - "password": "$6$rounds=665394$dwfj7W19CAmlrQDx$FXRiQm4V16IDXAtWi05FXqaPJDWoZE1G4kTcnxEEJr4DIVC8Xl9DDNhSrFHRTkIgj03h3fOxWAwZm6yCJGyOm0", - "self_link": "http://localhost:9001/3.0/users/4", "user_id": 4}'} + "\"5cd50a95563331af2dc6b22c77423258f4025629\"", "is_server_owner": false, + "password": "$6$rounds=692048$z/XmBc5wTRIOUnMq$76ov81e/l795odjZAhtsUqJ.Q5Qqg2jPQdGcFajp7lP21MT/k1RY8pgW6KzobvDXkRsFk8grz107eqvt.Tmzk1", + "self_link": "http://localhost:9001/3.0/users/34", "user_id": 34}'} headers: - content-length: ['324'] + content-length: ['326'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -68,15 +83,15 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET - uri: http://localhost:9001/3.0/users/4/addresses + uri: http://localhost:9001/3.0/users/34/addresses response: body: {string: !!python/unicode '{"entries": [{"email": "les@example.org", "http_etag": - "\"96914eb17770a09302e3be4860191b2eaebfce2d\"", "original_email": "les@example.org", + "\"90a74eff5a9d7a1fbb568b166642e9b630ffd155\"", "original_email": "les@example.org", "registered_on": "2005-08-01T07:49:23", "self_link": "http://localhost:9001/3.0/addresses/les@example.org", - "user": "http://localhost:9001/3.0/users/4"}], "http_etag": "\"c9346595dcf5d836882bd227f35ba2d8211d5396\"", + "user": "http://localhost:9001/3.0/users/34"}], "http_etag": "\"f8037b34d17713bbeab087a17a536695ff6a28ab\"", "start": 0, "total_size": 1}'} headers: - content-length: ['384'] + content-length: ['385'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -87,11 +102,11 @@ uri: http://localhost:9001/3.0/users/les@example.org response: body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": - "\"38608862753852e1594b0569ca9f829ba203f02d\"", "is_server_owner": false, - "password": "$6$rounds=665394$dwfj7W19CAmlrQDx$FXRiQm4V16IDXAtWi05FXqaPJDWoZE1G4kTcnxEEJr4DIVC8Xl9DDNhSrFHRTkIgj03h3fOxWAwZm6yCJGyOm0", - "self_link": "http://localhost:9001/3.0/users/4", "user_id": 4}'} + "\"5cd50a95563331af2dc6b22c77423258f4025629\"", "is_server_owner": false, + "password": "$6$rounds=692048$z/XmBc5wTRIOUnMq$76ov81e/l795odjZAhtsUqJ.Q5Qqg2jPQdGcFajp7lP21MT/k1RY8pgW6KzobvDXkRsFk8grz107eqvt.Tmzk1", + "self_link": "http://localhost:9001/3.0/users/34", "user_id": 34}'} headers: - content-length: ['324'] + content-length: ['326'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -115,13 +130,13 @@ uri: http://localhost:9001/3.0/users response: body: {string: !!python/unicode '{"entries": [{"created_on": "2005-08-01T07:49:23", - "http_etag": "\"38608862753852e1594b0569ca9f829ba203f02d\"", "is_server_owner": - false, "password": "$6$rounds=665394$dwfj7W19CAmlrQDx$FXRiQm4V16IDXAtWi05FXqaPJDWoZE1G4kTcnxEEJr4DIVC8Xl9DDNhSrFHRTkIgj03h3fOxWAwZm6yCJGyOm0", - "self_link": "http://localhost:9001/3.0/users/4", "user_id": 4}], "http_etag": - "\"bc23703fe51a39f9442fcc260659063b1e8e7646\"", "start": 0, "total_size": + "http_etag": "\"5cd50a95563331af2dc6b22c77423258f4025629\"", "is_server_owner": + false, "password": "$6$rounds=692048$z/XmBc5wTRIOUnMq$76ov81e/l795odjZAhtsUqJ.Q5Qqg2jPQdGcFajp7lP21MT/k1RY8pgW6KzobvDXkRsFk8grz107eqvt.Tmzk1", + "self_link": "http://localhost:9001/3.0/users/34", "user_id": 34}], "http_etag": + "\"2511e6bae67e583db88c2b187179ce7f28fa893f\"", "start": 0, "total_size": 1}'} headers: - content-length: ['429'] + content-length: ['431'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -129,7 +144,7 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode DELETE - uri: http://localhost:9001/3.0/users/4 + uri: http://localhost:9001/3.0/users/34 response: body: {string: !!python/unicode ''} headers: diff --git a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_view_contains_form.yaml b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_view_contains_form.yaml index e112900..a2e8e58 100644 --- a/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_view_contains_form.yaml +++ b/src/postorius/tests/fixtures/vcr_cassettes/TestProfile.test_view_contains_form.yaml @@ -34,21 +34,21 @@ body: {string: !!python/unicode ''} headers: content-length: ['0'] - location: ['http://localhost:9001/3.0/users/5'] + location: ['http://localhost:9001/3.0/users/35'] status: {code: 201, message: Created} - request: body: null headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode GET - uri: http://localhost:9001/3.0/users/5 + uri: http://localhost:9001/3.0/users/35 response: body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "http_etag": - "\"b9c2f5b5bdabcccb0cff4b78d3cd4f16cf5c71c3\"", "is_server_owner": false, - "password": "$6$rounds=686290$uMXKSe83AtShteY/$AGl.X49.AIQDQ9j9yUSKuInfurq2n1jL9PMqkM93DWgNDrTN2o6uZQBW7s3EAEWgr3ZooDv6WBH6WPmRX0u/O0", - "self_link": "http://localhost:9001/3.0/users/5", "user_id": 5}'} + "\"371790a6d8bf4e0903a6da47dcacb90e72e8bdb9\"", "is_server_owner": false, + "password": "$6$rounds=634445$E/IorwYNeGyH.2hY$dKuMaRbe4KgmFGcwGaZM1xemNnHoAb3ZLH.quJmVuHKC8nfViLvpJRb.Gw7qzFRTUUjoSlcugmilge8MVjR1i1", + "self_link": "http://localhost:9001/3.0/users/35", "user_id": 35}'} headers: - content-length: ['324'] + content-length: ['326'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -72,13 +72,13 @@ uri: http://localhost:9001/3.0/users response: body: {string: !!python/unicode '{"entries": [{"created_on": "2005-08-01T07:49:23", - "http_etag": "\"b9c2f5b5bdabcccb0cff4b78d3cd4f16cf5c71c3\"", "is_server_owner": - false, "password": "$6$rounds=686290$uMXKSe83AtShteY/$AGl.X49.AIQDQ9j9yUSKuInfurq2n1jL9PMqkM93DWgNDrTN2o6uZQBW7s3EAEWgr3ZooDv6WBH6WPmRX0u/O0", - "self_link": "http://localhost:9001/3.0/users/5", "user_id": 5}], "http_etag": - "\"f9ad3f14c385d71051b6ba5380fc6605d4463ae3\"", "start": 0, "total_size": + "http_etag": "\"371790a6d8bf4e0903a6da47dcacb90e72e8bdb9\"", "is_server_owner": + false, "password": "$6$rounds=634445$E/IorwYNeGyH.2hY$dKuMaRbe4KgmFGcwGaZM1xemNnHoAb3ZLH.quJmVuHKC8nfViLvpJRb.Gw7qzFRTUUjoSlcugmilge8MVjR1i1", + "self_link": "http://localhost:9001/3.0/users/35", "user_id": 35}], "http_etag": + "\"89b31057a7271a605f8fb510cbef2c4d3d44a80f\"", "start": 0, "total_size": 1}'} headers: - content-length: ['429'] + content-length: ['431'] content-type: [application/json; charset=utf-8] status: {code: 200, message: OK} - request: @@ -86,7 +86,7 @@ headers: accept-encoding: ['gzip, deflate'] method: !!python/unicode DELETE - uri: http://localhost:9001/3.0/users/5 + uri: http://localhost:9001/3.0/users/35 response: body: {string: !!python/unicode ''} headers: diff --git a/src/postorius/tests/mailman_api_tests/test_profile.py b/src/postorius/tests/mailman_api_tests/test_profile.py index a36ec23..419b6c8 100644 --- a/src/postorius/tests/mailman_api_tests/test_profile.py +++ b/src/postorius/tests/mailman_api_tests/test_profile.py @@ -22,6 +22,7 @@ from mock import patch from smtplib import SMTPException +from postorius.models import MailmanUser from postorius.models import AddressConfirmationProfile from postorius.tests.utils import ViewTestCase @@ -87,3 +88,12 @@ self.assertEqual(mock_send_confirmation_link.call_count, 1) self.assertContains(response, 'Currently emails can not be added, ' 'please try again later') + + def test_change_display_name(self): + # We create a Mailman user, from the django user object. + self.mm_user = MailmanUser.objects.create_from_django(self.user) + self.client.post(reverse('user_profile'), { + 'formname': 'displayname', + 'display_name': 'testname'}) + # The Mailman user's display name, must have been changed correctly. + self.assertEqual(self.mm_user.display_name, 'testname') diff --git a/src/postorius/views/user.py b/src/postorius/views/user.py index d5f3513..c76668c 100644 --- a/src/postorius/views/user.py +++ b/src/postorius/views/user.py @@ -39,7 +39,7 @@ AddressConfirmationProfile, MailmanUser, Mailman404Error) from postorius.forms import (UserPreferences, AddressActivationForm, - ChangeSubscriptionForm) + ChangeSubscriptionForm, ChangeDisplayNameForm) from postorius.views.generic import MailmanUserView from smtplib import SMTPException from socket import error as socket_error @@ -247,29 +247,53 @@ except MailmanApiError: return utils.render_api_error(request) if request.method == 'POST': - form = AddressActivationForm(request.POST) - if form.is_valid(): - profile, c = AddressConfirmationProfile.objects.update_or_create( - email=form.cleaned_data['email'], user=request.user, - defaults={'activation_key': uuid.uuid4().hex}) - try: - profile.send_confirmation_link(request) - messages.success(request, - _('Please follow the instructions sent via' - ' email to confirm the address')) + if request.POST.get('formname') == 'displayname': + display_name_form = ChangeDisplayNameForm(request.POST) + form = AddressActivationForm( + initial={'user_email': request.user.email}) + if display_name_form.is_valid(): + name = display_name_form.cleaned_data['display_name'] + try: + mm_user.display_name = name + mm_user.save() + except MailmanApiError: + return utils.render_api_error(request) + except HTTPError as e: + messages.error(request, e) + else: + messages.success(request, _('Display name changed')) return redirect('user_profile') - except (SMTPException, socket_error) as e: - if (not isinstance(e, SMTPException) and - e.errno != errno.ECONNREFUSED): - raise e - profile.delete() - messages.error(request, _('Currently emails can not be added,' - ' please try again later')) + else: + display_name_form = ChangeDisplayNameForm( + initial={'display_name': mm_user.display_name}) + form = AddressActivationForm(request.POST) + if form.is_valid(): + profile, c = ( + AddressConfirmationProfile.objects.update_or_create( + email=form.cleaned_data['email'], user=request.user, + defaults={'activation_key': uuid.uuid4().hex})) + try: + profile.send_confirmation_link(request) + messages.success(request, _( + 'Please follow the instructions sent via' + ' email to confirm the address')) + return redirect('user_profile') + except (SMTPException, socket_error) as e: + if (not isinstance(e, SMTPException) and + e.errno != errno.ECONNREFUSED): + raise e + profile.delete() + messages.error(request, + _('Currently emails can not be added,' + ' please try again later')) else: form = AddressActivationForm( initial={'user_email': request.user.email}) + display_name_form = ChangeDisplayNameForm( + initial={'display_name': mm_user.display_name}) return render(request, 'postorius/user/profile.html', - {'mm_user': mm_user, 'form': form}) + {'mm_user': mm_user, 'form': form, + 'name_form': display_name_form}) @login_required()