Skip to content

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

Add to app input field activate_after_installation

Maciej Korycinskib8f88543fdb0
diff --git a/saleor/app/installation_utils.py b/saleor/app/installation_utils.py
index b08ccf6a8f..2faee6b4c4 100644
--- a/saleor/app/installation_utils.py
+++ b/saleor/app/installation_utils.py
@@ -27,7 +27,11 @@ def validate_manifest_fields(manifest_data):
@transaction.atomic
-def install_app(manifest_url: str, required_permissions: Iterable[Permission]):
+def install_app(
+ manifest_url: str,
+ required_permissions: Iterable[Permission],
+ activate: bool = False,
+):
manifest_data = requests.get(manifest_url, timeout=REQUEST_TIMEOUT).json()
validate_manifest_fields(manifest_data)
@@ -37,6 +41,7 @@ def install_app(manifest_url: str, required_permissions: Iterable[Permission]):
app = App.objects.create(
name=manifest_data.get("name"),
+ is_active=activate,
identificator=manifest_data.get("identificator"),
about_app=manifest_data.get("about_app"),
data_privacy=manifest_data.get("data_privacy"),
diff --git a/saleor/app/tasks.py b/saleor/app/tasks.py
index f362566b0a..8f656195c2 100644
--- a/saleor/app/tasks.py
+++ b/saleor/app/tasks.py
@@ -8,10 +8,10 @@ from .models import AppJob
@celeryconf.app.task
-def install_app_task(job_id):
+def install_app_task(job_id, activate=False):
app_job = AppJob.objects.get(id=job_id)
try:
- install_app(app_job.manifest_url, app_job.permissions.all())
+ install_app(app_job.manifest_url, app_job.permissions.all(), activate=activate)
app_job.delete()
return
except ValidationError:
diff --git a/saleor/graphql/app/mutations.py b/saleor/graphql/app/mutations.py
index 688bb991f1..76450874e6 100644
--- a/saleor/graphql/app/mutations.py
+++ b/saleor/graphql/app/mutations.py
@@ -210,6 +210,7 @@ class AppDelete(ModelDeleteMutation):
class InstallAppInput(graphene.InputObjectType):
name = graphene.String(description="Name of the app to register.")
manifest_url = graphene.String(description="Url to app's manifest in JSON format.")
+ activate_after_installation = graphene.Boolean(default_value=True, required=False)
permissions = graphene.List(
PermissionEnum,
description="List of permission code names to assign to this app.",
@@ -256,4 +257,5 @@ class InstallApp(ModelMutation):
@classmethod
def post_save_action(cls, info, instance, cleaned_input):
- install_app_task.delay(instance.pk)
+ activate_after_installation = cleaned_input["activate_after_installation"]
+ install_app_task.delay(instance.pk, activate_after_installation)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 56925a6b7a..a08f1e12c9 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -1962,6 +1962,7 @@ type InstallApp {
input InstallAppInput {
name: String
manifestUrl: String
+ activateAfterInstallation: Boolean = true
permissions: [PermissionEnum]
}
diff --git a/tests/api/app/mutations/test_install_app.py b/tests/api/app/mutations/test_install_app.py
index f9f55408dc..2ff131cc3f 100644
--- a/tests/api/app/mutations/test_install_app.py
+++ b/tests/api/app/mutations/test_install_app.py
@@ -53,7 +53,7 @@ def test_install_app_mutation(
assert int(app_job_data["id"]) == app_job.id
assert app_job_data["status"] == JobStatus.PENDING.upper()
assert app_job_data["manifestUrl"] == app_job.manifest_url
- mocked_task.assert_called_with(app_job.pk)
+ mocked_task.assert_called_with(app_job.pk, True)
def test_install_app_mutation_by_app(
@@ -79,7 +79,7 @@ def test_install_app_mutation_by_app(
assert int(app_job_data["id"]) == app_job.id
assert app_job_data["status"] == JobStatus.PENDING.upper()
assert app_job_data["manifestUrl"] == app_job.manifest_url
- mocked_task.assert_called_with(app_job.pk)
+ mocked_task.assert_called_with(app_job.pk, True)
def test_app_install_mutation_out_of_scope_permissions(