Skip to content

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

Don't require all app permissions to app retry installation

IKarbowiak4ecf25b9395f
diff --git a/saleor/graphql/app/mutations.py b/saleor/graphql/app/mutations.py
index 0fbe32413c..d7b3e3f6eb 100644
--- a/saleor/graphql/app/mutations.py
+++ b/saleor/graphql/app/mutations.py
@@ -328,15 +328,6 @@ class AppRetryInstall(ModelMutation):
@classmethod
def clean_instance(cls, info, instance):
- requestor = get_user_or_app_from_context(info.context)
- permissions = instance.permissions.all()
- if not requestor_is_superuser(requestor) and not requestor.has_perms(
- permissions
- ):
- msg = "You don't have enough permission to perform this action."
- code = AppErrorCode.OUT_OF_SCOPE_APP.value
- raise ValidationError({"id": ValidationError(msg, code=code)})
-
if instance.status != JobStatus.FAILED:
msg = "Cannot retry installation with different status than failed."
code = AppErrorCode.INVALID_STATUS.value
diff --git a/saleor/graphql/app/tests/mutations/test_app_retry_install.py b/saleor/graphql/app/tests/mutations/test_app_retry_install.py
index 99f4bb8d62..b8b160b011 100644
--- a/saleor/graphql/app/tests/mutations/test_app_retry_install.py
+++ b/saleor/graphql/app/tests/mutations/test_app_retry_install.py
@@ -93,17 +93,23 @@ def test_retry_install_app_mutation_by_app(
mocked_task.assert_called_with(app_installation.pk, False)
-def test_retry_install_app_mutation_missing_required_permissions(
+def test_retry_install_app_mutation_app_has_more_permission_than_user_requestor(
permission_manage_apps,
staff_api_client,
staff_user,
app_installation,
permission_manage_orders,
+ monkeypatch,
):
app_installation.status = JobStatus.FAILED
app_installation.permissions.add(permission_manage_orders)
app_installation.save()
+ mocked_task = Mock()
+ monkeypatch.setattr(
+ "saleor.graphql.app.mutations.install_app_task.delay", mocked_task
+ )
+
query = RETRY_INSTALL_APP_MUTATION
staff_user.user_permissions.set([permission_manage_apps])
@@ -117,19 +123,33 @@ def test_retry_install_app_mutation_missing_required_permissions(
data = content["data"]["appRetryInstall"]
errors = data["appErrors"]
- assert not data["appInstallation"]
- assert len(errors) == 1
- error = errors[0]
- assert error["field"] == "id"
- assert error["code"] == AppErrorCode.OUT_OF_SCOPE_APP.name
+ assert not errors
+ app_installation = AppInstallation.objects.get()
+ app_installation_data = content["data"]["appRetryInstall"]["appInstallation"]
+ _, app_id = graphene.Node.from_global_id(app_installation_data["id"])
+ assert int(app_id) == app_installation.id
+ assert app_installation_data["status"] == JobStatus.PENDING.upper()
+ assert app_installation_data["manifestUrl"] == app_installation.manifest_url
+ mocked_task.assert_called_with(app_installation.pk, True)
-def test_retry_install_app_mutation_by_app_missing_required_permissions(
- permission_manage_apps, app_api_client, app_installation, permission_manage_orders
+
+def test_retry_install_app_mutation_app_has_more_permission_than_app_requestor(
+ permission_manage_apps,
+ app_api_client,
+ app_installation,
+ permission_manage_orders,
+ monkeypatch,
):
app_installation.status = JobStatus.FAILED
app_installation.permissions.add(permission_manage_orders)
app_installation.save()
+
+ mocked_task = Mock()
+ monkeypatch.setattr(
+ "saleor.graphql.app.mutations.install_app_task.delay", mocked_task
+ )
+
query = RETRY_INSTALL_APP_MUTATION
app_api_client.app.permissions.set([permission_manage_apps])
id = graphene.Node.to_global_id("AppInstallation", app_installation.id)
@@ -142,11 +162,15 @@ def test_retry_install_app_mutation_by_app_missing_required_permissions(
data = content["data"]["appRetryInstall"]
errors = data["appErrors"]
- assert not data["appInstallation"]
- assert len(errors) == 1
- error = errors[0]
- assert error["field"] == "id"
- assert error["code"] == AppErrorCode.OUT_OF_SCOPE_APP.name
+ assert not errors
+
+ app_installation = AppInstallation.objects.get()
+ app_installation_data = content["data"]["appRetryInstall"]["appInstallation"]
+ _, app_id = graphene.Node.from_global_id(app_installation_data["id"])
+ assert int(app_id) == app_installation.id
+ assert app_installation_data["status"] == JobStatus.PENDING.upper()
+ assert app_installation_data["manifestUrl"] == app_installation.manifest_url
+ mocked_task.assert_called_with(app_installation.pk, True)
def test_cannot_retry_installation_if_status_is_different_than_failed(