Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow to trash pages with subpages
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Jun 27, 2023
commit cdea1717d56474f94ea1662c6e23fb6c7c59e181
47 changes: 47 additions & 0 deletions cypress/e2e/page-list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,51 @@ describe('Page list', function() {
})
})
})

describe('Page trash', function() {
it('allows to trash and restore page with subpage and attachment', function() {
cy.visit('/apps/collectives/Our%20Garden/Day%201')

// Insert attachment
cy.intercept({ method: 'POST', url: '**/text/attachment/upload*' }).as('attachmentUpload')
cy.get('input[data-text-el="attachment-file-input"]')
.selectFile('cypress/fixtures/test.png', { force: true })
cy.wait('@attachmentUpload')

// Trash page
cy.contains('.page-list .app-content-list-item', 'Day 1')
.find('.action-item__menutoggle')
.click({ force: true })
cy.get('button.action-button')
.contains('Delete page')
.click()
cy.get('.page-list .app-content-list-item')
.should('not.contain', 'Day 1')

// Restore page
cy.get('#page-trash')
.click()
cy.contains('#page-trash__content .app-content-list-item', 'Day 1')
.find('.action-item__menutoggle')
.click({ force: true })
cy.get('button.action-button')
.contains('Restore')
.click()
cy.get('#page-trash')
.click()
cy.get('#page-trash__content .app-content-list-item')
.should('not.exist')

cy.visit('/apps/collectives/Our%20Garden/Day%201')
if (Cypress.env('ncVersion') === 'stable25') {
cy.getEditor()
.find('img.image__main')
.should('be.visible')
} else {
cy.getReadOnlyEditor()
.find('img.image__main')
.should('be.visible')
}
})
})
})
5 changes: 0 additions & 5 deletions lib/Service/PageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -843,11 +843,6 @@ public function trash(int $collectiveId, int $parentId, int $id, string $userId)

try {
if (NodeHelper::isIndexPage($file)) {
// Don't delete if still page has subpages
if (NodeHelper::indexPageHasOtherContent($file)) {
throw new NotPermittedException('Failed to delete page ' . $id . ' with subpages');
}

// Delete folder if it's an index page without subpages
$file->getParent()->delete();
} else {
Expand Down
18 changes: 4 additions & 14 deletions src/components/Page/PageActionMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,9 @@
</NcActionButton>
<NcActionButton v-if="currentCollectiveCanEdit && !isLandingPage"
:close-after-click="true"
:disabled="hasSubpages"
@click="deletePage(parentId, pageId)">
<template #icon>
<DeleteOffIcon v-if="hasSubpages" :size="20" />
<DeleteIcon v-else :size="20" />
<DeleteIcon :size="20" />
</template>
{{ deletePageString }}
</NcActionButton>
Expand All @@ -87,7 +85,6 @@ import { NcActions, NcActionButton, NcActionLink, NcActionSeparator } from '@nex
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile.js'
import CollectiveActions from '../Collective/CollectiveActions.vue'
import DeleteIcon from 'vue-material-design-icons/Delete.vue'
import DeleteOffIcon from 'vue-material-design-icons/DeleteOff.vue'
import EmoticonOutlineIcon from 'vue-material-design-icons/EmoticonOutline.vue'
import FormatListBulletedIcon from 'vue-material-design-icons/FormatListBulleted.vue'
import OpenInNewIcon from 'vue-material-design-icons/OpenInNew.vue'
Expand All @@ -107,7 +104,6 @@ export default {
NcActionLink,
NcActionSeparator,
DeleteIcon,
DeleteOffIcon,
EmoticonOutlineIcon,
FormatListBulletedIcon,
PagesTemplateIcon,
Expand Down Expand Up @@ -201,21 +197,15 @@ export default {
},

deletePageString() {
return this.hasSubpages
? t('collectives', 'Cannot delete page with subpages')
: this.isTemplate
? t('collectives', 'Delete template')
: t('collectives', 'Delete page')
return this.isTemplate
? t('collectives', 'Delete template')
: t('collectives', 'Delete page')
},

hasTemplate() {
return !!this.templatePage(this.pageId)
},

hasSubpages() {
return !!this.visibleSubpages(this.pageId).length || !!this.hasTemplate
},

/**
* Other apps can register an extra collective action via
* OCA.Collectives.CollectiveExtraAction
Expand Down
9 changes: 5 additions & 4 deletions tests/Integration/features/pages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ Feature: pages
And user "jane" sets subpageOrder for page "firstpage" to "[1,2]" with parentPath "Readme.md" in "BehatPagesCollective"
And user "jane" fails to set subpageOrder for page "firstpage" to "[invalid]" with parentPath "Readme.md" in "BehatPagesCollective"

Scenario: Fail to trash a page with subpages
When user "jane" fails to trash page "firstpage" with parentPath "Readme.md" in "BehatPagesCollective"
Then user "jane" sees pagePath "firstpage/Readme.md" in "BehatPagesCollective"

Scenario: Rename parent page
When user "jane" renames page "firstpage" to "parentpage" with parentPath "Readme.md" in "BehatPagesCollective"
Then user "jane" sees pagePath "parentpage/Readme.md" in "BehatPagesCollective"
Expand Down Expand Up @@ -78,6 +74,11 @@ Feature: pages
When user "jane" restores page "subpage" from trash in "BehatPagesCollective"
Then user "jane" sees pagePath "parentpage/subpage.md" in "BehatPagesCollective"

Scenario: Trash and restore a page with subpages
When user "jane" trashes page "parentpage" with parentPath "Readme.md" in "BehatPagesCollective"
And user "jane" doesn't see pagePath "parentpage/Readme.md" in "BehatPagesCollective"
Then user "jane" restores page "parentpage" from trash in "BehatPagesCollective"

Scenario: Trash and delete all subpages reverts subfolders
When user "jane" trashes page "subpage" with parentPath "parentpage/Readme.md" in "BehatPagesCollective"
And user "jane" trashes page "subpage2" with parentPath "parentpage/Readme.md" in "BehatPagesCollective"
Expand Down