Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add new type of target and include openAs option
Maciej Korycinski4e6dca308547
diff --git a/saleor/app/app_manifest_sample.json b/saleor/app/app_manifest_sample.jsonindex 12e46b11b4..2c4129215b 100644--- a/saleor/app/app_manifest_sample.json+++ b/saleor/app/app_manifest_sample.json@@ -1,14 +1,41 @@{- "id": "saleor.app.sample",- "version": "1.0.0",- "name": "My Wonderful App",- "about": "My Wonderful App is a wonderful App for Saleor.",- "permissions": ["MANAGE_USERS", "MANAGE_STAFF"],- "appUrl": "http://localhost:3000/app",- "configurationUrl": "htpp://localhost:3000/configuration",- "tokenTargetUrl": "http://localhost:3000/register",- "dataPrivacy": "Lorem ipsum",- "dataPrivacyUrl": "http://localhost:3000/app-data-privacy",- "homepageUrl": "http://localhost:3000/homepage",- "supportUrl": "http://localhost:3000/support"+ "name": "Saleor App",+ "version": "1.0.0",+ "about": "",+ "dataPrivacy": "",+ "dataPrivacyUrl": "",+ "homepageUrl": "https://example.com/homepage",+ "supportUrl": "https://example.com/support",+ "id": "sample-app",+ "permissions": [+ "MANAGE_PRODUCTS",+ "MANAGE_ORDERS"+ ],+ "appUrl": "https://example.com/app",+ "extensions": [+ {+ "label": "Create with Sample app",+ "view": "PRODUCT",+ "type": "OVERVIEW",+ "target": "CREATE",+ "openAs": "POPUP",+ "permissions": [+ "MANAGE_PRODUCTS"+ ],+ "url": "https://example.com/extension/"+ },+ {+ "label": "Create with App and redirect",+ "view": "PRODUCT",+ "type": "OVERVIEW",+ "target": "CREATE",+ "openAs": "APP_PAGE",+ "permissions": [+ "MANAGE_PRODUCTS"+ ],+ "url": "/extension/redirect"+ }+ ],+ "configurationUrl": "https://example.com/configuration/",+ "tokenTargetUrl": "https://example.com/configuration/install"}diff --git a/saleor/app/const.py b/saleor/app/const.pynew file mode 100644index 0000000000..dc7e88c094--- /dev/null+++ b/saleor/app/const.py@@ -0,0 +1,42 @@+from .types import (+ AppExtensionOpenAs,+ AppExtensionTarget,+ AppExtensionType,+ AppExtensionView,+)++# Stores all potential way of configuration of extension+AVAILABLE_APP_EXTENSION_CONFIGS = {+ AppExtensionType.DETAILS: {+ AppExtensionView.PRODUCT: [+ AppExtensionTarget.CREATE,+ AppExtensionTarget.MORE_ACTIONS,+ ]+ },+ AppExtensionType.OVERVIEW: {+ AppExtensionView.PRODUCT: [+ AppExtensionTarget.CREATE,+ AppExtensionTarget.MORE_ACTIONS,+ ]+ },+ AppExtensionType.NAVIGATION: {+ AppExtensionView.ALL: [+ AppExtensionTarget.CATALOG,+ AppExtensionTarget.ORDERS,+ AppExtensionTarget.CUSTOMERS,+ AppExtensionTarget.DISCOUNTS,+ AppExtensionTarget.TRANSLATIONS,+ AppExtensionTarget.PAGES,+ ]+ },+}++# Stores a values enum_type:field:is_optional for AppExtensions+EXTENSION_ENUM_MAP = [+ (AppExtensionView, "view", False),+ (AppExtensionType, "type", False),+ (AppExtensionTarget, "target", False),+ (AppExtensionOpenAs, "open_as", True),+]+# Stores a map of fields 'manifest-field:saleor-field+EXTENSION_FIELDS_MAP = [("openAs", "open_as")]diff --git a/saleor/app/installation_utils.py b/saleor/app/installation_utils.pyindex de720795a1..0bfe5468f1 100644--- a/saleor/app/installation_utils.py+++ b/saleor/app/installation_utils.py@@ -4,7 +4,7 @@ from django.contrib.sites.models import Sitefrom ..core.permissions import get_permission_namesfrom .manifest_validations import clean_manifest_datafrom .models import App, AppExtension, AppInstallation-from .types import AppType+from .types import AppExtensionOpenAs, AppTypeREQUEST_TIMEOUT = 25@@ -60,6 +60,7 @@ def install_app(view=extension_data.get("view"),type=extension_data.get("type"),target=extension_data.get("target"),+ open_as=extension_data.get("open_as") or AppExtensionOpenAs.POPUP,)extension.permissions.set(extension_data.get("permissions", []))diff --git a/saleor/app/manifest_validations.py b/saleor/app/manifest_validations.pyindex 02c0d458b2..b7b0df45a6 100644--- a/saleor/app/manifest_validations.py+++ b/saleor/app/manifest_validations.py@@ -1,3 +1,4 @@+import loggingfrom collections import defaultdictfrom typing import Dict, Iterable, List@@ -11,27 +12,18 @@ from ..core.permissions import (get_permissions_enum_list,split_permission_codename,)+from .const import (+ AVAILABLE_APP_EXTENSION_CONFIGS,+ EXTENSION_ENUM_MAP,+ EXTENSION_FIELDS_MAP,+)from .error_codes import AppErrorCode-from .types import AppExtensionTarget, AppExtensionType, AppExtensionView+from .types import AppExtensionOpenAsfrom .validators import AppURLValidator-T_ERRORS = Dict[str, List[ValidationError]]-+logger = logging.getLogger(__name__)-AVAILABLE_APP_EXTENSION_CONFIGS = {- AppExtensionType.DETAILS: {- AppExtensionView.PRODUCT: [- AppExtensionTarget.CREATE,- AppExtensionTarget.MORE_ACTIONS,- ]- },- AppExtensionType.OVERVIEW: {- AppExtensionView.PRODUCT: [- AppExtensionTarget.CREATE,- AppExtensionTarget.MORE_ACTIONS,- ]- },-}+T_ERRORS = Dict[str, List[ValidationError]]def _clean_app_url(url):@@ -39,6 +31,37 @@ def _clean_app_url(url):url_validator(url)+def clean_extension_url(extension: dict, manifest_data: dict):+ """Clean assigned extension url.++ Make sure that format of url is correct based on the rest of manifest fields.+ - url can start with '/' when one of these conditions is true:+ a) extension.open_as == APP_PAGE+ b) appUrl is provided+ - url cannot start with protocol when openAs == "APP_PAGE"+ """+ extension_url = extension["url"]+ open_as = extension.get("open_as") or AppExtensionOpenAs.POPUP+ if extension_url.startswith("/"):+ if open_as == AppExtensionOpenAs.APP_PAGE:+ pass+ elif manifest_data["appUrl"]:+ _clean_app_url(manifest_data["appUrl"])+ else:+ msg = (+ "Incorect relation between extension's openAs and url fields. "+ "APP_PAGE can be used only with relative url path."+ )+ logger.warning(msg, extra={"open_as": open_as, "url": extension_url})+ raise ValidationError(msg)+ elif open_as == AppExtensionOpenAs.APP_PAGE:+ msg = "Url cannot start with protocol when openAs == APP_PAGE"+ logger.warning(msg)+ raise ValidationError(msg)+ else:+ _clean_app_url(extension_url)++def clean_manifest_url(manifest_url):try:_clean_app_url(manifest_url)@@ -122,7 +145,6 @@ def _clean_extension_permissions(extension, app_permissions, errors):def _validate_configuration(extension, errors):-available_config_for_type = AVAILABLE_APP_EXTENSION_CONFIGS.get(extension["type"], {})@@ -145,13 +167,15 @@ def _validate_configuration(extension, errors):def clean_extensions(manifest_data, app_permissions, errors):extensions = manifest_data.get("extensions", [])- enum_map = [- (AppExtensionView, "view"),- (AppExtensionType, "type"),- (AppExtensionTarget, "target"),- ]for extension in extensions:- for extension_enum, key in enum_map:+ for manifest_field_name, expected_field_name in EXTENSION_FIELDS_MAP:+ if manifest_field_name in extension:+ extension[expected_field_name] = extension[manifest_field_name]+ del extension[manifest_field_name]++ for extension_enum, key, is_optional in EXTENSION_ENUM_MAP:+ if extension.get(key) is None and is_optional:+ continueif extension[key] in [code.upper() for code, _ in extension_enum.CHOICES]:extension[key] = getattr(extension_enum, extension[key])else:@@ -163,7 +187,7 @@ def clean_extensions(manifest_data, app_permissions, errors):)try:- _clean_app_url(extension["url"])+ clean_extension_url(extension, manifest_data)except (ValidationError, AttributeError):errors["extensions"].append(ValidationError(diff --git a/saleor/app/migrations/0006_auto_20220113_1108.py b/saleor/app/migrations/0006_auto_20220113_1108.pynew file mode 100644index 0000000000..183ebadfa5--- /dev/null+++ b/saleor/app/migrations/0006_auto_20220113_1108.py@@ -0,0 +1,58 @@+# Generated by Django 3.2.6 on 2022-01-13 11:08++from django.db import migrations, models+++class Migration(migrations.Migration):++ dependencies = [+ ("app", "0005_appextension"),+ ]++ operations = [+ migrations.AddField(+ model_name="appextension",+ name="open_as",+ field=models.CharField(+ choices=[("popup", "popup"), ("app_page", "app_page")],+ default="popup",+ max_length=128,+ ),+ ),+ migrations.AlterField(+ model_name="appextension",+ name="target",+ field=models.CharField(+ choices=[+ ("more_actions", "more_actions"),+ ("create", "create"),+ ("catalog", "catalog"),+ ("orders", "orders"),+ ("customers", "customers"),+ ("discounts", "discounts"),+ ("translations", "translations"),+ ("pages", "pages"),+ ],+ max_length=128,+ ),+ ),+ migrations.AlterField(+ model_name="appextension",+ name="type",+ field=models.CharField(+ choices=[+ ("overview", "overview"),+ ("details", "details"),+ ("navigation", "navigation"),+ ],+ max_length=128,+ ),+ ),+ migrations.AlterField(+ model_name="appextension",+ name="view",+ field=models.CharField(+ choices=[("product", "product"), ("all", "all")], max_length=128+ ),+ ),+ ]diff --git a/saleor/app/models.py b/saleor/app/models.pyindex 09eaf2f7e4..8d3e589485 100644--- a/saleor/app/models.py+++ b/saleor/app/models.py@@ -7,7 +7,13 @@ from oauthlib.common import generate_tokenfrom ..core.models import Job, ModelWithMetadatafrom ..core.permissions import AppPermissionfrom ..webhook.event_types import WebhookEventAsyncType, WebhookEventSyncType-from .types import AppExtensionTarget, AppExtensionType, AppExtensionView, AppType+from .types import (+ AppExtensionOpenAs,+ AppExtensionTarget,+ AppExtensionType,+ AppExtensionView,+ AppType,+)class AppQueryset(models.QuerySet):@@ -112,6 +118,11 @@ class AppExtension(models.Model):view = models.CharField(choices=AppExtensionView.CHOICES, max_length=128)type = models.CharField(choices=AppExtensionType.CHOICES, max_length=128)target = models.CharField(choices=AppExtensionTarget.CHOICES, max_length=128)+ open_as = models.CharField(+ choices=AppExtensionOpenAs.CHOICES,+ max_length=128,+ default=AppExtensionOpenAs.POPUP,+ )permissions = models.ManyToManyField(Permission,blank=True,diff --git a/saleor/app/types.py b/saleor/app/types.pyindex 7a4abf02ae..cc259c394a 100644--- a/saleor/app/types.py+++ b/saleor/app/types.py@@ -8,25 +8,42 @@ class AppType:class AppExtensionView:"""All available places where app's iframe can be mounted.- PRODUCT - app's iframe will be mounted in product section+ PRODUCT - app's extension will be mounted in product section+ ALL - app's extension will be mounted in all views"""PRODUCT = "product"+ ALL = "all"- CHOICES = [(PRODUCT, "product")]+ CHOICES = [(PRODUCT, "product"), (ALL, "all")]class AppExtensionType:"""All available types where app's iframe can be mounted.- OVERVIEW - app's iframe will be mounted on list view.- DETAILS - app's iframe will be mounted on detail view+ OVERVIEW - app's extension will be mounted on list view.+ DETAILS - app's extension will be mounted on detail view+ NAVIGATION - app's extension will be mounted on navigation"""OVERVIEW = "overview"DETAILS = "details"+ NAVIGATION = "navigation"- CHOICES = [(OVERVIEW, "overview"), (DETAILS, "details")]+ CHOICES = [(OVERVIEW, "overview"), (DETAILS, "details"), (NAVIGATION, "navigation")]+++class AppExtensionOpenAs:+ """All available ways of opening an app extension.++ POPUP - app's extension will be mounted as a popup window+ APP_PAGE - redirect to app's page+ """++ POPUP = "popup"+ APP_PAGE = "app_page"++ CHOICES = [(POPUP, "popup"), (APP_PAGE, "app_page")]class AppExtensionTarget:@@ -34,9 +51,30 @@ class AppExtensionTarget:MORE_ACTIONS - more actions buttonCREATE - create button+ CATALOG - catalog section on navigation bar+ ORDERS - orders section on navigation bar+ CUSTOMERS - customers section on navigation bar+ DISCOUNTS - discounts section on navigation bar+ TRANSLATION - translations section on navigation bar+ PAGES - pages section on navigation bar"""MORE_ACTIONS = "more_actions"CREATE = "create"-- CHOICES = [(MORE_ACTIONS, "more_actions"), (CREATE, "create")]+ CATALOG = "catalog"+ ORDERS = "orders"+ CUSTOMERS = "customers"+ DISCOUNTS = "discounts"+ TRANSLATIONS = "translations"+ PAGES = "pages"++ CHOICES = [+ (MORE_ACTIONS, "more_actions"),+ (CREATE, "create"),+ (CATALOG, "catalog"),+ (ORDERS, "orders"),+ (CUSTOMERS, "customers"),+ (DISCOUNTS, "discounts"),+ (TRANSLATIONS, "translations"),+ (PAGES, "pages"),+ ]diff --git a/saleor/graphql/app/enums.py b/saleor/graphql/app/enums.pyindex 819d43cbc3..9e7e32a580 100644--- a/saleor/graphql/app/enums.py+++ b/saleor/graphql/app/enums.py@@ -1,4 +1,10 @@-from ...app.types import AppExtensionTarget, AppExtensionType, AppExtensionView, AppType+from ...app.types import (+ AppExtensionOpenAs,+ AppExtensionTarget,+ AppExtensionType,+ AppExtensionView,+ AppType,+)from ..core.enums import to_enum@@ -26,3 +32,6 @@ AppExtensionViewEnum = to_enum(AppExtensionView, description=AppExtensionView.__AppExtensionTargetEnum = to_enum(AppExtensionTarget, description=AppExtensionTarget.__doc__)+AppExtensionOpenAsEnum = to_enum(+ AppExtensionOpenAs, description=AppExtensionOpenAs.__doc__+)diff --git a/saleor/graphql/app/filters.py b/saleor/graphql/app/filters.pyindex 1d876e2575..9dcbe600b3 100644--- a/saleor/graphql/app/filters.py+++ b/saleor/graphql/app/filters.py@@ -1,10 +1,17 @@import django_filtersfrom ...app import models-from ...app.types import AppExtensionTarget, AppExtensionType, AppExtensionView, AppType+from ...app.types import (+ AppExtensionOpenAs,+ AppExtensionTarget,+ AppExtensionType,+ AppExtensionView,+ AppType,+)from ..core.filters import EnumFilterfrom ..utils.filters import filter_by_query_paramfrom .enums import (+ AppExtensionOpenAsEnum,AppExtensionTargetEnum,AppExtensionTypeEnum,AppExtensionViewEnum,@@ -42,6 +49,12 @@ def filter_app_extension_target(qs, _, value):return qs+def filter_app_extension_open_as(qs, _, value):+ if value in [target for target, _ in AppExtensionOpenAs.CHOICES]:+ qs = qs.filter(open_as=value)+ return qs++class AppFilter(django_filters.FilterSet):type = EnumFilter(input_class=AppTypeEnum, method=filter_app_type)search = django_filters.CharFilter(method=filter_app_search)@@ -62,11 +75,10 @@ class AppExtensionFilter(django_filters.FilterSet):target = EnumFilter(input_class=AppExtensionTargetEnum, method=filter_app_extension_target)+ open_as = EnumFilter(+ input_class=AppExtensionOpenAsEnum, method=filter_app_extension_open_as+ )class Meta:model = models.AppExtension- fields = [- "view",- "type",- "target",- ]+ fields = ["view", "type", "target", "open_as"]diff --git a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.pyindex eafb2774d8..c152cb4dc8 100644--- a/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py+++ b/saleor/graphql/app/tests/mutations/test_app_fetch_manifest.py@@ -4,7 +4,12 @@ import pytestimport requestsfrom ....tests.utils import assert_no_permission, get_graphql_content-from ...enums import AppExtensionTargetEnum, AppExtensionTypeEnum, AppExtensionViewEnum+from ...enums import (+ AppExtensionOpenAsEnum,+ AppExtensionTargetEnum,+ AppExtensionTypeEnum,+ AppExtensionViewEnum,+)APP_FETCH_MANIFEST_MUTATION = """mutation AppFetchManifest($manifest_url: String!){@@ -30,6 +35,7 @@ mutation AppFetchManifest($manifest_url: String!){viewtypetarget+ openAspermissions{codename@@ -380,17 +386,71 @@ def test_app_fetch_manifest_extensions_incorrect_enum_values(@pytest.mark.parametrize(- "url",+ "url, open_as, app_url",+ [+ ("/app", AppExtensionOpenAsEnum.APP_PAGE.name, ""),+ ("/app", AppExtensionOpenAsEnum.APP_PAGE.name, "https://www.example.com/app"),+ ("/app", AppExtensionOpenAsEnum.POPUP.name, "https://www.example.com/app"),+ ],+)+def test_app_fetch_manifest_extensions_correct_url(+ url,+ open_as,+ app_url,+ app_manifest,+ monkeypatch,+ staff_api_client,+ permission_manage_apps,+):+ # given+ app_manifest["appUrl"] = app_url+ app_manifest["extensions"] = [+ {+ "permissions": ["MANAGE_PRODUCTS"],+ "label": "Create product with App",+ "url": url,+ "view": AppExtensionViewEnum.PRODUCT.name,+ "type": AppExtensionTypeEnum.OVERVIEW.name,+ "target": AppExtensionTargetEnum.CREATE.name,+ "openAs": open_as,+ }+ ]++ mocked_get_response = Mock()+ mocked_get_response.json.return_value = app_manifest++ monkeypatch.setattr(requests, "get", Mock(return_value=mocked_get_response))+ query = APP_FETCH_MANIFEST_MUTATION+ manifest_url = "http://localhost:3000/configuration/manifest"+ variables = {+ "manifest_url": manifest_url,+ }++ # when+ response = staff_api_client.post_graphql(+ query, variables=variables, permissions=[permission_manage_apps]+ )++ # then+ content = get_graphql_content(response)+ errors = content["data"]["appFetchManifest"]["errors"]+ assert len(errors) == 0+++ "url, open_as",[- "http:/127.0.0.1:8080/app",- "127.0.0.1:8080/app",- "",- "/app",- "www.example.com/app",+ ("http:/127.0.0.1:8080/app", AppExtensionOpenAsEnum.POPUP.name),+ ("127.0.0.1:8080/app", AppExtensionOpenAsEnum.POPUP.name),+ ("", AppExtensionOpenAsEnum.POPUP.name),+ ("/app", AppExtensionOpenAsEnum.POPUP.name),+ ("www.example.com/app", AppExtensionOpenAsEnum.POPUP.name),+ ("https://www.example.com/app", AppExtensionOpenAsEnum.APP_PAGE.name),+ ("http://www.example.com/app", AppExtensionOpenAsEnum.APP_PAGE.name),],)def test_app_fetch_manifest_extensions_incorrect_url(- url, app_manifest, monkeypatch, staff_api_client, permission_manage_apps+ url, open_as, app_manifest, monkeypatch, staff_api_client, permission_manage_apps):# givenapp_manifest["extensions"] = [@@ -401,6 +461,7 @@ def test_app_fetch_manifest_extensions_incorrect_url("view": AppExtensionViewEnum.PRODUCT.name,"type": AppExtensionTypeEnum.OVERVIEW.name,"target": AppExtensionTargetEnum.CREATE.name,+ "openAs": open_as,}]@@ -579,3 +640,4 @@ def test_app_fetch_manifest_with_extensions(assert extension["view"] == AppExtensionViewEnum.PRODUCT.nameassert extension["type"] == AppExtensionTypeEnum.OVERVIEW.nameassert extension["target"] == AppExtensionTargetEnum.CREATE.name+ assert extension["openAs"] == AppExtensionOpenAsEnum.POPUP.namediff --git a/saleor/graphql/app/tests/queries/test_app_extensions.py b/saleor/graphql/app/tests/queries/test_app_extensions.pyindex 872f5b2502..44ddb97b12 100644--- a/saleor/graphql/app/tests/queries/test_app_extensions.py+++ b/saleor/graphql/app/tests/queries/test_app_extensions.py@@ -1,10 +1,20 @@import pytestfrom .....app.models import AppExtension-from .....app.types import AppExtensionTarget, AppExtensionType, AppExtensionView+from .....app.types import (+ AppExtensionOpenAs,+ AppExtensionTarget,+ AppExtensionType,+ AppExtensionView,+)from .....core.jwt import jwt_decodefrom ....tests.utils import assert_no_permission, get_graphql_content-from ...enums import AppExtensionTargetEnum, AppExtensionTypeEnum, AppExtensionViewEnum+from ...enums import (+ AppExtensionOpenAsEnum,+ AppExtensionTargetEnum,+ AppExtensionTypeEnum,+ AppExtensionViewEnum,+)QUERY_APP_EXTENSIONS = """query ($filter: AppExtensionFilterInput){@@ -156,6 +166,15 @@ def test_app_extensions_user_not_staff(},1,),+ ({"openAs": AppExtensionOpenAsEnum.APP_PAGE.name}, 1),+ ({"openAs": AppExtensionOpenAsEnum.POPUP.name}, 2),+ (+ {+ "openAs": AppExtensionOpenAsEnum.POPUP.name,+ "type": AppExtensionTypeEnum.DETAILS.name,+ },+ 1,+ ),],)def test_app_extensions_with_filter(@@ -171,6 +190,7 @@ def test_app_extensions_with_filter(view=AppExtensionView.PRODUCT,type=AppExtensionType.OVERVIEW,target=AppExtensionTarget.MORE_ACTIONS,+ open_as=AppExtensionOpenAs.APP_PAGE,),AppExtension(app=app,@@ -179,6 +199,7 @@ def test_app_extensions_with_filter(view=AppExtensionView.PRODUCT,type=AppExtensionType.DETAILS,target=AppExtensionTarget.MORE_ACTIONS,+ open_as=AppExtensionOpenAs.POPUP,),AppExtension(app=app,diff --git a/saleor/graphql/app/types.py b/saleor/graphql/app/types.pyindex 9fc312a363..626a3a6251 100644--- a/saleor/graphql/app/types.py+++ b/saleor/graphql/app/types.py@@ -1,9 +1,11 @@from typing import List+from urllib.parse import urljoin, urlparseimport graphenefrom graphene_federation import keyfrom ...app import models+from ...app.types import AppExtensionOpenAsfrom ...core.exceptions import PermissionDeniedfrom ...core.permissions import AppPermissionfrom ..core.connection import CountableConnection, CountableDjangoObjectType@@ -17,6 +19,7 @@ from ..utils import format_permissions_for_display, get_user_or_app_from_contextfrom ..webhook.types import Webhookfrom .dataloaders import AppByIdLoader, AppExtensionByAppIdLoaderfrom .enums import (+ AppExtensionOpenAsEnum,AppExtensionTargetEnum,AppExtensionTypeEnum,AppExtensionViewEnum,@@ -51,6 +54,31 @@ class AppManifestExtension(graphene.ObjectType):target = AppExtensionTargetEnum(description="Place where extension's iframe will be mounted.", required=True)+ open_as = AppExtensionOpenAsEnum(+ description="Type of way how app extension will be opened.", required=True+ )++ @staticmethod+ def resolve_open_as(root, info):+ return root.get("open_as") or AppExtensionOpenAs.POPUP++ @staticmethod+ def resolve_url(root, info):+ """Return an extension url.++ Apply url stitching when these 3 conditions are met:+ - url starts with /+ - openAs == "POPUP"+ - appUrl is defined+ """+ open_as = root.get("open_as", AppExtensionOpenAs.POPUP)+ app_url = root["app_url"]+ url = root["url"]+ if url.startswith("/") and app_url and open_as == AppExtensionOpenAs.POPUP:+ parsed_url = urlparse(app_url)+ new_path = urljoin(parsed_url.path, url[1:])+ return parsed_url._replace(path=new_path).geturl()+ return urlclass AppExtension(AppManifestExtension, CountableDjangoObjectType):@@ -64,6 +92,23 @@ class AppExtension(AppManifestExtension, CountableDjangoObjectType):interfaces = [graphene.relay.Node]model = models.AppExtension+ @staticmethod+ def resolve_url(root, info):+ return (+ AppByIdLoader(info.context)+ .load(root.app_id)+ .then(+ lambda app: AppManifestExtension.resolve_url(+ {"open_as": root.open_as, "app_url": app.app_url, "url": root.url},+ info,+ )+ )+ )++ @staticmethod+ def resolve_open_as(root, info):+ return root.open_as+@staticmethoddef resolve_app(root, info):app_id = None@@ -114,6 +159,12 @@ class Manifest(graphene.ObjectType):class Meta:description = "The manifest definition."+ @staticmethod+ def resolve_extensions(root, info):+ for extension in root.extensions:+ extension["app_url"] = root.app_url+ return root.extensions+class AppToken(CountableDjangoObjectType):name = graphene.String(description="Name of the authenticated token.")diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex f3334ca969..05647521c7 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -301,6 +301,7 @@ type AppExtension implements Node {view: AppExtensionViewEnum!type: AppExtensionTypeEnum!target: AppExtensionTargetEnum!+ openAs: AppExtensionOpenAsEnum!permissions: [Permission!]!accessToken: String}@@ -320,20 +321,34 @@ input AppExtensionFilterInput {view: AppExtensionViewEnumtype: AppExtensionTypeEnumtarget: AppExtensionTargetEnum+ openAs: AppExtensionOpenAsEnum+}++enum AppExtensionOpenAsEnum {+ POPUP+ APP_PAGE}enum AppExtensionTargetEnum {MORE_ACTIONSCREATE+ CATALOG+ ORDERS+ CUSTOMERS+ DISCOUNTS+ TRANSLATIONS+ PAGES}enum AppExtensionTypeEnum {OVERVIEWDETAILS+ NAVIGATION}enum AppExtensionViewEnum {PRODUCT+ ALL}type AppFetchManifest {@@ -383,6 +398,7 @@ type AppManifestExtension {view: AppExtensionViewEnum!type: AppExtensionTypeEnum!target: AppExtensionTargetEnum!+ openAs: AppExtensionOpenAsEnum!}type AppRetryInstall {