Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/ambv/black
rev: 21.9b0
rev: 22.3.0
hooks:
- id: black
language_version: python3.8
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#### There is no stable release yet. Get help on gitter chat.

#### We are looking for contributors. Use issues to get an invite to organization.
#### We are looking for contributors. Use issues to get an invite to organization.

Short Analysis:

Expand Down
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ backports.entry-points-selectable==1.1.0; python_version >= "2.7" and python_ful
beautifulsoup4==4.7.1
beautifultable==0.7.0
billiard==3.6.4.0; python_version >= "3.6"
black==21.9b0; python_full_version >= "3.6.2"
black==22.3.0; python_full_version >= "3.6.2"
boto3==1.18.48; python_version >= "3.6"
botocore==1.21.48; python_version >= "3.6"
braintree==4.12.0
Expand Down
41 changes: 41 additions & 0 deletions saleor/graphql/account/mutations/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from copy import copy

import graphene
from django.contrib.auth import password_validation
from django.core.exceptions import ValidationError

from ....account import events as account_events
Expand Down Expand Up @@ -57,6 +58,16 @@ class StaffCreateInput(StaffInput):
)


class StaffVendorCreateInput(StaffInput):
redirect_url = graphene.String(
description=(
"URL of a view where users should be redirected to "
"set the password. URL in RFC 1808 format."
)
)
password = graphene.String(description="Password.", required=True)


