Commit 49dbde6ab176a68d2dd494f5b91d440c8e511f52
1 parent
ffa7b38c
Exists in
master
and in
39 other branches
Fixing email edition for admins
Showing
2 changed files
with
26 additions
and
14 deletions
Show diff stats
src/accounts/templates/accounts/user_update_form.html
| @@ -13,7 +13,7 @@ $(function() { | @@ -13,7 +13,7 @@ $(function() { | ||
| 13 | $.ajax({ | 13 | $.ajax({ |
| 14 | url: "{% url 'archive_email_view' %}", | 14 | url: "{% url 'archive_email_view' %}", |
| 15 | type: 'post', | 15 | type: 'post', |
| 16 | - data: { email: $('#new_email').val() }, | 16 | + data: { email: $('#new_email').val(), user: '{{ user_.pk }}' }, |
| 17 | beforeSend: function(xhr, settings) { | 17 | beforeSend: function(xhr, settings) { |
| 18 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); | 18 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); |
| 19 | } | 19 | } |
| @@ -36,7 +36,10 @@ $(function() { | @@ -36,7 +36,10 @@ $(function() { | ||
| 36 | $.ajax({ | 36 | $.ajax({ |
| 37 | url: "{% url 'archive_email_view' %}", | 37 | url: "{% url 'archive_email_view' %}", |
| 38 | type: 'delete', | 38 | type: 'delete', |
| 39 | - data: { email: $('.email-address', $email_block).text() }, | 39 | + data: { |
| 40 | + email: $('.email-address', $email_block).text(), | ||
| 41 | + user: '{{ user_.pk }}' | ||
| 42 | + }, | ||
| 40 | context: $email_block[0], | 43 | context: $email_block[0], |
| 41 | beforeSend: function(xhr, settings) { | 44 | beforeSend: function(xhr, settings) { |
| 42 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); | 45 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); |
| @@ -53,7 +56,10 @@ $(function() { | @@ -53,7 +56,10 @@ $(function() { | ||
| 53 | $.ajax({ | 56 | $.ajax({ |
| 54 | url: "{% url 'archive_email_validation_view' %}", | 57 | url: "{% url 'archive_email_validation_view' %}", |
| 55 | type: 'post', | 58 | type: 'post', |
| 56 | - data: { email: $('.email-address', $email_block).text() }, | 59 | + data: { |
| 60 | + email: $('.email-address', $email_block).text(), | ||
| 61 | + user: '{{ user_.pk }}' | ||
| 62 | + }, | ||
| 57 | context: $email_block[0], | 63 | context: $email_block[0], |
| 58 | beforeSend: function(xhr, settings) { | 64 | beforeSend: function(xhr, settings) { |
| 59 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); | 65 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); |
| @@ -77,7 +83,10 @@ $(function() { | @@ -77,7 +83,10 @@ $(function() { | ||
| 77 | $.ajax({ | 83 | $.ajax({ |
| 78 | url: "{% url 'archive_email_view' %}", | 84 | url: "{% url 'archive_email_view' %}", |
| 79 | type: 'update', | 85 | type: 'update', |
| 80 | - data: { email: $('.email-address', $email_block).text() }, | 86 | + data: { |
| 87 | + email: $('.email-address', $email_block).text(), | ||
| 88 | + user: '{{ user_.pk }}' | ||
| 89 | + }, | ||
| 81 | beforeSend: function(xhr, settings) { | 90 | beforeSend: function(xhr, settings) { |
| 82 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); | 91 | xhr.setRequestHeader("X-CSRFToken", $.cookie('csrftoken')); |
| 83 | } | 92 | } |
src/super_archives/views.py
| @@ -138,8 +138,7 @@ class EmailView(View): | @@ -138,8 +138,7 @@ class EmailView(View): | ||
| 138 | """Validate an email with the given key""" | 138 | """Validate an email with the given key""" |
| 139 | 139 | ||
| 140 | try: | 140 | try: |
| 141 | - email_val = EmailAddressValidation.objects.get(validation_key=key, | ||
| 142 | - user__pk=request.user.pk) | 141 | + email_val = EmailAddressValidation.objects.get(validation_key=key) |
| 143 | except EmailAddressValidation.DoesNotExist: | 142 | except EmailAddressValidation.DoesNotExist: |
| 144 | messages.error(request, _('The email address you are trying to ' | 143 | messages.error(request, _('The email address you are trying to ' |
| 145 | 'verify either has already been verified ' | 144 | 'verify either has already been verified ' |
| @@ -171,12 +170,13 @@ class EmailView(View): | @@ -171,12 +170,13 @@ class EmailView(View): | ||
| 171 | """Create new email address that will wait for validation""" | 170 | """Create new email address that will wait for validation""" |
| 172 | 171 | ||
| 173 | email = request.POST.get('email') | 172 | email = request.POST.get('email') |
| 173 | + user_pk = request.POST.get('user') | ||
| 174 | if not email: | 174 | if not email: |
| 175 | return http.HttpResponseBadRequest() | 175 | return http.HttpResponseBadRequest() |
| 176 | 176 | ||
| 177 | try: | 177 | try: |
| 178 | EmailAddressValidation.objects.create(address=email, | 178 | EmailAddressValidation.objects.create(address=email, |
| 179 | - user=request.user) | 179 | + user_pk=user_pk) |
| 180 | except IntegrityError: | 180 | except IntegrityError: |
| 181 | # 409 Conflict | 181 | # 409 Conflict |
| 182 | # duplicated entries | 182 | # duplicated entries |
| @@ -191,13 +191,14 @@ class EmailView(View): | @@ -191,13 +191,14 @@ class EmailView(View): | ||
| 191 | 191 | ||
| 192 | request.DELETE = http.QueryDict(request.body) | 192 | request.DELETE = http.QueryDict(request.body) |
| 193 | email_addr = request.DELETE.get('email') | 193 | email_addr = request.DELETE.get('email') |
| 194 | + user_pk = request.DELETE.get('user') | ||
| 194 | 195 | ||
| 195 | if not email_addr: | 196 | if not email_addr: |
| 196 | return http.HttpResponseBadRequest() | 197 | return http.HttpResponseBadRequest() |
| 197 | 198 | ||
| 198 | try: | 199 | try: |
| 199 | email = EmailAddressValidation.objects.get(address=email_addr, | 200 | email = EmailAddressValidation.objects.get(address=email_addr, |
| 200 | - user=request.user) | 201 | + user_pk=user_pk) |
| 201 | except EmailAddressValidation.DoesNotExist: | 202 | except EmailAddressValidation.DoesNotExist: |
| 202 | pass | 203 | pass |
| 203 | else: | 204 | else: |
| @@ -206,7 +207,7 @@ class EmailView(View): | @@ -206,7 +207,7 @@ class EmailView(View): | ||
| 206 | 207 | ||
| 207 | try: | 208 | try: |
| 208 | email = EmailAddress.objects.get(address=email_addr, | 209 | email = EmailAddress.objects.get(address=email_addr, |
| 209 | - user=request.user) | 210 | + user_pk=user_pk) |
| 210 | except EmailAddress.DoesNotExist: | 211 | except EmailAddress.DoesNotExist: |
| 211 | raise http.Http404 | 212 | raise http.Http404 |
| 212 | 213 | ||
| @@ -221,17 +222,18 @@ class EmailView(View): | @@ -221,17 +222,18 @@ class EmailView(View): | ||
| 221 | request.UPDATE = http.QueryDict(request.body) | 222 | request.UPDATE = http.QueryDict(request.body) |
| 222 | 223 | ||
| 223 | email_addr = request.UPDATE.get('email') | 224 | email_addr = request.UPDATE.get('email') |
| 225 | + user_pk = request.UPDATE.get('user') | ||
| 224 | if not email_addr: | 226 | if not email_addr: |
| 225 | return http.HttpResponseBadRequest() | 227 | return http.HttpResponseBadRequest() |
| 226 | 228 | ||
| 227 | try: | 229 | try: |
| 228 | email = EmailAddress.objects.get(address=email_addr, | 230 | email = EmailAddress.objects.get(address=email_addr, |
| 229 | - user=request.user) | 231 | + user_pk=user_pk) |
| 230 | except EmailAddress.DoesNotExist: | 232 | except EmailAddress.DoesNotExist: |
| 231 | raise http.Http404 | 233 | raise http.Http404 |
| 232 | 234 | ||
| 233 | - request.user.email = email_addr | ||
| 234 | - request.user.save() | 235 | + email.user.email = email_addr |
| 236 | + email.user.save() | ||
| 235 | return http.HttpResponse(status=204) | 237 | return http.HttpResponse(status=204) |
| 236 | 238 | ||
| 237 | 239 | ||
| @@ -241,14 +243,15 @@ class EmailValidationView(View): | @@ -241,14 +243,15 @@ class EmailValidationView(View): | ||
| 241 | 243 | ||
| 242 | def post(self, request): | 244 | def post(self, request): |
| 243 | email_addr = request.POST.get('email') | 245 | email_addr = request.POST.get('email') |
| 246 | + user_pk = request.POST.get('user') | ||
| 244 | try: | 247 | try: |
| 245 | email = EmailAddressValidation.objects.get(address=email_addr, | 248 | email = EmailAddressValidation.objects.get(address=email_addr, |
| 246 | - user=request.user) | 249 | + user_pk=user_pk) |
| 247 | except http.DoesNotExist: | 250 | except http.DoesNotExist: |
| 248 | raise http.Http404 | 251 | raise http.Http404 |
| 249 | 252 | ||
| 250 | try: | 253 | try: |
| 251 | - send_verification_email(email_addr, request.user, | 254 | + send_verification_email(email_addr, email.user, |
| 252 | email.validation_key) | 255 | email.validation_key) |
| 253 | except smtplib.SMTPException: | 256 | except smtplib.SMTPException: |
| 254 | logging.exception('Error sending validation email') | 257 | logging.exception('Error sending validation email') |