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(Reference): Add public API endpoints to get references #46378

Merged
merged 1 commit into from
Jul 17, 2024

Conversation

mejo-
Copy link
Member

@mejo- mejo- commented Jul 9, 2024

Calling the public API endpoints will check for matching registered reference providers that implement IPublicReferenceProvider and call their respective functions. If no matching provider is found, the default LinkReferenceProvider will be used to provide open graph data.

The frontend reference widget components will call these endpoints from unauthorized sessions, e.g. in public shares.

If present, the sharing token of the origin URL is passed to resolveReferencePublic() as additional information for the reference provider to determine the access scope. This allows the respective reference providers to determine whether the origin share has access to the linked resource.

getCacheKeyPublic also gets the sharing token so it can scope the cached entry to it.

Contributes to #45978

Checklist

@mejo- mejo- added the 2. developing Work in progress label Jul 9, 2024
@mejo- mejo- added this to the Nextcloud 30 milestone Jul 9, 2024
@mejo- mejo- self-assigned this Jul 9, 2024
mejo- added a commit to nextcloud-libraries/nextcloud-vue that referenced this pull request Jul 9, 2024
* Depends on nextcloud/server#46378
* Contributes to nextcloud/server#45978

Signed-off-by: Jonas <jonas@freesources.org>
Copy link
Member

@juliushaertl juliushaertl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested yet but looks good from a first read

core/Controller/ReferenceApiController.php Show resolved Hide resolved
@mejo- mejo- force-pushed the feat/public_reference_api branch 2 times, most recently from 6922479 to 224d292 Compare July 10, 2024 09:55
@mejo- mejo- requested a review from juliushaertl July 10, 2024 09:55
$cached = $this->cache->get($cacheKey);
if ($cached) {
return Reference::fromCache($cached);
}

$reference = $matchedProvider->resolveReference($referenceId);
if ($public) {
$reference = $matchedProvider->resolveReferencePublic($referenceId, $sharingToken);

Check failure

Code scanning / Psalm

UndefinedInterfaceMethod Error

Method OCP\Collaboration\Reference\IReferenceProvider::resolveReferencePublic does not exist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grafik
Is fixed.

break;
}

$result[$reference] = $resolve ? $this->referenceManager->resolveReference($reference, true, $sharingToken)->jsonSerialize() : null;

Check notice

Code scanning / Psalm

PossiblyNullReference Note

Cannot call method jsonSerialize on possibly null value
mejo- added a commit to nextcloud-libraries/nextcloud-vue that referenced this pull request Jul 10, 2024
* Depends on nextcloud/server#46378
* Contributes to nextcloud/server#45978

Signed-off-by: Jonas <jonas@freesources.org>
@mejo- mejo- force-pushed the feat/public_reference_api branch from 224d292 to f447eb1 Compare July 15, 2024 12:48
@mejo- mejo- added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 15, 2024
@mejo- mejo- requested a review from blizzz July 15, 2024 13:29
mejo- added a commit to nextcloud/collectives that referenced this pull request Jul 16, 2024
Allow to resolve page references by share token to support lookups from
public shares. This adds link previews for links to other pages in the
same collective in public shares.

It requires the new public reference API from nextcloud/server#46378 and
the Text app being built with nextcloud-libraries/nextcloud-vue#5800.

Fixes: #1275
Contributes to nextcloud/text#5520

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/collectives that referenced this pull request Jul 16, 2024
Allow to resolve page references by share token to support lookups from
public shares. This adds link previews for links to other pages in the
same collective in public shares.

It requires the new public reference API from nextcloud/server#46378 and
the Text app being built with nextcloud-libraries/nextcloud-vue#5800.

Fixes: #1275
Contributes to nextcloud/text#5520

Signed-off-by: Jonas <jonas@freesources.org>
Copy link
Contributor

@max-nextcloud max-nextcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment that will need to be addressed I think.

$cached = $this->cache->get($cacheKey);
if ($cached) {
return Reference::fromCache($cached);
}

$reference = $matchedProvider->resolveReference($referenceId);
if ($public) {
$reference = $matchedProvider->resolveReferencePublic($referenceId, $sharingToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grafik
Is fixed.

core/Controller/ReferenceApiController.php Show resolved Hide resolved
core/Controller/ReferenceApiController.php Show resolved Hide resolved
Calling the public API endpoints will check for matching registered
reference providers that implement `IPublicReferenceProvider` and call
their respective functions. If no matching provider is found, the
default `LinkReferenceProvider` will be used to provide open graph data.

The frontend reference widget components will call these endpoints from
unauthorized sessions, e.g. in public shares.

If present, the sharing token of the origin URL is passed to
`resolveReferencePublic()` as additional information for the reference
provider to determine the access scope. This allows the respective
reference providers to determine whether the origin share has access to
the linked resource.

`getCacheKeyPublic` also gets the sharing token so it can scope the cached
entry to it.

Contributes to #45978

Signed-off-by: Jonas <jonas@freesources.org>
@mejo- mejo- merged commit e4368f6 into master Jul 17, 2024
167 checks passed
@mejo- mejo- deleted the feat/public_reference_api branch July 17, 2024 12:35
mejo- added a commit to nextcloud-libraries/nextcloud-vue that referenced this pull request Jul 17, 2024
* Depends on nextcloud/server#46378
* Contributes to nextcloud/server#45978

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/collectives that referenced this pull request Jul 17, 2024
Allow to resolve page references by share token to support lookups from
public shares. This adds link previews for links to other pages in the
same collective in public shares.

It requires the new public reference API from nextcloud/server#46378 and
the Text app being built with nextcloud-libraries/nextcloud-vue#5800.

Fixes: #1275
Contributes to nextcloud/text#5520

Signed-off-by: Jonas <jonas@freesources.org>
/**
* @since 30.0.0
*/
interface IPublicReferenceProvider extends IReferenceProvider {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done so now in nextcloud/documentation#12037. The HTTP API additions got already documented with nextcloud/documentation#12030

@nickvergessen nickvergessen added the pending documentation This pull request needs an associated documentation update label Jul 18, 2024
@mejo- mejo- removed the pending documentation This pull request needs an associated documentation update label Jul 18, 2024
Copy link
Member

@julien-nc julien-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit late to the party... LGTM

@@ -26,7 +26,7 @@
/**
* @since 29.0.0
*/
class LinkReferenceProvider implements IReferenceProvider {
class LinkReferenceProvider implements IReferenceProvider, IPublicReferenceProvider {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPublicReferenceProvider extends IReferenceProvider so LinkReferenceProvider could just extend IPublicReferenceProvider, right?

mejo- added a commit to nextcloud-libraries/nextcloud-vue that referenced this pull request Jul 22, 2024
* Depends on nextcloud/server#46378
* Contributes to nextcloud/server#45978

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud-libraries/nextcloud-vue that referenced this pull request Jul 22, 2024
* Depends on nextcloud/server#46378
* Contributes to nextcloud/server#45978

Signed-off-by: Jonas <jonas@freesources.org>
backportbot bot pushed a commit to nextcloud-libraries/nextcloud-vue that referenced this pull request Jul 22, 2024
* Depends on nextcloud/server#46378
* Contributes to nextcloud/server#45978

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/collectives that referenced this pull request Jul 24, 2024
Allow to resolve page references by share token to support lookups from
public shares. This adds link previews for links to other pages in the
same collective in public shares.

It requires the new public reference API from nextcloud/server#46378 and
the Text app being built with nextcloud-libraries/nextcloud-vue#5800.

Fixes: #1275
Contributes to nextcloud/text#5520

Signed-off-by: Jonas <jonas@freesources.org>
@blizzz blizzz mentioned this pull request Jul 24, 2024
mejo- added a commit to nextcloud/collectives that referenced this pull request Jul 24, 2024
Allow to resolve page references by share token to support lookups from
public shares. This adds link previews for links to other pages in the
same collective in public shares.

It requires the new public reference API from nextcloud/server#46378 and
the Text app being built with nextcloud-libraries/nextcloud-vue#5800.

Fixes: #1275
Contributes to nextcloud/text#5520

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/collectives that referenced this pull request Jul 24, 2024
Allow to resolve page references by share token to support lookups from
public shares. This adds link previews for links to other pages in the
same collective in public shares.

It requires the new public reference API from nextcloud/server#46378 and
the Text app being built with nextcloud-libraries/nextcloud-vue#5800.

Fixes: #1275
Contributes to nextcloud/text#5520

Signed-off-by: Jonas <jonas@freesources.org>
mejo- added a commit to nextcloud/collectives that referenced this pull request Jul 24, 2024
Allow to resolve page references by share token to support lookups from
public shares. This adds link previews for links to other pages in the
same collective in public shares.

It requires the new public reference API from nextcloud/server#46378 and
the Text app being built with nextcloud-libraries/nextcloud-vue#5800.

Fixes: #1275
Contributes to nextcloud/text#5520

Signed-off-by: Jonas <jonas@freesources.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants