Skip to content

Commit

Permalink
Merge branch 'master' into fix-gateway-braintree-template
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwaidan00 committed Feb 11, 2019
2 parents e6f58cd + 085a207 commit 29148af
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 97 deletions.
273 changes: 233 additions & 40 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions saleor/dashboard/customer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from ...account.models import CustomerNote, User
from ...core.utils import get_paginator_items
from ..emails import send_set_password_email
from ..emails import send_set_password_customer_email
from ..views import staff_member_required
from .filters import UserFilter
from .forms import CustomerDeleteForm, CustomerForm, CustomerNoteForm
Expand Down Expand Up @@ -61,7 +61,7 @@ def customer_create(request):
form.save()
msg = pgettext_lazy(
'Dashboard message', 'Added customer %s') % customer
send_set_password_email.delay(customer.pk)
send_set_password_customer_email.delay(customer.pk)
messages.success(request, msg)
return redirect('dashboard:customer-details', pk=customer.pk)
ctx = {'form': form, 'customer': customer}
Expand Down
27 changes: 19 additions & 8 deletions saleor/dashboard/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,35 @@
from ..core.utils import build_absolute_uri


@shared_task
def send_set_password_email(staff_pk):
staff = User.objects.get(pk=staff_pk)
uid = urlsafe_base64_encode(force_bytes(staff.pk)).decode()
token = default_token_generator.make_token(staff)
def _send_set_password_email(pk, template_name):
user = User.objects.get(pk=pk)
uid = urlsafe_base64_encode(force_bytes(user.pk)).decode()
token = default_token_generator.make_token(user)
password_set_url = build_absolute_uri(
reverse(
'account:reset-password-confirm',
kwargs={'token': token, 'uidb64': uid}))
kwargs={
'token': token,
'uidb64': uid}))
ctx = get_email_base_context()
ctx['password_set_url'] = password_set_url
send_templated_mail(
template_name='dashboard/staff/set_password',
template_name=template_name,
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[staff.email],
recipient_list=[user.email],
context=ctx)


@shared_task
def send_set_password_staff_email(staff_pk):
_send_set_password_email(staff_pk, 'dashboard/staff/set_password')


@shared_task
def send_set_password_customer_email(pk):
_send_set_password_email(pk, 'dashboard/customer/set_password')


@shared_task
def send_promote_customer_to_staff_email(staff_pk):
staff = User.objects.get(pk=staff_pk)
Expand Down
4 changes: 2 additions & 2 deletions saleor/dashboard/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ...account.models import User
from ...core.utils import get_paginator_items
from ..emails import (
send_promote_customer_to_staff_email, send_set_password_email)
send_promote_customer_to_staff_email, send_set_password_staff_email)
from ..views import staff_member_required
from .filters import StaffFilter
from .forms import StaffForm
Expand Down Expand Up @@ -63,7 +63,7 @@ def staff_create(request):
'Dashboard message', 'Added staff member %s') % (staff,)
messages.success(request, msg)
if created:
send_set_password_email.delay(staff.pk)
send_set_password_staff_email.delay(staff.pk)
else:
send_promote_customer_to_staff_email.delay(staff.pk)
return redirect('dashboard:staff-list')
Expand Down
11 changes: 6 additions & 5 deletions saleor/graphql/account/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from ...account import emails, models
from ...core.permissions import MODELS_PERMISSIONS, get_permissions
from ...dashboard.emails import (
send_set_password_customer_email, send_set_password_staff_email)
from ...dashboard.staff.utils import remove_staff_member
from ..account.i18n import I18nMixin
from ..account.types import AddressInput, User
Expand Down Expand Up @@ -136,11 +138,11 @@ def save(cls, info, instance, cleaned_input):
default_billing_address.save()
instance.default_billing_address = default_billing_address

if cleaned_input.get('send_password_email'):
site = info.context.site
send_user_password_reset_email(instance, site)
super().save(info, instance, cleaned_input)

