-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QA-15066: add unpublish action on vanity urls (#221)
* QA-15066: add unpublish action on vanity urls * fix publication check failing after moving a url
- Loading branch information
1 parent
4235518
commit 8a267b5
Showing
10 changed files
with
211 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/javascript/components/actions/UnpublishVanityAction.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React, {useContext, useEffect, useState} from 'react'; | ||
import {ComponentRendererContext} from '@jahia/ui-extender'; | ||
import * as PropTypes from 'prop-types'; | ||
import {allNotPublishedAndMarkedForDeletion, atLeastOneNotPublished, contentIsVisibleInLive} from '../Utils/Utils'; | ||
import {useApolloClient, useQuery} from '@apollo/client'; | ||
import {CheckPublishPermissions, GetPublicationStatus} from '~/components/gqlQueries'; | ||
import {Publication} from '~/components/Publication/Publication'; | ||
|
||
export const UnpublishVanityAction = ({render: Render, urlPairs, path, buttonLabel, ...otherProps}) => { | ||
const componentRenderer = useContext(ComponentRendererContext); | ||
|
||
const {data, loading, error} = useQuery(CheckPublishPermissions, {variables: {path: path}}); | ||
|
||
const closeDialog = () => { | ||
componentRenderer.destroy('PublishVanityDialog'); | ||
}; | ||
|
||
const openModal = () => { | ||
componentRenderer.render( | ||
'PublishVanityDialog', | ||
Publication, | ||
{ | ||
...otherProps, | ||
urlPairs: urlPairs, | ||
isOpen: true, | ||
onClose: closeDialog | ||
}); | ||
}; | ||
|
||
const openPublicationWorkflow = () => { | ||
const uuids = urlPairs.map(urlPair => urlPair.uuid); | ||
window.authoringApi.openPublicationWorkflow( | ||
uuids, | ||
false, // Not publishing all subNodes (AKA sub pages) | ||
false, // Not publishing all language | ||
false // Not unpublish action | ||
); | ||
}; | ||
|
||
const [isVisibleInLive, setIsVisibleInLive] = useState(false); | ||
const client = useApolloClient(); | ||
|
||
useEffect(() => { | ||
const fetchPublicationData = async () => { | ||
const data = await Promise.all( | ||
urlPairs.map(async urlPair => { | ||
const {data} = await client.query({ | ||
query: GetPublicationStatus, | ||
variables: {path: urlPair.default.targetNode.path, language: urlPair.default.language} | ||
}); | ||
console.debug(data); | ||
return data.jcr.nodeByPath.aggregatedPublicationInfo; | ||
}) | ||
); | ||
setIsVisibleInLive(data.every(contentIsVisibleInLive)); | ||
}; | ||
|
||
fetchPublicationData(); | ||
}, [client, urlPairs, urlPairs.length]); | ||
|
||
if (error) { | ||
console.log('Error while fetching publish permissions'); | ||
console.debug(error); | ||
return null; | ||
} | ||
|
||
if (loading || !data) { | ||
return null; | ||
} | ||
|
||
let requestPublicationLabel = null; | ||
let action = openModal; | ||
if (!data.jcr.nodeByPath.hasPublishPermission && data.jcr.nodeByPath.hasPublicationStartPermission) { | ||
requestPublicationLabel = 'site-settings-seo:label.actions.requestPublication'; | ||
action = openPublicationWorkflow; | ||
} | ||
|
||
const shouldBeVisible = !allNotPublishedAndMarkedForDeletion(urlPairs) && atLeastOneNotPublished(urlPairs) && isVisibleInLive; | ||
return ( | ||
<> | ||
<Render | ||
{...otherProps} | ||
buttonLabel={requestPublicationLabel || buttonLabel} | ||
isVisible={shouldBeVisible} | ||
onClick={action}/> | ||
</> | ||
); | ||
}; | ||
|
||
UnpublishVanityAction.propTypes = { | ||
render: PropTypes.elementType.isRequired, | ||
urlPairs: PropTypes.array.isRequired, | ||
path: PropTypes.string.isRequired, | ||
buttonLabel: PropTypes.string.isRequired | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { | ||
publishAndWaitJobEnding, | ||
createSite, | ||
deleteSite, | ||
addVanityUrl, | ||
createUser, | ||
deleteUser, | ||
grantRoles, | ||
deleteNode, | ||
unpublishNode, | ||
} from '@jahia/cypress' | ||
import { VanityUrlsPage } from '../../page-object/vanityUrls.page' | ||
|
||
describe('Test actions of vanity urls', () => { | ||
const siteKey = 'siteActionCheck' | ||
const sitePath = '/sites/' + siteKey | ||
const homePath = sitePath + '/home' | ||
const pageName = 'basic-page' | ||
const pagePath = homePath + '/' + pageName | ||
const langEN = 'en' | ||
const siteConfig = { | ||
languages: langEN, | ||
templateSet: 'site-settings-seo-test-module', | ||
serverName: 'localhost', | ||
locale: langEN, | ||
} | ||
|
||
let pageUuid = '' | ||
|
||
const createPage = (parent: string, name: string, template: string, lang: string) => { | ||
return cy.apollo({ | ||
variables: { | ||
parentPathOrId: parent, | ||
name: name, | ||
template: template, | ||
language: lang, | ||
}, | ||
mutationFile: 'graphql/jcrAddPage.graphql', | ||
}) | ||
} | ||
|
||
before('Create test data', function () { | ||
createSite(siteKey, siteConfig) | ||
|
||
cy.log('Add user to check permissions') | ||
createUser('editorUser', 'password') | ||
grantRoles(sitePath, ['editor'], 'editorUser', 'USER') | ||
}) | ||
|
||
beforeEach(() => { | ||
createPage(homePath, `${pageName}-a`, 'withoutseo', langEN).then(({ data }) => { | ||
pageUuid = data.jcr.addNode.uuid | ||
addVanityUrl(`${pagePath}-a`, 'en', '/vanityOnPageA') | ||
}) | ||
publishAndWaitJobEnding(homePath) | ||
}) | ||
|
||
afterEach(() => { | ||
deleteNode(`${homePath}/${pageName}-a`) | ||
publishAndWaitJobEnding(homePath) | ||
}) | ||
|
||
after('Clear test data', function () { | ||
deleteSite(siteKey) | ||
deleteUser('editorUser') | ||
}) | ||
|
||
it('Should unpublish action enabled in menu for for content existing in live', function () { | ||
cy.login('editorUser', 'password') | ||
|
||
const vanityUrlsPage = VanityUrlsPage.visit(siteKey, 'en') | ||
const pageCard = vanityUrlsPage.getPagesWithVanityUrl().getPageCard(pageUuid) | ||
pageCard.open() | ||
|
||
const vanityUrlRow = pageCard.getStagingVanityUrls().getVanityUrlRow('/vanityOnPageA') | ||
|
||
const menu = vanityUrlRow.openContextualMenu() | ||
menu.getUnpublishButton().invoke('attr', 'aria-disabled').should('eq', 'false') | ||
cy.logout() | ||
}) | ||
|
||
it('Should unpublish action disabled in menu for for content not existing in live', function () { | ||
cy.login('editorUser', 'password') | ||
unpublishNode(`${homePath}/${pageName}-a`, langEN) | ||
|
||
const vanityUrlsPage = VanityUrlsPage.visit(siteKey, 'en') | ||
const pageCard = vanityUrlsPage.getPagesWithVanityUrl().getPageCard(pageUuid) | ||
pageCard.open() | ||
|
||
const vanityUrlRow = pageCard.getStagingVanityUrls().getVanityUrlRow('/vanityOnPageA') | ||
|
||
const menu = vanityUrlRow.openContextualMenu() | ||
menu.getUnpublishButton().invoke('attr', 'aria-disabled').should('eq', 'true') | ||
cy.logout() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters