Skip to content

Commit

Permalink
Merge branch 'main' into SALEOR-6544-migrate-order-line-id-to-uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
IKarbowiak committed May 5, 2022
2 parents f1c6c44 + a1a7a22 commit 828405a
Show file tree
Hide file tree
Showing 85 changed files with 724 additions and 579 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
exclude: tests/

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.942
rev: v0.950
hooks:
- id: mypy
language: system
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Migrate order line id from int to UUID - #9637 by @IKarbowiak
- Changed the order line `id` from `int` to `UUID`, the old ids still can be used
for old order lines.
- Fix invalid `ADDED_PRODUCTS` event parameter for `OrderLinesCreate` mutation - #9653 by @IKarbowiak

### Other changes
- Fix for sending incorrect prices to Avatax - #9633 by @korycins
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,22 @@ The current production-ready version is 3.0 (beta) and you should use this versi

- Saleor: https://github.com/saleor/saleor/releases/
- Dashboard: https://github.com/saleor/saleor-dashboard/releases/
- Storefront: https://github.com/saleor/saleor-storefront/releases/
- Storefront: https://github.com/saleor/react-storefront/releases/

### Saleor Cloud
The fastest way to develop with Saleor are free developer accounts in [Saleor Cloud](https://cloud.saleor.io).

Register [here](https://cloud.saleor.io/register) or install our [CLI tool](https://github.com/saleor/saleor-cli):

`npm i -g saleor@latest`

and run the following command:

`saleor register`

Bootstrap your first [storefront](https://github.com/saleor/react-storefront) with:

`saleor storefront create --demo`

## Documentation

Expand Down
216 changes: 108 additions & 108 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ documentation = "https://docs.saleor.io/"
[tool.poetry.dependencies]
python = "~3.9"
babel = ">=2.8,<2.10"
boto3 = "^1.21"
boto3 = "^1.22"
braintree = ">=4.2,<4.16"
dj-database-url = "^0"
dj-email-url = "^1"
Expand Down
16 changes: 8 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ adyen==4.0.0
amqp==5.1.1; python_version >= "3.7"
aniso8601==7.0.0
anyio==3.5.0; python_version >= "3.7" and python_full_version >= "3.6.2"
asgiref==3.5.0; python_version >= "3.7"
asgiref==3.5.1; python_version >= "3.7"
async-timeout==4.0.2; python_version >= "3.7"
authlib==1.0.1
authorizenet==1.1.4
babel==2.9.1; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
beautifulsoup4==4.7.1
billiard==3.6.4.0; python_version >= "3.7"
boto3==1.21.46; python_version >= "3.6"
botocore==1.24.46; python_version >= "3.6"
boto3==1.22.4; python_version >= "3.6"
botocore==1.25.4; python_version >= "3.6"
braintree==4.15.2
brotli==1.0.9; platform_python_implementation == "CPython" and python_version >= "3.7"
brotlicffi==1.0.9.2; platform_python_implementation != "CPython" and python_version >= "3.7"
Expand All @@ -22,7 +22,7 @@ charset-normalizer==2.0.12; python_full_version >= "3.6.0" and python_version >=
click-didyoumean==0.3.0; python_full_version >= "3.6.2" and python_full_version < "4.0.0" and python_version >= "3.7"
click-plugins==1.1.1; python_version >= "3.7"
click-repl==0.2.0; python_version >= "3.7"
click==8.1.2; python_full_version >= "3.6.2" and python_full_version < "4.0.0" and python_version >= "3.7"
click==8.1.3; python_full_version >= "3.6.2" and python_full_version < "4.0.0" and python_version >= "3.7"
colorama==0.4.4; python_version >= "3.7" and python_full_version < "3.0.0" and sys_platform == "win32" and platform_system == "Windows" or sys_platform == "win32" and python_version >= "3.7" and python_full_version >= "3.5.0" and platform_system == "Windows"
cryptography==36.0.2; python_version >= "3.6"
cssselect2==0.6.0; python_version >= "3.7"
Expand All @@ -49,8 +49,8 @@ django==3.2.13; python_version >= "3.6"
draftjs-sanitizer==1.0.0
enmerkar==0.7.1
et-xmlfile==1.1.0; python_version >= "3.6"
faker==13.4.0; python_version >= "3.6"
fonttools==4.33.2; python_version >= "3.7"
faker==13.7.0; python_version >= "3.6"
fonttools==4.33.3; python_version >= "3.7"
freezegun==1.2.1; python_version >= "3.6"
google-api-core==2.7.2; python_version >= "3.7"
google-auth==2.6.6; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.7"
Expand Down Expand Up @@ -90,7 +90,7 @@ oauthlib==3.2.0; python_version >= "3.6"
openpyxl==3.0.9; python_version >= "3.6"
opentracing==2.4.0
packaging==21.3; python_version >= "3.7"
petl==1.7.8; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
petl==1.7.9; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
phonenumberslite==8.12.46
pillow==9.1.0; python_version >= "3.7"
posuto==2022.3.0
Expand Down Expand Up @@ -150,6 +150,6 @@ wcwidth==0.2.5; python_full_version >= "3.6.2" and python_version >= "3.7"
weasyprint==54.3; python_version >= "3.6"
webencodings==0.5.1; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
websockets==10.3; python_version >= "3.7"
wrapt==1.14.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_version >= "3.7" and python_full_version >= "3.5.0"
wrapt==1.14.1; python_version >= "3.7" and python_full_version < "3.0.0" or python_version >= "3.7" and python_full_version >= "3.5.0"
zipp==3.8.0; python_version < "3.10" and python_version >= "3.7"
zopfli==0.2.1; python_version >= "3.7"
32 changes: 16 additions & 16 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ adyen==4.0.0
amqp==5.1.1; python_version >= "3.7"
aniso8601==7.0.0; python_version >= "3.6" and python_version < "4.0"
anyio==3.5.0; python_version >= "3.7" and python_full_version >= "3.6.2"
asgiref==3.5.0; python_version >= "3.7" and python_version < "4.0"
astroid==2.11.3; python_full_version >= "3.6.2"
asgiref==3.5.1; python_version >= "3.7" and python_version < "4.0"
astroid==2.11.4; python_full_version >= "3.6.2"
async-timeout==4.0.2; python_version >= "3.7"
atomicwrites==1.4.0; python_version >= "3.7" and python_full_version < "3.0.0" and sys_platform == "win32" and python_version < "4.0" or sys_platform == "win32" and python_version >= "3.7" and python_full_version >= "3.4.0" and python_version < "4.0"
attrs==21.4.0; python_version >= "3.7" and python_full_version < "3.0.0" and python_version < "4.0" or python_full_version >= "3.5.0" and python_version >= "3.7" and python_version < "4.0"
Expand All @@ -15,8 +15,8 @@ beautifultable==0.7.0
before-after==1.0.1
billiard==3.6.4.0; python_version >= "3.7"
black==22.3.0; python_full_version >= "3.6.2"
boto3==1.21.46; python_version >= "3.6"
botocore==1.24.46; python_version >= "3.6"
boto3==1.22.4; python_version >= "3.6"
botocore==1.25.4; python_version >= "3.6"
braintree==4.15.2
brotli==1.0.9; platform_python_implementation == "CPython" and python_version >= "3.7"
brotlicffi==1.0.9.2; platform_python_implementation != "CPython" and python_version >= "3.7"
Expand All @@ -29,7 +29,7 @@ charset-normalizer==2.0.12; python_full_version >= "3.6.0" and python_version >=
click-didyoumean==0.3.0; python_full_version >= "3.6.2" and python_full_version < "4.0.0" and python_version >= "3.7"
click-plugins==1.1.1; python_version >= "3.7"
click-repl==0.2.0; python_version >= "3.7"
click==8.1.2; python_version >= "3.7" and python_full_version >= "3.6.2" and python_full_version < "4.0.0"
click==8.1.3; python_version >= "3.7" and python_full_version >= "3.6.2" and python_full_version < "4.0.0"
codecov==2.1.12; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
colorama==0.4.4; sys_platform == "win32" and python_version >= "3.7" and python_full_version >= "3.6.2" and (python_version >= "3.7" and python_full_version < "3.0.0" and sys_platform == "win32" or sys_platform == "win32" and python_version >= "3.7" and python_full_version >= "3.5.0") and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0") and (python_version >= "2.7" and python_full_version < "3.0.0" and platform_system == "Windows" or python_full_version >= "3.5.0" and platform_system == "Windows") and platform_system == "Windows" and (python_version >= "3.7" and python_full_version < "3.0.0" and sys_platform == "win32" and python_version < "4.0" or sys_platform == "win32" and python_version >= "3.7" and python_version < "4.0" and python_full_version >= "3.5.0")
coverage==6.3.2; python_version >= "3.7"
Expand All @@ -45,7 +45,7 @@ django-cache-url==3.4.0
django-celery-beat==2.2.1
django-countries==7.3.2
django-debug-toolbar-request-history==0.1.4
django-debug-toolbar==3.2.4; python_version >= "3.6"
django-debug-toolbar==3.3.0; python_version >= "3.7"
django-extensions==3.1.5; python_version >= "3.6"
django-filter==21.1; python_version >= "3.6"
django-graphiql-debug-toolbar==0.2.0; python_version >= "3.6" and python_version < "4.0"
Expand All @@ -67,10 +67,10 @@ draftjs-sanitizer==1.0.0
enmerkar==0.7.1
et-xmlfile==1.1.0; python_version >= "3.6"
execnet==1.9.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
faker==13.4.0; python_version >= "3.6"
faker==13.7.0; python_version >= "3.6"
filelock==3.6.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
flake8==4.0.1; python_version >= "3.6"
fonttools==4.33.2; python_version >= "3.7"
fonttools==4.33.3; python_version >= "3.7"
freezegun==1.2.1; python_version >= "3.6"
google-api-core==2.7.2; python_version >= "3.7"
google-auth==2.6.6; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.7"
Expand All @@ -95,13 +95,13 @@ html-to-draftjs==1.0.1
html2text==2020.1.16; python_version >= "3.5"
html5lib==1.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
httptools==0.4.0; python_version >= "3.7" and python_full_version >= "3.5.0"
identify==2.4.12; python_version >= "3.7"
identify==2.5.0; python_version >= "3.7"
idna==3.3; python_full_version >= "3.6.2" and python_version >= "3.7"
importlib-metadata==4.11.3; python_version < "3.10" and python_version >= "3.7"
iniconfig==1.1.1; python_version >= "3.7" and python_version < "4.0"
isort==5.10.1; python_full_version >= "3.6.1" and python_version < "4.0"
jaeger-client==4.8.0; python_version >= "3.7"
jinja2==3.1.1; python_version >= "3.7"
jinja2==3.1.2; python_version >= "3.7"
jmespath==1.0.0; python_version >= "3.7"
jsonfield==3.1.0; python_version >= "3.6"
kombu==5.2.4; python_version >= "3.7"
Expand All @@ -124,7 +124,7 @@ openpyxl==3.0.9; python_version >= "3.6"
opentracing==2.4.0
packaging==21.3; python_version >= "3.7" and python_full_version < "3.0.0" and python_version < "4.0" or python_full_version >= "3.5.0" and python_version >= "3.7" and python_version < "4.0"
pathspec==0.9.0; python_full_version >= "3.6.2"
petl==1.7.8; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
petl==1.7.9; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
phonenumberslite==8.12.46
pillow==9.1.0; python_version >= "3.7"
platformdirs==2.5.2; python_version >= "3.7" and python_full_version >= "3.6.2" and (python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7")
Expand Down Expand Up @@ -204,11 +204,11 @@ tox==3.25.0; (python_version >= "2.7" and python_full_version < "3.0.0") or (pyt
types-certifi==2021.10.8.2
types-freezegun==1.1.9
types-pkg-resources==0.1.3
types-python-dateutil==2.8.12
types-pytz==2021.3.6
types-requests==2.27.20
types-python-dateutil==2.8.14
types-pytz==2021.3.7
types-requests==2.27.25
types-six==1.16.15
types-urllib3==1.26.13
types-urllib3==1.26.14
typing-extensions==4.2.0; python_version < "3.10" and python_full_version >= "3.6.2" and python_version >= "3.7"
urllib3==1.26.9; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version < "4" and python_version >= "3.7"
uvicorn==0.17.6; python_version >= "3.7"
Expand All @@ -221,7 +221,7 @@ wcwidth==0.2.5; python_full_version >= "3.6.2" and python_version >= "3.7"
weasyprint==54.3; python_version >= "3.6"
webencodings==0.5.1; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.7"
websockets==10.3; python_version >= "3.7"
wrapt==1.14.0; python_full_version >= "3.6.2" and python_version >= "3.5" and (python_version >= "3.7" and python_full_version < "3.0.0" or python_version >= "3.7" and python_full_version >= "3.5.0")
wrapt==1.14.1; python_full_version >= "3.6.2" and python_version >= "3.5" and (python_version >= "3.7" and python_full_version < "3.0.0" or python_version >= "3.7" and python_full_version >= "3.5.0")
yarl==1.7.2; python_version >= "3.6"
zipp==3.8.0; python_version < "3.10" and python_version >= "3.7"
zopfli==0.2.1; python_version >= "3.7"
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 3.2.13 on 2022-04-27 09:10

import django.contrib.postgres.indexes
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("account", "0064_rewrite_customerevent_order_relation"),
]

operations = [
migrations.AddIndex(
model_name="address",
index=django.contrib.postgres.indexes.GinIndex(
fields=[
"company_name",
"street_address_1",
"street_address_2",
"city",
"postal_code",
"phone",
],
name="warehouse_address_search_gin",
opclasses=[
"gin_trgm_ops",
"gin_trgm_ops",
"gin_trgm_ops",
"gin_trgm_ops",
"gin_trgm_ops",
"gin_trgm_ops",
],
),
),
]
29 changes: 26 additions & 3 deletions saleor/account/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union
from typing import Collection, Union

from django.conf import settings
from django.contrib.auth.models import _user_has_perm # type: ignore
Expand Down Expand Up @@ -80,6 +80,19 @@ class Meta:
fields=["first_name", "last_name", "city", "country"],
opclasses=["gin_trgm_ops"] * 4,
),
GinIndex(
name="warehouse_address_search_gin",
# `opclasses` and `fields` should be the same length
fields=[
"company_name",
"street_address_1",
"street_address_2",
"city",
"postal_code",
"phone",
],
opclasses=["gin_trgm_ops"] * 6,
),
]

@property
Expand Down Expand Up @@ -263,15 +276,25 @@ def get_full_name(self):
def get_short_name(self):
return self.email

def has_perm(self, perm: Union[BasePermissionEnum, str], obj=None): # type: ignore
def has_perm(self, perm: Union[BasePermissionEnum, str], obj=None) -> bool:
# This method is overridden to accept perm as BasePermissionEnum
perm = perm.value if hasattr(perm, "value") else perm # type: ignore
perm = perm.value if isinstance(perm, BasePermissionEnum) else perm

# Active superusers have all permissions.
if self.is_active and self.is_superuser and not self._effective_permissions:
return True
return _user_has_perm(self, perm, obj)

def has_perms(
self, perm_list: Collection[Union[BasePermissionEnum, str]], obj=None
) -> bool:
# This method is overridden to accept perm as BasePermissionEnum
perm_list = [
perm.value if isinstance(perm, BasePermissionEnum) else perm
for perm in perm_list
]
return super().has_perms(perm_list, obj)


class CustomerNote(models.Model):
user = models.ForeignKey(
Expand Down
18 changes: 10 additions & 8 deletions saleor/app/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Set
from typing import Collection, Set, Union

from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import Permission
from django.db import models
from oauthlib.common import generate_token

from saleor.core.permissions.enums import BasePermissionEnum

from ..core.models import Job, ModelWithMetadata
from ..core.permissions import AppPermission
from ..webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType
Expand Down Expand Up @@ -78,25 +80,25 @@ def get_permissions(self) -> Set[str]:
setattr(self, perm_cache_name, {f"{ct}.{name}" for ct, name in perms})
return getattr(self, perm_cache_name)

def has_perms(self, perm_list):
def has_perms(self, perm_list: Collection[Union[BasePermissionEnum, str]]) -> bool:
"""Return True if the app has each of the specified permissions."""
if not self.is_active:
return False

try:
wanted_perms = {perm.value for perm in perm_list}
except AttributeError:
wanted_perms = set(perm_list)
wanted_perms = {
perm.value if isinstance(perm, BasePermissionEnum) else perm
for perm in perm_list
}
actual_perms = self.get_permissions()

return (wanted_perms & actual_perms) == wanted_perms

def has_perm(self, perm):
def has_perm(self, perm: Union[BasePermissionEnum, str]) -> bool:
"""Return True if the app has the specified permission."""
if not self.is_active:
return False

perm_value = perm.value if hasattr(perm, "value") else perm
perm_value = perm.value if isinstance(perm, BasePermissionEnum) else perm
return perm_value in self.get_permissions()


Expand Down
11 changes: 6 additions & 5 deletions saleor/core/jwt_manager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
from os.path import exists, join
from typing import Union
from typing import Optional, Union

import jwt
from cryptography.hazmat.primitives import serialization
Expand All @@ -14,7 +14,7 @@

logger = logging.getLogger(__name__)

PUBLIC_KEY = None
PUBLIC_KEY: Optional[rsa.RSAPublicKey] = None
KID = "1"


Expand Down Expand Up @@ -98,10 +98,11 @@ def _create_local_private_key(cls, path) -> "rsa.RSAPrivateKey":
return private_key

@classmethod
def get_public_key(cls, *_args, **_kwargs):
private_key = cls.get_private_key()
def get_public_key(cls) -> rsa.RSAPublicKey:
global PUBLIC_KEY

if PUBLIC_KEY is None:
private_key = cls.get_private_key()
PUBLIC_KEY = private_key.public_key()
return PUBLIC_KEY

Expand All @@ -123,7 +124,7 @@ def decode(cls, token, verify_expiration: bool = True):
if headers.get("alg") == "RS256":
return jwt.decode(
token,
cls.get_public_key(),
cls.get_public_key(), # type: ignore
algorithms=["RS256"],
options={"verify_exp": verify_expiration},
)
Expand Down

0 comments on commit 828405a

Please sign in to comment.