Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(PageReference): Public page reference lookups #1369

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
107 changes: 107 additions & 0 deletions cypress/e2e/pages-links.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,3 +598,110 @@ describe('Page link handling', function() {
}
})
})

// Previews got added with Nextcloud 29
if (!['stable27', 'stable28'].includes(Cypress.env('ncVersion'))) {
describe('Page link preview handling', function() {
before(function() {
cy.loginAs('bob')
cy.deleteAndSeedCollective('Link Preview Testing')
.seedPage('Link Source', '', 'Readme.md')
.seedPage('Link Target', '', 'Readme.md')
.then(({ pageId }) => {
const pageUrls = [
`${baseUrl}/index.php/apps/collectives/Link%20Preview%20Testing/Link%20Target?fileId=${pageId}`,
`${baseUrl}/index.php/apps/collectives/Link%20Preview%20Testing/Link%20Target`,
`${baseUrl}/index.php/apps/collectives/p/qqqYoCgYRnZ598p/Link%20Preview%20Testing/Link%20Target?fileId=${pageId}`,
`${baseUrl}/index.php/apps/collectives/p/qqqYoCgYRnZ598p/Link%20Preview%20Testing/Link%20Target`,
]
cy.seedPageContent('Link%20Preview%20Testing/Link%20Target.md', 'Some content')
.seedPageContent('Link%20Preview%20Testing/Link%20Source.md', `
## Link previews to own Collective

[Internal link to page with fileId](${pageUrls[0]} (preview))

[Internal link to page without fileId](${pageUrls[1]} (preview))

[Public link to page with fileId](${pageUrls[2]} (preview))

[Public link to page without fileId](${pageUrls[3]} (preview))
`)

})
})

beforeEach(function() {
cy.loginAs('bob')
cy.visit('/apps/collectives/Link Preview Testing/Link Source')
// make sure the page list loaded properly
cy.contains('.app-content-list-item a', 'Link Target')
})

it('Shows previews in view and edit mode', function() {
cy.getEditorContent()
.find('.widget-custom a.collective-page')
.should('have.length', 4)

cy.switchToEditMode()
cy.getEditorContent(true)
.find('.widget-custom a.collective-page')
.should('have.length', 4)
})

// Previews in public shares got added with Nextcloud 30
if (!['stable29'].includes(Cypress.env('ncVersion'))) {
let shareUrl

it('Share the collective', function() {
cy.visit('/apps/collectives', {
onBeforeLoad(win) {
// navigator.clipboard doesn't exist on HTTP requests (in CI), so let's create it
if (!win.navigator.clipboard) {
win.navigator.clipboard = {
__proto__: {
writeText: () => {
},
},
}
}
// overwrite navigator.clipboard.writeText with cypress stub
cy.stub(win.navigator.clipboard, 'writeText', (text) => {
shareUrl = text
})
.as('clipBoardWriteText')
},
})
cy.openCollectiveMenu('Link Preview Testing')
cy.clickMenuButton('Share link')
cy.intercept('POST', '**/_api/*/share').as('createShare')
cy.get('.sharing-entry button.new-share-link')
.click()
cy.wait('@createShare')
cy.get('.sharing-entry .share-select')
.click()
cy.intercept('PUT', '**/_api/*/share/*').as('updateShare')
cy.get('.sharing-entry .share-select .dropdown-item')
.contains('Can edit')
.click()
cy.wait('@updateShare')
cy.get('button.sharing-entry__copy')
.click()
cy.get('@clipBoardWriteText').should('have.been.calledOnce')
})

it('Public share: Shows previews in view and edit mode', function() {
cy.logout()
cy.visit(`${shareUrl}/Link Source`)

cy.getEditorContent()
.find('.widget-custom a.collective-page')
.should('have.length', 4)

cy.switchToEditMode()
cy.getEditorContent(true)
.find('.widget-custom a.collective-page')
.should('have.length', 4)
})
}
})
}
8 changes: 7 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use OCA\Collectives\Mount\CollectiveFolderManager;
use OCA\Collectives\Mount\MountProvider;
use OCA\Collectives\Reference\SearchablePageReferenceProvider;
use OCA\Collectives\Reference\SearchablePageReferenceProvider29;
use OCA\Collectives\Search\CollectiveProvider;
use OCA\Collectives\Search\PageContentProvider;
use OCA\Collectives\Search\PageProvider;
Expand All @@ -36,6 +37,7 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Collaboration\Reference\IPublicReferenceProvider;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Dashboard\IAPIWidgetV2;
use OCP\Files\Config\IMountProviderCollection;
Expand Down Expand Up @@ -98,7 +100,11 @@ public function register(IRegistrationContext $context): void {
$context->registerSearchProvider(PageProvider::class);
$context->registerSearchProvider(PageContentProvider::class);

$context->registerReferenceProvider(SearchablePageReferenceProvider::class);
if (interface_exists(IPublicReferenceProvider::class)) {
$context->registerReferenceProvider(SearchablePageReferenceProvider::class);
} else {
$context->registerReferenceProvider(SearchablePageReferenceProvider29::class);
}

$cacheListener = $this->getContainer()->get(CacheListener::class);
$cacheListener->listen();
Expand Down
12 changes: 11 additions & 1 deletion lib/Db/Collective.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ class Collective extends Entity implements JsonSerializable {
protected ?int $trashTimestamp = null;
protected int $pageMode = self::defaultPageMode;
/** transient attributes, not persisted in database */
protected string $name;
protected string $name = '';
protected int $level = Member::LEVEL_MEMBER;
protected ?string $shareToken = null;
protected bool $isPageShare = false;
protected int $sharePageId = 0;
protected bool $shareEditable = false;
protected int $userPageOrder = Collective::defaultPageOrder;
protected bool $userShowRecentPages = Collective::defaultShowRecentPages;
Expand Down Expand Up @@ -158,6 +159,14 @@ public function setIsPageShare(bool $isPageShare): void {
$this->isPageShare = $isPageShare;
}

public function getSharePageId(): int {
return $this->sharePageId;
}

public function setSharePageId(int $sharePageId): void {
$this->sharePageId = $sharePageId;
}

public function getShareEditable(): bool {
return $this->shareEditable;
}
Expand Down Expand Up @@ -251,6 +260,7 @@ public function jsonSerialize(): array {
'canShare' => $this->canShare(),
'shareToken' => $this->shareToken,
'isPageShare' => $this->isPageShare,
'sharePageId' => $this->sharePageId,
'shareEditable' => $this->canEdit() && $this->shareEditable,
'userPageOrder' => $this->userPageOrder,
'userShowRecentPages' => $this->userShowRecentPages,
Expand Down
Loading
Loading