class StaffUpdateInput(StaffInput):
remove_groups = graphene.List(
graphene.NonNull(graphene.ID),
Expand Down Expand Up @@ -260,6 +271,36 @@ def _save_m2m(cls, info, instance, cleaned_data):
instance.groups.add(*groups)


class VendorStaffCreate(StaffCreate):
class Arguments:
input = StaffVendorCreateInput(
description="Fields required to create a staff user.", required=True
)

class Meta:
description = "Creates a new vendor staff user."
exclude = ["password"]
model = models.User
# permissions = (AccountPermissions.MANAGE_STAFF,)
error_type_class = StaffError
error_type_field = "staff_errors"

@classmethod
def clean_input(cls, info, instance, data):
password = data["password"]
try:
password_validation.validate_password(password, instance)
except ValidationError as error:
raise ValidationError({"password": error})
return super().clean_input(info, instance, data)

@classmethod
def save(cls, info, user, cleaned_input):
password = cleaned_input["password"]
user.set_password(password)
super().save(info, user, cleaned_input)


class StaffUpdate(StaffCreate):
class Arguments:
id = graphene.ID(description="ID of a staff user to update.", required=True)
Expand Down
3 changes: 3 additions & 0 deletions saleor/graphql/account/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
StaffUpdate,
UserAvatarDelete,
UserAvatarUpdate,
VendorStaffCreate,
)
from .resolvers import (
resolve_address,
Expand Down Expand Up @@ -245,3 +246,5 @@ class AccountMutations(graphene.ObjectType):
permission_group_create = PermissionGroupCreate.Field()
permission_group_update = PermissionGroupUpdate.Field()
permission_group_delete = PermissionGroupDelete.Field()

vendor_staff_create = VendorStaffCreate.Field()
6 changes: 4 additions & 2 deletions saleor/graphql/core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
from ...product import error_codes as product_error_codes
from ...shipping import error_codes as shipping_error_codes
from ...site import error_codes as site_error_codes
from ...warehouse import error_codes as warehouse_error_codes
from ...vendor import error_codes as vendor_error_codes
from ...warehouse import error_codes as warehouse_error_codes
from ...webhook import error_codes as webhook_error_codes
from ...wishlist import error_codes as wishlist_error_codes
from ..notifications import error_codes as external_notifications_error_codes
Expand Down Expand Up @@ -135,7 +135,9 @@ def to_enum(enum_cls, *, type_name=None, **options) -> graphene.Enum:
StockErrorCode = graphene.Enum.from_enum(warehouse_error_codes.StockErrorCode)
UploadErrorCode = graphene.Enum.from_enum(core_error_codes.UploadErrorCode)
WarehouseErrorCode = graphene.Enum.from_enum(warehouse_error_codes.WarehouseErrorCode)
VendorErrorCode = graphene.Enum.from_enum(vendor_error_codes.VendorErrorCode) # registering the error code
VendorErrorCode = graphene.Enum.from_enum(
vendor_error_codes.VendorErrorCode
) # registering the error code
WebhookErrorCode = graphene.Enum.from_enum(webhook_error_codes.WebhookErrorCode)
WishlistErrorCode = graphene.Enum.from_enum(wishlist_error_codes.WishlistErrorCode)
TranslationErrorCode = graphene.Enum.from_enum(core_error_codes.TranslationErrorCode)
4 changes: 3 additions & 1 deletion saleor/graphql/core/types/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
TimePeriodTypeEnum,
TranslationErrorCode,
UploadErrorCode,
WarehouseErrorCode,
VendorErrorCode,
WarehouseErrorCode,
WebhookErrorCode,
WeightUnitsEnum,
WishlistErrorCode,
Expand Down Expand Up @@ -340,10 +340,12 @@ class UploadError(Error):
class WarehouseError(Error):
code = WarehouseErrorCode(description="The error code.", required=True)


# to handle errors and its response for vendor app
class VendorError(Error):
code = VendorErrorCode(description="The error code.", required=True)


class WebhookError(Error):
code = WebhookErrorCode(description="The error code.", required=True)

Expand Down
11 changes: 6 additions & 5 deletions saleor/graphql/product/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
from ..core.types.common import IntRangeInput, PriceRangeInput
from ..utils import resolve_global_ids_to_primary_keys
from ..utils.filters import filter_fields_containing_value, filter_range_field
from ..warehouse import types as warehouse_types
from ..vendor import types as vendor_types
from ..warehouse import types as warehouse_types
from . import types as product_types
from .enums import (
CollectionPublished,
Expand Down Expand Up @@ -518,11 +518,12 @@ def filter_product_type_kind(qs, _, value):
qs = qs.filter(kind=value)
return qs


def filter_vendor_ids(qs, _, value):
_,vendor_ids = resolve_global_ids_to_primary_keys(
value,vendor_types.Vendor
)
vendor_warehouse = VendorWarehouse.objects.filter(vendor_id__pk__in=vendor_ids).values_list('warehouse',flat=True)
_, vendor_ids = resolve_global_ids_to_primary_keys(value, vendor_types.Vendor)
vendor_warehouse = VendorWarehouse.objects.filter(
vendor_id__pk__in=vendor_ids
).values_list("warehouse", flat=True)
print(vendor_warehouse)
return qs.filter(variants__stocks__warehouse__pk__in=vendor_warehouse)

Expand Down
18 changes: 18 additions & 0 deletions saleor/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4000,6 +4000,7 @@ type Mutation {
permissionGroupCreate(input: PermissionGroupCreateInput!): PermissionGroupCreate
permissionGroupUpdate(id: ID!, input: PermissionGroupUpdateInput!): PermissionGroupUpdate
permissionGroupDelete(id: ID!): PermissionGroupDelete
vendorStaffCreate(input: StaffVendorCreateInput!): VendorStaffCreate
}

input NameTranslationInput {
Expand Down Expand Up @@ -6567,6 +6568,17 @@ input StaffUserInput {
search: String
}

input StaffVendorCreateInput {
firstName: String
lastName: String
email: String
isActive: Boolean
note: String
addGroups: [ID!]
redirectUrl: String
password: String!
}

type Stock implements Node {
warehouse: Warehouse!
productVariant: ProductVariant!
Expand Down Expand Up @@ -6947,6 +6959,12 @@ input VendorSortingInput {
field: VendorSortField!
}

type VendorStaffCreate {
staffErrors: [StaffError!]! @deprecated(reason: "This field will be removed in Saleor 4.0. Use `errors` field instead.")
errors: [StaffError!]!
user: User
}

type VendorUpdate {
vendorErrors: [VendorError!]! @deprecated(reason: "This field will be removed in Saleor 4.0. Use `errors` field instead.")
errors: [VendorError!]!
Expand Down
19 changes: 11 additions & 8 deletions saleor/graphql/vendor/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
from django.core.exceptions import ValidationError

from ...core.permissions import VendorPermissions
from ..core.utils import validate_slug_and_generate_if_needed
from ...vendor import models
from ...vendor.error_codes import VendorErrorCode
from ..account.i18n import I18nMixin
from ..core.mutations import ModelDeleteMutation, ModelMutation
from ..core.types.common import VendorError
from ..core.utils import validate_slug_and_generate_if_needed
from .types import VendorCreateInput, VendorWarehouseInput


Expand All @@ -21,10 +21,10 @@ class Arguments:
class Meta:
description = "Create new Vendor"
model = models.Vendor
permissions = (VendorPermissions.MANAGE_VENDOR,)
# permissions = (VendorPermissions.MANAGE_VENDOR,)
error_type_class = VendorError
error_type_field = "vendor_errors"

@classmethod
def clean_input(cls, info, instance, data):
cleaned_input = super().clean_input(info, instance, data)
Expand All @@ -34,7 +34,7 @@ def clean_input(cls, info, instance, data):
)
except ValidationError as error:
error.code = VendorErrorCode.REQUIRED.value
raise ValidationError({"slug":error})
raise ValidationError({"slug": error})
return cleaned_input


Expand All @@ -52,17 +52,19 @@ class Meta:
error_type_class = VendorError
error_type_field = "vendor_errors"


class VendorDelete(ModelDeleteMutation):
class Arguments:
id = graphene.ID(required=True, description="ID of a vendor")

class Meta:
description = "Delete a vendor"
model = models.Vendor
permissions = (VendorPermissions.MANAGE_VENDOR,)
error_type_class = VendorError
error_type_field = "vendor_errors"


class VendorWarehouseCreate(ModelMutation, I18nMixin):
class Arguments:
input = VendorWarehouseInput(
Expand All @@ -72,12 +74,12 @@ class Arguments:
class Meta:
description = "Create new Vendor Warehouse"
model = models.VendorWarehouse
permissions = (VendorPermissions.MANAGE_VENDOR,)
# permissions = (VendorPermissions.MANAGE_VENDOR,)
error_type_class = VendorError
error_type_field = "vendor_errors"

class VendorWarehouseUpdate(VendorWarehouseCreate):

class VendorWarehouseUpdate(VendorWarehouseCreate):
class Arguments:
id = graphene.ID(required=True, description="ID of a vendorWarehouse")
input = VendorWarehouseInput(
Expand All @@ -91,6 +93,7 @@ class Meta:
error_type_class = VendorError
error_type_field = "vendor_errors"


class VendorWarehouseDelete(ModelDeleteMutation):
class Arguments:
id = graphene.ID(required=True, description="ID of a vendorWarehouse")
Expand All @@ -100,4 +103,4 @@ class Meta:
model = models.VendorWarehouse
permissions = (VendorPermissions.MANAGE_VENDOR,)
error_type_class = VendorError
error_type_field = "vendor_errors"
error_type_field = "vendor_errors"
32 changes: 14 additions & 18 deletions saleor/graphql/vendor/types.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,42 @@
import graphene
from ..core.connection import CountableDjangoObjectType

from ...vendor import models
from ..core.connection import CountableDjangoObjectType


# Basic input required for vendor
class VendorInput(graphene.InputObjectType):
slug = graphene.String(decription="Slug")


# More input fields for create required.
class VendorCreateInput(VendorInput):
shop_name = graphene.String(description="Shop Name")
user = graphene.ID(description="User id")
allocation = graphene.List(graphene.ID,description="Allocation list",name="allocation")
allocation = graphene.List(
graphene.ID, description="Allocation list", name="allocation"
)

# This might be for response is requried

# This might be for response is requried
class Vendor(CountableDjangoObjectType):

class Meta:
description = "Represents Vendor"
model = models.Vendor
interfaces = [graphene.relay.Node]
only_fields = [
"id",
"slug",
"shop_name",
"user",
"allocation"
]

only_fields = ["id", "slug", "shop_name", "user", "allocation"]


# input fields for create required.
class VendorWarehouseInput(graphene.InputObjectType):
vendor_id = graphene.ID(description="Vendor Id")
warehouse = graphene.ID(description="warehouse id", required=False)


# This is the response on submit.
class VendorWarehouse(CountableDjangoObjectType):

class Meta:
description = "Represents VendorWarehoue"
model = models.VendorWarehouse
interfaces = [graphene.relay.Node]
only_fields = [
"id",
"vendor_id",
"warehouse"
]
only_fields = ["id", "vendor_id", "warehouse"]
1 change: 1 addition & 0 deletions saleor/vendor/error_codes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


# error handle using the enum
class VendorErrorCode(Enum):
GRAPHQL_ERROR = "graphql_error"
Expand Down