Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add unpublish mutation
Adam Janik5ba817d0891c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 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.0diff --git a/saleor/graphql/page/bulk_mutations.py b/saleor/graphql/page/bulk_mutations.pyindex ea2222cd22..b3a15d2fb9 100644--- a/saleor/graphql/page/bulk_mutations.py+++ b/saleor/graphql/page/bulk_mutations.py@@ -34,3 +34,19 @@ class PageBulkPublish(ModelBulkPublishMutation):@classmethoddef 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.pyindex a69942895a..243f2ee2df 100644--- a/saleor/graphql/page/schema.py+++ b/saleor/graphql/page/schema.py@@ -3,7 +3,7 @@ import graphenefrom ..core.fields import PrefetchingConnectionFieldfrom ..descriptions import DESCRIPTIONSfrom ..translations.mutations import PageTranslate-from .bulk_mutations import PageBulkDelete, PageBulkPublish+from .bulk_mutations import PageBulkDelete, PageBulkPublish, PageBulkUnpublishfrom .mutations import PageCreate, PageDelete, PageUpdatefrom .resolvers import resolve_page, resolve_pagesfrom .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.graphqlindex 4dd7079fa3..ba88e440b5 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -41,7 +41,7 @@ input AddressInput {city: StringcityArea: StringpostalCode: String- country: String!+ country: StringcountryArea: Stringphone: 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!): PageCreatepageDelete(id: ID!): PageDeletepageBulkDelete(ids: [ID]!): PageBulkDelete+ pageBulkPublish(ids: [ID]!): PageBulkPublish+ pageBulkUnpublish(ids: [ID]!): PageBulkUnpublishpageUpdate(id: ID!, input: PageInput!): PageUpdatepageTranslate(id: ID!, input: PageTranslationInput!, languageCode: LanguageCodeEnum!): PageTranslatedraftOrderComplete(id: ID!): DraftOrderComplete@@ -1198,7 +1200,7 @@ type Mutations {tokenCreate(email: String!, password: String!): CreateTokentokenRefresh(token: String!): RefreshtokenVerify(token: String!): VerifyToken- checkoutBillingAddressUpdate(billingAddress: AddressInput, checkoutId: ID): CheckoutBillingAddressUpdate+ checkoutBillingAddressUpdate(billingAddress: AddressInput!, checkoutId: ID): CheckoutBillingAddressUpdatecheckoutComplete(checkoutId: ID!): CheckoutCompletecheckoutCreate(input: CheckoutCreateInput!): CheckoutCreatecheckoutCustomerAttach(checkoutId: ID!, customerId: ID!): CheckoutCustomerAttach@@ -1208,7 +1210,7 @@ type Mutations {checkoutLinesAdd(checkoutId: ID!, lines: [CheckoutLineInput]!): CheckoutLinesAddcheckoutLinesUpdate(checkoutId: ID!, lines: [CheckoutLineInput]!): CheckoutLinesUpdatecheckoutPaymentCreate(checkoutId: ID!, input: PaymentInput!): CheckoutPaymentCreate- checkoutShippingAddressUpdate(checkoutId: ID, shippingAddress: AddressInput): CheckoutShippingAddressUpdate+ checkoutShippingAddressUpdate(checkoutId: ID, shippingAddress: AddressInput!): CheckoutShippingAddressUpdatecheckoutShippingMethodUpdate(checkoutId: ID, shippingMethodId: ID!): CheckoutShippingMethodUpdatecheckoutUpdateVoucher(checkoutId: ID!, voucherCode: String): CheckoutUpdateVoucherpasswordReset(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.pyindex 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)