if cleaned_input.get('send_password_email'):
send_set_password_customer_email.delay(instance.pk)


class CustomerUpdate(CustomerCreate):
class Arguments:
Expand Down Expand Up @@ -253,8 +255,7 @@ def clean_input(cls, info, instance, input, errors):
def save(cls, info, user, cleaned_input):
user.save()
if cleaned_input.get('send_password_email'):
site = info.context.site
send_user_password_reset_email(user, site)
send_set_password_staff_email.delay(user.pk)


class StaffUpdate(StaffCreate):
Expand Down
2 changes: 2 additions & 0 deletions saleor/order/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ def start_payment(request, order, gateway):
except Exception as exc:
form.add_error(None, str(exc))
else:
if order.is_fully_paid():
return redirect('order:payment-success', token=order.token)
return redirect(order.get_absolute_url())

ctx = {
Expand Down
4 changes: 2 additions & 2 deletions saleor/static/scss/components/_header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@
padding: $global-padding * 2 0;
display: flex;
align-items: center;
svg {
a svg {
height: 38px;
width: 100%;
width: 113px;
}
.menu-icon-mobile {
position: relative;
Expand Down
3 changes: 3 additions & 0 deletions saleor/static/scss/layouts/_checkout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@
display: grid;
grid-template-columns: 1fr 1fr;
grid-column-gap: $global-margin * 2;
&--full-width {
grid-template-columns: 1fr;
}
@include media-breakpoint-down(md) {
grid-template-columns: 1fr;
}
Expand Down
6 changes: 4 additions & 2 deletions templates/checkout/shipping_address.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@
<form method="post" novalidate class="checkout__shipping">
{% csrf_token %}
<h2>{% trans "Shipping address" context "Checkout shipping address title" %}</h2>
<div class="checkout__addresses">


<div class="checkout__addresses{{ request.user.is_authenticated|yesno:",--full-width" }}">
{% if request.user.is_authenticated %}
{% include "checkout/snippets/addresses_form.html" with addresses_form=user_form addresses=additional_addresses address_form=address_form only %}
{% else %}
{% bootstrap_form user_form %}
{% include "account/snippets/address_form.html" with address_form=address_form only %}
{% endif %}
</div>

<div class="checkout__addresses">
<button type="submit" class="btn btn-primary">
{% trans "Continue" context "Checkout shipping address primary action" %}
</button>
Expand Down
30 changes: 16 additions & 14 deletions templates/dashboard/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@
</thead>
<tbody>
{% for payment in preauthorized_payments %}
<tr data-action-go="{% url "dashboard:order-details" order_pk=payment.order.pk %}">
<td>
{{ payment.order }}
</td>
<td>
{{ payment.created }}
</td>
<td>
{{ payment.order.user|default:_("Guest") }}
</td>
<td class="right-align">
{% price payment.get_total %}
</td>
</tr>
{% if payment.order %}
<tr data-action-go="{% url "dashboard:order-details" order_pk=payment.order.pk %}">
<td>
{{ payment.order }}
</td>
<td>
{{ payment.created }}
</td>
<td>
{{ payment.order.user|default:_("Guest") }}
</td>
<td class="right-align">
{% price payment.get_total %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
Expand Down
7 changes: 3 additions & 4 deletions templates/product/_filters.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
This is required if you want to have sorting to be kept during further filtering.
{% endcomment %}
<input type="hidden" name="sort_by" value="{% if request.GET.sort_by %}{{ request.GET.sort_by }}{% endif %}">
{% elif field.name == 'price' %}
{% else %}
{% elif field.name != 'price' %}
<div class="filter-section" aria-expanded="true">
<div class="filter-section__header">
<h3>{{ field.label }}</h3>
Expand All @@ -40,10 +39,10 @@ <h3>{{ field.label }}</h3>
</div>
<div class="filter-section__content">
<div class="filter-form-field price-field">
<input id="{{ field.auto_id }}_0" name="{{ field.name }}_0"
<input id="{{ field.auto_id }}_0" name="{{ field.name }}_min"
value="{% if field.value.0 %}{{ field.value.0 }}{% endif %}" type="number" min="0"
class="form-control d-inline"
placeholder="{% trans 'from' context 'Product price filter' %}"/><span>-</span><input id="{{ field.auto_id }}_1" name="{{ field.name }}_1"
placeholder="{% trans 'from' context 'Product price filter' %}"/><span>-</span><input id="{{ field.auto_id }}_1" name="{{ field.name }}_max"
value="{% if field.value.1 %}{{ field.value.1 }}{% endif %}" type="number" min="0"
class="form-control d-inline" placeholder="{% trans 'to' context 'Product price filter' %}"/>
</div>
Expand Down
21 changes: 21 additions & 0 deletions templates/templated_email/dashboard/customer/set_password.email
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% load i18n %}
{% block subject %}{% blocktrans context "Set password for customer e-mail title" %}Hello from {{ site_name }}!{% endblocktrans %}{% endblock %}

{% block plain %}
{% blocktrans context "Set password for customer e-mail text" %}
Hi!

You're receiving this e-mail because you have to set password for your customer account at {{ domain }}.
Click the link below to reset your password.
{% endblocktrans %}

{{ password_set_url }}

{% blocktrans context "Set password for customer e-mail text" %}
This is an automatically generated email, please do not reply.
{% endblocktrans %}
{% endblock %}

{% block html %}
{% include 'templated_email/compiled/set_customer_password.html' %}
{% endblock %}
30 changes: 30 additions & 0 deletions templates/templated_email/source/set_customer_password.mjml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 17 additions & 16 deletions tests/api/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ def test_customer_register(user_api_client):
'User with this Email already exists.')


@patch('saleor.account.emails.send_password_reset_email.delay')
@patch('saleor.dashboard.emails.send_set_password_customer_email.delay')
def test_customer_create(
send_password_reset_mock, staff_api_client, address,
send_set_password_customer_email_mock, staff_api_client, address,
permission_manage_users):
query = """
mutation CreateCustomer(
Expand Down Expand Up @@ -429,12 +429,10 @@ def test_customer_create(
assert not data['user']['isStaff']
assert data['user']['isActive']

assert send_password_reset_mock.call_count == 1
args, kwargs = send_password_reset_mock.call_args
call_context = args[0]
call_email = args[1]
assert call_email == email
assert 'token' in call_context
assert send_set_password_customer_email_mock.call_count == 1
args, kwargs = send_set_password_customer_email_mock.call_args
call_pk = args[0]
assert call_pk == customer.pk


def test_customer_update(
Expand Down Expand Up @@ -618,9 +616,9 @@ def test_customer_delete_errors(customer_user, admin_user, staff_user):
assert errors == []


@patch('saleor.account.emails.send_password_reset_email.delay')
@patch('saleor.dashboard.emails.send_set_password_staff_email.delay')
def test_staff_create(
send_password_reset_mock, staff_api_client, permission_manage_staff):
send_set_password_staff_email_mock, staff_api_client, permission_manage_staff):
query = """
mutation CreateStaff(
$email: String, $permissions: [PermissionEnum],
Expand Down Expand Up @@ -661,12 +659,15 @@ def test_staff_create(
permissions = data['user']['permissions']
assert permissions[0]['code'] == 'MANAGE_PRODUCTS'

assert send_password_reset_mock.call_count == 1
args, kwargs = send_password_reset_mock.call_args
call_context = args[0]
call_email = args[1]
assert call_email == email
assert 'token' in call_context
User = get_user_model()
staff_user = User.objects.get(email=email)

assert staff_user.is_staff

assert send_set_password_staff_email_mock.call_count == 1
args, kwargs = send_set_password_staff_email_mock.call_args
call_pk = args[0]
assert call_pk == staff_user.pk


def test_staff_update(staff_api_client, permission_manage_staff):
Expand Down
Loading

0 comments on commit 29148af

Please sign in to comment.