Skip to content

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

Add unpublish mutation

Adam Janik5ba817d0891c
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24172b6d66..62baf8dfaf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Add mutation for bulk delete order lines - #3935 by @akjanik
- Fix dashboard 1.0 missing logo and missing back arrow on collections - #3958 by @NyanKiyoshi
+- Add mutations for (un)publish multiple pages - #3954 by @akjanik
## 2.5.0
diff --git a/saleor/graphql/page/bulk_mutations.py b/saleor/graphql/page/bulk_mutations.py
index ea2222cd22..b3a15d2fb9 100644
--- a/saleor/graphql/page/bulk_mutations.py
+++ b/saleor/graphql/page/bulk_mutations.py
@@ -34,3 +34,19 @@ class PageBulkPublish(ModelBulkPublishMutation):
@classmethod
def user_is_allowed(cls, user, input):
return user.has_perm('page.manage_pages')
+
+
+class PageBulkUnpublish(PageBulkPublish):
+ class Arguments:
+ ids = graphene.List(
+ graphene.ID,
+ required=True,
+ description='List of page IDs to unpublish.')
+
+ class Meta:
+ description = 'Unpublish pages.'
+ model = models.Page
+
+ @classmethod
+ def bulk_action(cls, queryset):
+ queryset.update(is_published=False)
diff --git a/saleor/graphql/page/schema.py b/saleor/graphql/page/schema.py
index a69942895a..243f2ee2df 100644
--- a/saleor/graphql/page/schema.py
+++ b/saleor/graphql/page/schema.py
@@ -3,7 +3,7 @@ import graphene
from ..core.fields import PrefetchingConnectionField
from ..descriptions import DESCRIPTIONS
from ..translations.mutations import PageTranslate
-from .bulk_mutations import PageBulkDelete, PageBulkPublish
+from .bulk_mutations import PageBulkDelete, PageBulkPublish, PageBulkUnpublish
from .mutations import PageCreate, PageDelete, PageUpdate
from .resolvers import resolve_page, resolve_pages
from .types import Page
@@ -30,5 +30,6 @@ class PageMutations(graphene.ObjectType):
page_delete = PageDelete.Field()
page_bulk_delete = PageBulkDelete.Field()
page_bulk_publish = PageBulkPublish.Field()
+ page_bulk_unpublish = PageBulkUnpublish.Field()
page_update = PageUpdate.Field()
page_translate = PageTranslate.Field()
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 4dd7079fa3..ba88e440b5 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -41,7 +41,7 @@ input AddressInput {
city: String
cityArea: String
postalCode: String
- country: String!
+ country: String
countryArea: String
phone: String
}
@@ -796,8 +796,8 @@ type DraftOrderLinesBulkDelete {
type DraftOrderLinesCreate {
errors: [Error!]
- order: Order!
- orderLines: [OrderLine!]!
+ order: Order
+ orderLines: [OrderLine!]
}
type DraftOrderUpdate {
@@ -1149,6 +1149,8 @@ type Mutations {
pageCreate(input: PageInput!): PageCreate
pageDelete(id: ID!): PageDelete
pageBulkDelete(ids: [ID]!): PageBulkDelete
+ pageBulkPublish(ids: [ID]!): PageBulkPublish
+ pageBulkUnpublish(ids: [ID]!): PageBulkUnpublish
pageUpdate(id: ID!, input: PageInput!): PageUpdate
pageTranslate(id: ID!, input: PageTranslationInput!, languageCode: LanguageCodeEnum!): PageTranslate
draftOrderComplete(id: ID!): DraftOrderComplete
@@ -1198,7 +1200,7 @@ type Mutations {
tokenCreate(email: String!, password: String!): CreateToken
tokenRefresh(token: String!): Refresh
tokenVerify(token: String!): VerifyToken
- checkoutBillingAddressUpdate(billingAddress: AddressInput, checkoutId: ID): CheckoutBillingAddressUpdate
+ checkoutBillingAddressUpdate(billingAddress: AddressInput!, checkoutId: ID): CheckoutBillingAddressUpdate
checkoutComplete(checkoutId: ID!): CheckoutComplete
checkoutCreate(input: CheckoutCreateInput!): CheckoutCreate
checkoutCustomerAttach(checkoutId: ID!, customerId: ID!): CheckoutCustomerAttach
@@ -1208,7 +1210,7 @@ type Mutations {
checkoutLinesAdd(checkoutId: ID!, lines: [CheckoutLineInput]!): CheckoutLinesAdd
checkoutLinesUpdate(checkoutId: ID!, lines: [CheckoutLineInput]!): CheckoutLinesUpdate
checkoutPaymentCreate(checkoutId: ID!, input: PaymentInput!): CheckoutPaymentCreate
- checkoutShippingAddressUpdate(checkoutId: ID, shippingAddress: AddressInput): CheckoutShippingAddressUpdate
+ checkoutShippingAddressUpdate(checkoutId: ID, shippingAddress: AddressInput!): CheckoutShippingAddressUpdate
checkoutShippingMethodUpdate(checkoutId: ID, shippingMethodId: ID!): CheckoutShippingMethodUpdate
checkoutUpdateVoucher(checkoutId: ID!, voucherCode: String): CheckoutUpdateVoucher
passwordReset(email: String!): PasswordReset
@@ -1483,6 +1485,16 @@ type PageBulkDelete {
count: Int!
}
+type PageBulkPublish {
+ errors: [Error!]
+ count: Int!
+}
+
+type PageBulkUnpublish {
+ errors: [Error!]
+ count: Int!
+}
+
type PageCountableConnection {
pageInfo: PageInfo!
edges: [PageCountableEdge!]!
diff --git a/tests/api/test_page.py b/tests/api/test_page.py
index 8196805c36..1a45beeae6 100644
--- a/tests/api/test_page.py
+++ b/tests/api/test_page.py
@@ -235,3 +235,27 @@ def test_bulk_publish(
page.refresh_from_db()
assert content['data']['pageBulkPublish']['count'] == len(page_list)
assert all(page.is_published for page in page_list)
+
+
+def test_bulk_unpublish(
+ staff_api_client, page_list,
+ permission_manage_pages):
+ assert all(page.is_published for page in page_list)
+
+ query = """
+ mutation unPublishManyPages($ids: [ID]!) {
+ pageBulkUnpublish(ids: $ids) {
+ count
+ }
+ }
+ """
+ variables = {'ids': [
+ graphene.Node.to_global_id('Page', page.id)
+ for page in page_list]}
+ response = staff_api_client.post_graphql(
+ query, variables, permissions=[permission_manage_pages])
+ content = get_graphql_content(response)
+ for page in page_list:
+ page.refresh_from_db()
+ assert content['data']['pageBulkUnpublish']['count'] == len(page_list)
+ assert not any(page.is_published for page in page_list)