Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add App API

Maciej Korycinski69a90874bcff
diff --git a/saleor/app/error_codes.py b/saleor/app/error_codes.py
new file mode 100644
index 0000000000..8f6429d019
--- /dev/null
+++ b/saleor/app/error_codes.py
@@ -0,0 +1,9 @@
+from enum import Enum
+
+
+class AppErrorCode(Enum):
+ GRAPHQL_ERROR = "graphql_error"
+ INVALID = "invalid"
+ NOT_FOUND = "not_found"
+ REQUIRED = "required"
+ UNIQUE = "unique"
diff --git a/saleor/graphql/account/deprecated/mutations_service_account.py b/saleor/graphql/account/deprecated/mutations_service_account.py
index 9d8ff1a4c7..7ffbdf8da6 100644
--- a/saleor/graphql/account/deprecated/mutations_service_account.py
+++ b/saleor/graphql/account/deprecated/mutations_service_account.py
@@ -6,7 +6,7 @@ from ...core.enums import PermissionEnum
from ...core.mutations import ModelDeleteMutation, ModelMutation
from ...core.types.common import AccountError
from ...meta.deprecated.mutations import ClearMetaBaseMutation, UpdateMetaBaseMutation
-from .types import ServiceAccount, ServiceAccountToken # noqa: F401
+from .types import ServiceAccount, ServiceAccountToken
class ServiceAccountInput(graphene.InputObjectType):
@@ -43,6 +43,10 @@ class ServiceAccountTokenCreate(ModelMutation):
error_type_class = AccountError
error_type_field = "account_errors"
+ @classmethod
+ def get_type_for_model(cls):
+ return ServiceAccountToken
+
@classmethod
def perform_mutation(cls, root, info, **data):
input_data = data.get("input", {})
@@ -70,6 +74,10 @@ class ServiceAccountTokenDelete(ModelDeleteMutation):
error_type_class = AccountError
error_type_field = "account_errors"
+ @classmethod
+ def get_type_for_model(cls):
+ return ServiceAccountToken
+
class ServiceAccountCreate(ModelMutation):
auth_token = graphene.types.String(
@@ -90,6 +98,10 @@ class ServiceAccountCreate(ModelMutation):
error_type_class = AccountError
error_type_field = "account_errors"
+ @classmethod
+ def get_type_for_model(cls):
+ return ServiceAccount
+
@classmethod
def clean_input(cls, info, instance, data, input_cls=None):
cleaned_input = super().clean_input(info, instance, data, input_cls)
@@ -137,6 +149,10 @@ class ServiceAccountUpdate(ModelMutation):
cleaned_input["permissions"] = get_permissions(cleaned_input["permissions"])
return cleaned_input
+ @classmethod
+ def get_type_for_model(cls):
+ return ServiceAccount
+
class ServiceAccountDelete(ModelDeleteMutation):
class Arguments:
@@ -152,6 +168,10 @@ class ServiceAccountDelete(ModelDeleteMutation):
error_type_class = AccountError
error_type_field = "account_errors"
+ @classmethod
+ def get_type_for_model(cls):
+ return ServiceAccount
+
class ServiceAccountUpdatePrivateMeta(UpdateMetaBaseMutation):
class Meta:
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index 52b44fceff..1592ccd332 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -1,6 +1,7 @@
from graphene_federation import build_schema
from .account.schema import AccountMutations, AccountQueries
+from .app.schema import AppMutations, AppQueries
from .checkout.schema import CheckoutMutations, CheckoutQueries
from .core.schema import CoreMutations, CoreQueries
from .discount.schema import DiscountMutations, DiscountQueries
@@ -21,6 +22,7 @@ from .webhook.schema import WebhookMutations, WebhookQueries
class Query(
AccountQueries,
+ AppQueries,
CheckoutQueries,
CoreQueries,
DiscountQueries,
@@ -43,6 +45,7 @@ class Query(
class Mutation(
AccountMutations,
+ AppMutations,
CheckoutMutations,
CoreMutations,
DiscountMutations,
diff --git a/saleor/graphql/app/filters.py b/saleor/graphql/app/filters.py
new file mode 100644
index 0000000000..530c081ce8
--- /dev/null
+++ b/saleor/graphql/app/filters.py
@@ -0,0 +1,19 @@
+import django_filters
+
+from ...app import models
+from ..utils import filter_by_query_param
+
+
+def filter_app_search(qs, _, value):
+ if value:
+ qs = filter_by_query_param(qs, value, ("name",))
+ return qs
+
+
+class AppFilter(django_filters.FilterSet):
+ search = django_filters.CharFilter(method=filter_app_search)
+ is_active = django_filters.BooleanFilter()
+
+ class Meta:
+ model = models.App
+ fields = ["search", "is_active"]
diff --git a/saleor/graphql/app/mutations.py b/saleor/graphql/app/mutations.py
new file mode 100644
index 0000000000..804d58e6d2
--- /dev/null
+++ b/saleor/graphql/app/mutations.py
@@ -0,0 +1,189 @@
+import graphene
+
+from ...app import models
+from ...core.permissions import AppPermission, get_permissions
+from ..core.enums import PermissionEnum
+from ..core.mutations import ModelDeleteMutation, ModelMutation
+from ..core.types.common import AppError
+from ..meta.deprecated.mutations import ClearMetaBaseMutation, UpdateMetaBaseMutation
+from .types import App, AppToken
+
+
+class AppInput(graphene.InputObjectType):
+ name = graphene.String(description="Name of the app.")
+ is_active = graphene.Boolean(description="Determine if this app should be enabled.")
+ permissions = graphene.List(
+ PermissionEnum,
+ description="List of permission code names to assign to this app.",
+ )
+
+
+class AppTokenInput(graphene.InputObjectType):
+ name = graphene.String(description="Name of the token.", required=False)
+ app = graphene.ID(description="ID of app.", required=True)
+
+
+class AppTokenCreate(ModelMutation):
+ auth_token = graphene.types.String(
+ description="The newly created authentication token."
+ )
+
+ class Arguments:
+ input = AppTokenInput(
+ required=True, description="Fields required to create a new auth token."
+ )
+
+ class Meta:
+ description = "Creates a new token."
+ model = models.AppToken
+ permissions = (AppPermission.MANAGE_APPS,)
+ error_type_class = AppError
+ error_type_field = "app_errors"
+
+ @classmethod
+ def get_type_for_model(cls):
+ # Fixme this method can be deleted when we will drop support for ServiceAccount
+ # Let's create ticket for this
+ return AppToken
+
+ @classmethod
+ def perform_mutation(cls, root, info, **data):
+ input_data = data.get("input", {})
+ instance = cls.get_instance(info, **data)
+ cleaned_input = cls.clean_input(info, instance, input_data)
+ instance = cls.construct_instance(instance, cleaned_input)
+ cls.clean_instance(info, instance)
+ cls.save(info, instance, cleaned_input)
+ cls._save_m2m(info, instance, cleaned_input)
+ response = cls.success_response(instance)
+ response.auth_token = instance.auth_token
+ return response
+
+
+class AppTokenDelete(ModelDeleteMutation):
+ class Arguments:
+ id = graphene.ID(description="ID of an auth token to delete.", required=True)
+
+ class Meta:
+ description = "Deletes an authentication token assigned to app."
+ model = models.AppToken
+ permissions = (AppPermission.MANAGE_APPS,)
+ error_type_class = AppError
+ error_type_field = "app_errors"
+
+ @classmethod
+ def get_type_for_model(cls):
+ return AppToken
+
+
+class AppCreate(ModelMutation):
+ auth_token = graphene.types.String(
+ description="The newly created authentication token."
+ )
+
+ class Arguments:
+ input = AppInput(
+ required=True, description="Fields required to create a new app.",
+ )
+
+ class Meta:
+ description = "Creates a new app."
+ model = models.App
+ permissions = (AppPermission.MANAGE_APPS,)
+ error_type_class = AppError
+ error_type_field = "app_errors"
+
+ @classmethod
+ def get_type_for_model(cls):
+ return App
+
+ @classmethod
+ def clean_input(cls, info, instance, data, input_cls=None):
+ cleaned_input = super().clean_input(info, instance, data, input_cls)
+ # clean and prepare permissions
+ if "permissions" in cleaned_input:
+ permissions = cleaned_input.pop("permissions")
+ cleaned_input["permissions"] = get_permissions(permissions)
+ return cleaned_input
+
+ @classmethod
+ def save(cls, info, instance, cleaned_input):
+ instance.save()
+ instance.tokens.create(name="Default")
+
+ @classmethod
+ def success_response(cls, instance):
+ response = super().success_response(instance)
+ response.auth_token = instance.tokens.get().auth_token
+ return response
+
+
+class AppUpdate(ModelMutation):
+ class Arguments:
+ id = graphene.ID(description="ID of an app to update.", required=True)
+ input = AppInput(
+ required=True, description="Fields required to update an existing app.",
+ )
+
+ class Meta:
+ description = "Updates an existing app."
+ model = models.App
+ permissions = (AppPermission.MANAGE_APPS,)
+ error_type_class = AppError
+ error_type_field = "app_errors"
+
+ @classmethod
+ def get_type_for_model(cls):
+ return App
+
+ @classmethod
+ def clean_input(cls, info, instance, data, input_cls=None):
+ cleaned_input = super().clean_input(info, instance, data, input_cls)
+ # clean and prepare permissions
+ if "permissions" in cleaned_input:
+ cleaned_input["permissions"] = get_permissions(cleaned_input["permissions"])
+ return cleaned_input
+
+
+class AppDelete(ModelDeleteMutation):
+ class Arguments:
+ id = graphene.ID(description="ID of an app to delete.", required=True)
+
+ class Meta:
+ description = "Deletes an app."
+ model = models.App
+ permissions = (AppPermission.MANAGE_APPS,)
+ error_type_class = AppError
+ error_type_field = "app_errors"
+
+ @classmethod
+ def get_type_for_model(cls):
+ return App
+
+
+class AppUpdatePrivateMeta(UpdateMetaBaseMutation):
+ class Meta:
+ description = "Updates private metadata for an app."
+ permissions = (AppPermission.MANAGE_APPS,)
+ model = models.App
+ public = False
+ error_type_class = AppError
+ error_type_field = "app_errors"
+
+ @classmethod
+ def get_type_for_model(cls):
+ return App
+
+
+class AppClearPrivateMeta(ClearMetaBaseMutation):
+ class Meta:
+ description = "Clear private metadata for an app."
+ model = models.App
+ permissions = (AppPermission.MANAGE_APPS,)
+ public = False
+ error_type_class = AppError
+ error_type_field = "app_errors"
+
+ @classmethod
+ def get_type_for_model(cls):
+ return App
diff --git a/saleor/graphql/app/resolvers.py b/saleor/graphql/app/resolvers.py
new file mode 100644
index 0000000000..f12e77f08e
--- /dev/null
+++ b/saleor/graphql/app/resolvers.py
@@ -0,0 +1,11 @@
+import graphene_django_optimizer as gql_optimizer
+
+from ...app import models
+from ..utils import sort_queryset
+from .sorters import AppSortField
+
+
+def resolve_apps(info, sort_by=None, **_kwargs):
+ qs = models.App.objects.all()
+ qs = sort_queryset(qs, sort_by, AppSortField)
+ return gql_optimizer.query(qs, info)
diff --git a/saleor/graphql/app/schema.py b/saleor/graphql/app/schema.py
new file mode 100644
index 0000000000..cb3930ea13
--- /dev/null
+++ b/saleor/graphql/app/schema.py
@@ -0,0 +1,47 @@
+import graphene
+
+from ...core.permissions import AppPermission
+from ..core.fields import FilterInputConnectionField
+from ..core.types import FilterInputObjectType
+from ..decorators import permission_required
+from .filters import AppFilter
+from .mutations import AppCreate, AppDelete, AppTokenCreate, AppTokenDelete, AppUpdate
+from .resolvers import resolve_apps
+from .sorters import AppSortingInput
+from .types import App
+
+
+class AppFilterInput(FilterInputObjectType):
+ class Meta:
+ filterset_class = AppFilter
+
+
+class AppQueries(graphene.ObjectType):
+ apps = FilterInputConnectionField(
+ App,
+ filter=AppFilterInput(description="Filtering options for apps."),
+ sort_by=AppSortingInput(description="Sort apps."),
+ description="List of the apps.",
+ )
+ app = graphene.Field(
+ App,
+ id=graphene.Argument(graphene.ID, description="ID of the app.", required=True),
+ description="Look up a app by ID.",
+ )
+
+ @permission_required(AppPermission.MANAGE_APPS)
+ def resolve_apps(self, info, **kwargs):
+ return resolve_apps(info, **kwargs)
+
+ @permission_required(AppPermission.MANAGE_APPS)
+ def resolve_app(self, info, id):
+ return graphene.Node.get_node_from_global_id(info, id, App)
+
+
+class AppMutations(graphene.ObjectType):
+ app_create = AppCreate.Field()
+ app_update = AppUpdate.Field()
+ app_delete = AppDelete.Field()
+
+ app_token_create = AppTokenCreate.Field()
+ app_token_delete = AppTokenDelete.Field()
diff --git a/saleor/graphql/app/sorters.py b/saleor/graphql/app/sorters.py
new file mode 100644
index 0000000000..3d0276aa20
--- /dev/null
+++ b/saleor/graphql/app/sorters.py
@@ -0,0 +1,25 @@
+import graphene
+
+from ..core.types import SortInputObjectType
+
+
+class AppSortField(graphene.Enum):
+ NAME = "name"
+ CREATION_DATE = "created"
+
+ @property
+ def description(self):
+ # pylint: disable=no-member
+ if self in [
+ AppSortField.NAME,
+ AppSortField.CREATION_DATE,
+ ]:
+ sort_name = self.name.lower().replace("_", " ")
+ return f"Sort apps by {sort_name}."
+ raise ValueError("Unsupported enum value: %s" % self.value)
+
+
+class AppSortingInput(SortInputObjectType):
+ class Meta:
+ sort_enum = AppSortField
+ type_name = "apps"
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
index f906eb6604..ad72c03f79 100644
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -424,6 +424,10 @@ class ModelMutation(BaseMutation):
def save(cls, info, instance, cleaned_input):
instance.save()
+ @classmethod
+ def get_type_for_model(cls):
+ return registry.get_type_for_model(cls._meta.model)
+
@classmethod
def get_instance(cls, info, **data):
"""Retrieve an instance from the supplied global id.
@@ -432,7 +436,7 @@ class ModelMutation(BaseMutation):
"""
object_id = data.get("id")
if object_id:
- model_type = registry.get_type_for_model(cls._meta.model)
+ model_type = cls.get_type_for_model()
instance = cls.get_node_or_error(info, object_id, only_type=model_type)
else:
instance = cls._meta.model()
@@ -476,7 +480,7 @@ class ModelDeleteMutation(ModelMutation):
raise PermissionDenied()
node_id = data.get("id")
- model_type = registry.get_type_for_model(cls._meta.model)
+ model_type = cls.get_type_for_model()
instance = cls.get_node_or_error(info, node_id, only_type=model_type)
if instance:
diff --git a/saleor/graphql/meta/permissions.py b/saleor/graphql/meta/permissions.py
index 134cfa8171..8e5ba0a6e7 100644
--- a/saleor/graphql/meta/permissions.py
+++ b/saleor/graphql/meta/permissions.py
@@ -51,7 +51,7 @@ def order_permissions(_info, _object_pk: Any) -> List[BasePermissionEnum]:
return [OrderPermissions.MANAGE_ORDERS]
-def service_account_permissions(_info, _object_pk: int) -> List[BasePermissionEnum]:
+def app_permissions(_info, _object_pk: int) -> List[BasePermissionEnum]:
return [AppPermission.MANAGE_APPS]
@@ -70,7 +70,7 @@ PUBLIC_META_PERMISSION_MAP = {
"Product": product_permissions,
"ProductType": product_permissions,
"ProductVariant": product_permissions,
- "ServiceAccount": service_account_permissions,
+ "App": app_permissions,
"User": public_user_permissions,
}
@@ -86,6 +86,6 @@ PRIVATE_META_PERMISSION_MAP = {
"Product": product_permissions,
"ProductType": product_permissions,
"ProductVariant": product_permissions,
- "ServiceAccount": service_account_permissions,
+ "App": app_permissions,
"User": private_user_permissions,
}
diff --git a/saleor/graphql/meta/resolvers.py b/saleor/graphql/meta/resolvers.py
index ed1973859f..384cbcbe26 100644
--- a/saleor/graphql/meta/resolvers.py
+++ b/saleor/graphql/meta/resolvers.py
@@ -15,7 +15,7 @@ from .permissions import PRIVATE_META_PERMISSION_MAP
def resolve_object_with_metadata_type(instance: ModelWithMetadata):
# Imports inside resolvers to avoid circular imports.
from ..account import types as account_types
- from ..account.deprecated.types import ServiceAccount
+ from ..app import types as app_types
from ..checkout import types as checkout_types
from ..order import types as order_types
from ..product import types as product_types
@@ -31,7 +31,7 @@ def resolve_object_with_metadata_type(instance: ModelWithMetadata):
product_models.Product: product_types.Product,
product_models.ProductType: product_types.ProductType,
product_models.ProductVariant: product_types.ProductVariant,
- app_models.App: ServiceAccount, # FIXME
+ app_models.App: app_types.App,
account_models.User: account_types.User,
}
return MODEL_TO_TYPE_MAP.get(type(instance), None)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 941f754027..d234f079ee 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -184,6 +184,108 @@ type AddressValidationData {
postalCodePrefix: String
}
+type App implements Node & ObjectWithMetadata {
+ id: ID!
+ name: String
+ created: DateTime
+ isActive: Boolean
+ permissions: [PermissionDisplay]
+ tokens: [AppToken]
+ privateMetadata: [MetadataItem]!
+ metadata: [MetadataItem]!
+ privateMeta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `privetaMetadata` field instead. ")
+ meta: [MetaStore]! @deprecated(reason: "DEPRECATED: Will be removed in Saleor 2.11. use the `metadata` field instead. ")
+}
+
+type AppCountableConnection {
+ pageInfo: PageInfo!
+ edges: [AppCountableEdge!]!
+ totalCount: Int
+}
+
+type AppCountableEdge {
+ node: App!
+ cursor: String!
+}
+
+type AppCreate {
+ errors: [Error!]!
+ authToken: String
+ appErrors: [AppError!]!
+ app: App
+}
+
+type AppDelete {
+ errors: [Error!]!
+ appErrors: [AppError!]!
+ app: App
+}
+
+type AppError {
+ field: String
+ message: String
+ code: AppErrorCode!
+}
+
+enum AppErrorCode {
+ GRAPHQL_ERROR
+ INVALID
+ NOT_FOUND
+ REQUIRED
+ UNIQUE
+}
+
+input AppFilterInput {
+ search: String
+ isActive: Boolean
+}
+
+input AppInput {
+ name: String
+ isActive: Boolean
+ permissions: [PermissionEnum]
+}
+
+enum AppSortField {
+ NAME
+ CREATION_DATE
+}
+
+input AppSortingInput {
+ direction: OrderDirection!
+ field: AppSortField!
+}
+
+type AppToken implements Node {
+ name: String
+ authToken: String
+ id: ID!
+}
+
+type AppTokenCreate {
+ errors: [Error!]!
+ authToken: String
+ appErrors: [AppError!]!
+ appToken: AppToken
+}
+
+type AppTokenDelete {
+ errors: [Error!]!
+ appErrors: [AppError!]!
+ appToken: AppToken
+}
+
+input AppTokenInput {
+ name: String
+ app: ID!
+}
+
+type AppUpdate {
+ errors: [Error!]!
+ appErrors: [AppError!]!
+ app: App
+}
+
type AssignNavigation {
errors: [Error!]!
menu: Menu
@@ -2374,6 +2476,11 @@ type Mutation {
checkoutClearMetadata(id: ID!, input: MetaPath!): CheckoutClearMeta @deprecated(reason: "Will be removed in Saleor 2.11. Use the `DeleteMetadata` mutation instead.")
checkoutUpdatePrivateMetadata(id: ID!, input: MetaInput!): CheckoutUpdatePrivateMeta @deprecated(reason: "Will be removed in Saleor 2.11.Use the `UpdatePrivateMetadata` mutation instead.")
checkoutClearPrivateMetadata(id: ID!, input: MetaPath!): CheckoutClearPrivateMeta @deprecated(reason: "Will be removed in Saleor 2.11.Use the `DeletePrivateMetadata` mutation instead.")
+ appCreate(input: AppInput!): AppCreate
+ appUpdate(id: ID!, input: AppInput!): AppUpdate
+ appDelete(id: ID!): AppDelete
+ appTokenCreate(input: AppTokenInput!): AppTokenCreate
+ appTokenDelete(id: ID!): AppTokenDelete
requestPasswordReset(email: String!, redirectUrl: String!): RequestPasswordReset
confirmAccount(email: String!, token: String!): ConfirmAccount
setPassword(token: String!, email: String!, password: String!): SetPassword
@@ -3776,6 +3883,8 @@ type Query {
checkouts(before: String, after: String, first: Int, last: Int): CheckoutCountableConnection
checkoutLine(id: ID): CheckoutLine
checkoutLines(before: String, after: String, first: Int, last: Int): CheckoutLineCountableConnection
+ apps(filter: AppFilterInput, sortBy: AppSortingInput, before: String, after: String, first: Int, last: Int): AppCountableConnection
+ app(id: ID!): App
addressValidationRules(countryCode: CountryCode!, countryArea: String, city: String, cityArea: String): AddressValidationData
address(id: ID!): Address
customers(filter: CustomerFilterInput, sortBy: UserSortingInput, before: String, after: String, first: Int, last: Int): UserCountableConnection
@@ -5095,7 +5204,7 @@ enum WeightUnitsEnum {
scalar _Any
-union _Entity = Address | User | Group | ServiceAccount | ProductVariant | Product | ProductType | Collection | Category | ProductImage
+union _Entity = Address | User | Group | ServiceAccount | App | ProductVariant | Product | ProductType | Collection | Category | ProductImage
type _Service {
sdl: String
diff --git a/tests/api/test_meta_mutations.py b/tests/api/test_meta_mutations.py
index 8f36bd693e..625661f1b5 100644
--- a/tests/api/test_meta_mutations.py
+++ b/tests/api/test_meta_mutations.py
@@ -127,7 +127,7 @@ def test_add_public_metadata_for_customer_as_staff(
)
-def test_add_public_metadata_for_customer_as_service_account(
+def test_add_public_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -144,7 +144,7 @@ def test_add_public_metadata_for_customer_as_service_account(
)
-def test_add_multiple_public_metadata_for_customer_as_service_account(
+def test_add_multiple_public_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -179,7 +179,7 @@ def test_add_public_metadata_for_other_staff_as_staff(
)
-def test_add_public_metadata_for_staff_as_service_account(
+def test_add_public_metadata_for_staff_as_app(
app_api_client, permission_manage_staff, admin_user
):
# given
@@ -414,23 +414,18 @@ def test_add_public_metadata_for_product_variant(
)
-def test_add_public_metadata_for_service_account(
- staff_api_client, permission_manage_service_accounts, app
-):
+def test_add_public_metadata_for_app(staff_api_client, permission_manage_apps, app):
# given
- service_account_id = graphene.Node.to_global_id("ServiceAccount", app.pk)
+ app_id = graphene.Node.to_global_id("App", app.pk)
# when
response = execute_update_public_metadata_for_item(
- staff_api_client,
- permission_manage_service_accounts,
- service_account_id,
- "ServiceAccount",
+ staff_api_client, permission_manage_apps, app_id, "App",
)
# then
assert item_contains_proper_public_metadata(
- response["data"]["updateMetadata"]["item"], app, service_account_id
+ response["data"]["updateMetadata"]["item"], app, app_id
)
@@ -594,7 +589,7 @@ def test_delete_public_metadata_for_customer_as_staff(
)
-def test_delete_public_metadata_for_customer_as_service_account(
+def test_delete_public_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -613,7 +608,7 @@ def test_delete_public_metadata_for_customer_as_service_account(
)
-def test_delete_multiple_public_metadata_for_customer_as_service_account(
+def test_delete_multiple_public_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -654,7 +649,7 @@ def test_delete_public_metadata_for_other_staff_as_staff(
)
-def test_delete_public_metadata_for_staff_as_service_account(
+def test_delete_public_metadata_for_staff_as_app(
app_api_client, permission_manage_staff, admin_user
):
# given
@@ -917,23 +912,18 @@ def test_delete_public_metadata_for_product_variant(
)
-def test_delete_public_metadata_for_service_account(
- staff_api_client, permission_manage_service_accounts, app
-):
+def test_delete_public_metadata_for_app(staff_api_client, permission_manage_apps, app):
# given
- service_account_id = graphene.Node.to_global_id("ServiceAccount", app.pk)
+ app_id = graphene.Node.to_global_id("App", app.pk)
# when
response = execute_clear_public_metadata_for_item(
- staff_api_client,
- permission_manage_service_accounts,
- service_account_id,
- "ServiceAccount",
+ staff_api_client, permission_manage_apps, app_id, "App",
)
# then
assert item_without_public_metadata(
- response["data"]["deleteMetadata"]["item"], app, service_account_id
+ response["data"]["deleteMetadata"]["item"], app, app_id
)
@@ -1124,7 +1114,7 @@ def test_add_private_metadata_for_customer_as_staff(
)
-def test_add_private_metadata_for_customer_as_service_account(
+def test_add_private_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -1141,7 +1131,7 @@ def test_add_private_metadata_for_customer_as_service_account(
)
-def test_add_multiple_private_metadata_for_customer_as_service_account(
+def test_add_multiple_private_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -1176,7 +1166,7 @@ def test_add_private_metadata_for_other_staff_as_staff(
)
-def test_add_private_metadata_for_staff_as_service_account(
+def test_add_private_metadata_for_staff_as_app(
app_api_client, permission_manage_staff, admin_user
):
# given
@@ -1421,23 +1411,18 @@ def test_add_private_metadata_for_product_variant(
)
-def test_add_private_metadata_for_service_account(
- staff_api_client, permission_manage_service_accounts, app
-):
+def test_add_private_metadata_for_app(staff_api_client, permission_manage_apps, app):
# given
- service_account_id = graphene.Node.to_global_id("ServiceAccount", app.pk)
+ app_id = graphene.Node.to_global_id("App", app.pk)
# when
response = execute_update_private_metadata_for_item(
- staff_api_client,
- permission_manage_service_accounts,
- service_account_id,
- "ServiceAccount",
+ staff_api_client, permission_manage_apps, app_id, "App",
)
# then
assert item_contains_proper_private_metadata(
- response["data"]["updatePrivateMetadata"]["item"], app, service_account_id,
+ response["data"]["updatePrivateMetadata"]["item"], app, app_id,
)
@@ -1609,7 +1594,7 @@ def test_delete_private_metadata_for_customer_as_staff(
)
-def test_delete_private_metadata_for_customer_as_service_account(
+def test_delete_private_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -1628,7 +1613,7 @@ def test_delete_private_metadata_for_customer_as_service_account(
)
-def test_delete_multiple_private_metadata_for_customer_as_service_account(
+def test_delete_multiple_private_metadata_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -1669,7 +1654,7 @@ def test_delete_private_metadata_for_other_staff_as_staff(
)
-def test_delete_private_metadata_for_staff_as_service_account(
+def test_delete_private_metadata_for_staff_as_app(
app_api_client, permission_manage_staff, admin_user
):
# given
@@ -1946,23 +1931,18 @@ def test_delete_private_metadata_for_product_variant(
)
-def test_delete_private_metadata_for_service_account(
- staff_api_client, permission_manage_service_accounts, app
-):
+def test_delete_private_metadata_for_app(staff_api_client, permission_manage_apps, app):
# given
- service_account_id = graphene.Node.to_global_id("ServiceAccount", app.pk)
+ app_id = graphene.Node.to_global_id("App", app.pk)
# when
response = execute_clear_private_metadata_for_item(
- staff_api_client,
- permission_manage_service_accounts,
- service_account_id,
- "ServiceAccount",
+ staff_api_client, permission_manage_apps, app_id, "App",
)
# then
assert item_without_private_metadata(
- response["data"]["deletePrivateMetadata"]["item"], app, service_account_id,
+ response["data"]["deletePrivateMetadata"]["item"], app, app_id,
)
diff --git a/tests/api/test_meta_queries.py b/tests/api/test_meta_queries.py
index c9695ede46..23a9d5fa21 100644
--- a/tests/api/test_meta_queries.py
+++ b/tests/api/test_meta_queries.py
@@ -85,7 +85,7 @@ def test_query_public_meta_for_customer_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_customer_as_service_account(
+def test_query_public_meta_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -125,7 +125,7 @@ def test_query_public_meta_for_staff_as_other_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_staff_as_service_account(
+def test_query_public_meta_for_staff_as_app(
app_api_client, permission_manage_staff, admin_user
):
# given
@@ -231,7 +231,7 @@ def test_query_public_meta_for_checkout_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_checkout_as_service_account(
+def test_query_public_meta_for_checkout_as_app(
app_api_client, checkout, customer_user, permission_manage_checkouts
):
# given
@@ -324,7 +324,7 @@ def test_query_public_meta_for_order_by_token_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_order_by_token_as_service_account(
+def test_query_public_meta_for_order_by_token_as_app(
app_api_client, order, customer_user, permission_manage_orders
):
# given
@@ -409,7 +409,7 @@ def test_query_public_meta_for_order_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_order_as_service_account(
+def test_query_public_meta_for_order_as_app(
app_api_client, order, customer_user, permission_manage_orders
):
# given
@@ -494,7 +494,7 @@ def test_query_public_meta_for_draft_order_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_draft_order_as_service_account(
+def test_query_public_meta_for_draft_order_as_app(
app_api_client, draft_order, customer_user, permission_manage_orders
):
# given
@@ -598,7 +598,7 @@ def test_query_public_meta_for_fulfillment_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_fulfillment_as_service_account(
+def test_query_public_meta_for_fulfillment_as_app(
app_api_client, fulfilled_order, customer_user, permission_manage_orders
):
# given
@@ -691,7 +691,7 @@ def test_query_public_meta_for_attribute_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_attribute_as_service_account(
+def test_query_public_meta_for_attribute_as_app(
app_api_client, color_attribute, permission_manage_products
):
# given
@@ -781,7 +781,7 @@ def test_query_public_meta_for_category_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_category_as_service_account(
+def test_query_public_meta_for_category_as_app(
app_api_client, category, permission_manage_products
):
# given
@@ -871,7 +871,7 @@ def test_query_public_meta_for_collection_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_collection_as_service_account(
+def test_query_public_meta_for_collection_as_app(
app_api_client, collection, permission_manage_products
):
# given
@@ -959,7 +959,7 @@ def test_query_public_meta_for_digital_content_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_digital_content_as_service_account(
+def test_query_public_meta_for_digital_content_as_app(
app_api_client, digital_content, permission_manage_products
):
# given
@@ -1049,7 +1049,7 @@ def test_query_public_meta_for_product_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_product_as_service_account(
+def test_query_public_meta_for_product_as_app(
app_api_client, product, permission_manage_products
):
# given
@@ -1139,7 +1139,7 @@ def test_query_public_meta_for_product_type_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_product_type_as_service_account(
+def test_query_public_meta_for_product_type_as_app(
app_api_client, product_type, permission_manage_products
):
# given
@@ -1231,7 +1231,7 @@ def test_query_public_meta_for_product_variant_as_staff(
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_product_variant_as_service_account(
+def test_query_public_meta_for_product_variant_as_app(
app_api_client, variant, permission_manage_products
):
# given
@@ -1254,9 +1254,9 @@ def test_query_public_meta_for_product_variant_as_service_account(
assert metadata["value"] == PUBLIC_VALUE
-QUERY_SERVICE_ACCOUNT_PUBLIC_META = """
- query serviceAccountMeta($id: ID!){
- serviceAccount(id: $id){
+QUERY_APP_PUBLIC_META = """
+ query appMeta($id: ID!){
+ app(id: $id){
metadata{
key
value
@@ -1266,72 +1266,68 @@ QUERY_SERVICE_ACCOUNT_PUBLIC_META = """
"""
-def test_query_public_meta_for_service_account_as_anonymous_user(api_client, app):
+def test_query_public_meta_for_app_as_anonymous_user(api_client, app):
# given
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
- response = api_client.post_graphql(QUERY_SERVICE_ACCOUNT_PUBLIC_META, variables)
+ response = api_client.post_graphql(QUERY_APP_PUBLIC_META, variables)
# then
assert_no_permission(response)
-def test_query_public_meta_for_service_account_as_customer(user_api_client, app):
+def test_query_public_meta_for_app_as_customer(user_api_client, app):
# given
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
- response = user_api_client.post_graphql(
- QUERY_SERVICE_ACCOUNT_PUBLIC_META, variables
- )
+ response = user_api_client.post_graphql(QUERY_APP_PUBLIC_META, variables)
# then
assert_no_permission(response)
-def test_query_public_meta_for_service_account_as_staff(
- staff_api_client, app, permission_manage_service_accounts
+def test_query_public_meta_for_app_as_staff(
+ staff_api_client, app, permission_manage_apps
):
# given
app.store_value_in_metadata({PUBLIC_KEY: PUBLIC_VALUE})
app.save(update_fields=["metadata"])
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
response = staff_api_client.post_graphql(
- QUERY_SERVICE_ACCOUNT_PUBLIC_META,
+ QUERY_APP_PUBLIC_META,
variables,
- [permission_manage_service_accounts],
+ [permission_manage_apps],
check_no_permissions=False,
)
content = get_graphql_content(response)
# then
- metadata = content["data"]["serviceAccount"]["metadata"][0]
+ metadata = content["data"]["app"]["metadata"][0]
assert metadata["key"] == PUBLIC_KEY
assert metadata["value"] == PUBLIC_VALUE
-def test_query_public_meta_for_service_account_as_service_account(
- app_api_client, app, permission_manage_service_accounts
-):
+def test_query_public_meta_for_app_as_app(app_api_client, app, permission_manage_apps):
# given
app.store_value_in_metadata({PUBLIC_KEY: PUBLIC_VALUE})
app.save(update_fields=["metadata"])
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
response = app_api_client.post_graphql(
- QUERY_SERVICE_ACCOUNT_PUBLIC_META,
+ QUERY_APP_PUBLIC_META,
variables,
- [permission_manage_service_accounts],
+ [permission_manage_apps],
check_no_permissions=False,
)
content = get_graphql_content(response)
# then
- metadata = content["data"]["serviceAccount"]["metadata"][0]
+ metadata = content["data"]["app"]["metadata"][0]
assert metadata["key"] == PUBLIC_KEY
assert metadata["value"] == PUBLIC_VALUE
@@ -1424,7 +1420,7 @@ def test_query_private_meta_for_customer_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_customer_as_service_account(
+def test_query_private_meta_for_customer_as_app(
app_api_client, permission_manage_users, customer_user
):
# given
@@ -1464,7 +1460,7 @@ def test_query_private_meta_for_staff_as_other_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_staff_as_service_account(
+def test_query_private_meta_for_staff_as_app(
app_api_client, permission_manage_staff, admin_user
):
# given
@@ -1560,7 +1556,7 @@ def test_query_private_meta_for_checkout_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_checkout_as_service_account(
+def test_query_private_meta_for_checkout_as_app(
app_api_client, checkout, customer_user, permission_manage_checkouts
):
# given
@@ -1646,7 +1642,7 @@ def test_query_private_meta_for_order_by_token_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_order_by_token_as_service_account(
+def test_query_private_meta_for_order_by_token_as_app(
app_api_client, order, customer_user, permission_manage_orders
):
# given
@@ -1730,7 +1726,7 @@ def test_query_private_meta_for_order_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_order_as_service_account(
+def test_query_private_meta_for_order_as_app(
app_api_client, order, customer_user, permission_manage_orders
):
# given
@@ -1815,7 +1811,7 @@ def test_query_private_meta_for_draft_order_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_draft_order_as_service_account(
+def test_query_private_meta_for_draft_order_as_app(
app_api_client, draft_order, customer_user, permission_manage_orders
):
# given
@@ -1907,7 +1903,7 @@ def test_query_private_meta_for_fulfillment_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_fulfillment_as_service_account(
+def test_query_private_meta_for_fulfillment_as_app(
app_api_client, fulfilled_order, customer_user, permission_manage_orders
):
# given
@@ -1992,7 +1988,7 @@ def test_query_private_meta_for_attribute_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_attribute_as_service_account(
+def test_query_private_meta_for_attribute_as_app(
app_api_client, color_attribute, permission_manage_products
):
# given
@@ -2072,7 +2068,7 @@ def test_query_private_meta_for_category_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_category_as_service_account(
+def test_query_private_meta_for_category_as_app(
app_api_client, category, permission_manage_products
):
# given
@@ -2152,7 +2148,7 @@ def test_query_private_meta_for_collection_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_collection_as_service_account(
+def test_query_private_meta_for_collection_as_app(
app_api_client, collection, permission_manage_products
):
# given
@@ -2240,7 +2236,7 @@ def test_query_private_meta_for_digital_content_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_digital_content_as_service_account(
+def test_query_private_meta_for_digital_content_as_app(
app_api_client, digital_content, permission_manage_products
):
# given
@@ -2320,7 +2316,7 @@ def test_query_private_meta_for_product_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_product_as_service_account(
+def test_query_private_meta_for_product_as_app(
app_api_client, product, permission_manage_products
):
# given
@@ -2402,7 +2398,7 @@ def test_query_private_meta_for_product_type_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_product_type_as_service_account(
+def test_query_private_meta_for_product_type_as_app(
app_api_client, product_type, permission_manage_products
):
# given
@@ -2488,7 +2484,7 @@ def test_query_private_meta_for_product_variant_as_staff(
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_product_variant_as_service_account(
+def test_query_private_meta_for_product_variant_as_app(
app_api_client, variant, permission_manage_products
):
# given
@@ -2511,9 +2507,9 @@ def test_query_private_meta_for_product_variant_as_service_account(
assert metadata["value"] == PRIVATE_VALUE
-QUERY_SERVICE_ACCOUNT_PRIVATE_META = """
- query serviceAccountMeta($id: ID!){
- serviceAccount(id: $id){
+QUERY_APP_PRIVATE_META = """
+ query appMeta($id: ID!){
+ app(id: $id){
privateMetadata{
key
value
@@ -2523,71 +2519,67 @@ QUERY_SERVICE_ACCOUNT_PRIVATE_META = """
"""
-def test_query_private_meta_for_service_account_as_anonymous_user(api_client, app):
+def test_query_private_meta_for_app_as_anonymous_user(api_client, app):
# given
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
- response = api_client.post_graphql(QUERY_SERVICE_ACCOUNT_PRIVATE_META, variables)
+ response = api_client.post_graphql(QUERY_APP_PRIVATE_META, variables)
# then
assert_no_permission(response)
-def test_query_private_meta_for_service_account_as_customer(user_api_client, app):
+def test_query_private_meta_for_app_as_customer(user_api_client, app):
# given
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
- response = user_api_client.post_graphql(
- QUERY_SERVICE_ACCOUNT_PRIVATE_META, variables
- )
+ response = user_api_client.post_graphql(QUERY_APP_PRIVATE_META, variables)
# then
assert_no_permission(response)
-def test_query_private_meta_for_service_account_as_staff(
- staff_api_client, app, permission_manage_service_accounts
+def test_query_private_meta_for_app_as_staff(
+ staff_api_client, app, permission_manage_apps
):
# given
app.store_value_in_private_metadata({PRIVATE_KEY: PRIVATE_VALUE})
app.save(update_fields=["private_metadata"])
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
response = staff_api_client.post_graphql(
- QUERY_SERVICE_ACCOUNT_PRIVATE_META,
+ QUERY_APP_PRIVATE_META,
variables,
- [permission_manage_service_accounts],
+ [permission_manage_apps],
check_no_permissions=False,
)
content = get_graphql_content(response)
# then
- metadata = content["data"]["serviceAccount"]["privateMetadata"][0]
+ metadata = content["data"]["app"]["privateMetadata"][0]
assert metadata["key"] == PRIVATE_KEY
assert metadata["value"] == PRIVATE_VALUE
-def test_query_private_meta_for_service_account_as_service_account(
- app_api_client, app, permission_manage_service_accounts
-):
+def test_query_private_meta_for_app_as_app(app_api_client, app, permission_manage_apps):
# given
app.store_value_in_private_metadata({PRIVATE_KEY: PRIVATE_VALUE})
app.save(update_fields=["private_metadata"])
- variables = {"id": graphene.Node.to_global_id("ServiceAccount", app.pk)}
+ variables = {"id": graphene.Node.to_global_id("App", app.pk)}
# when
response = app_api_client.post_graphql(
- QUERY_SERVICE_ACCOUNT_PRIVATE_META,
+ QUERY_APP_PRIVATE_META,
variables,
- [permission_manage_service_accounts],
+ [permission_manage_apps],
check_no_permissions=False,
)
content = get_graphql_content(response)
# then
- metadata = content["data"]["serviceAccount"]["privateMetadata"][0]
+ metadata = content["data"]["app"]["privateMetadata"][0]
assert metadata["key"] == PRIVATE_KEY
assert metadata["value"] == PRIVATE_VALUE
diff --git a/tests/conftest.py b/tests/conftest.py
index d67f81d490..3535638151 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -583,6 +583,11 @@ def permission_manage_service_accounts():
return Permission.objects.get(codename="manage_apps")
+def permission_manage_apps():
+ return Permission.objects.get(codename="manage_apps")
+
+
@pytest.fixture
def product_type(color_attribute, size_attribute):
product_type = ProductType.objects.create(