Skip to content

Commit 2fcb6dd

Browse files
authored
Merge pull request #14664 from nextcloud/bugfix/noid/absolute-paths-of-images-for-linked-collaboration-resources
Replace the icon-class with an absolute link to an image
2 parents a5a2c7d + 21425eb commit 2fcb6dd

28 files changed

+695
-200
lines changed

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
/apps/accessibility/js/accessibility.js.map binary
66
/apps/comments/js/*.js binary
77
/apps/comments/js/*.js.map binary
8-
/apps/files_sharing/js/additionalScripts.js binary
9-
/apps/files_sharing/js/additionalScripts.js.map binary
8+
/apps/files_sharing/js/dist/*.js binary
9+
/apps/files_sharing/js/dist/*.js.map binary
1010
/apps/files_versions/js/files_versions.js binary
1111
/apps/files_versions/js/files_versions.js.map binary
1212
/apps/oauth2/js/oauth2.js binary
Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23
/**
34
* @copyright Copyright (c) 2018 Joas Schilling <coding@schilljs.com>
45
*
@@ -27,24 +28,29 @@
2728
use OCP\Collaboration\Resources\ResourceException;
2829
use OCP\Files\IRootFolder;
2930
use OCP\Files\Node;
31+
use OCP\IPreview;
3032
use OCP\IURLGenerator;
3133
use OCP\IUser;
3234

3335
class ResourceProvider implements IProvider {
3436

35-
const RESOURCE_TYPE = 'files';
37+
public const RESOURCE_TYPE = 'file';
3638

3739
/** @var IRootFolder */
3840
protected $rootFolder;
39-
41+
/** @var IPreview */
42+
private $preview;
4043
/** @var IURLGenerator */
4144
private $urlGenerator;
4245

4346
/** @var array */
4447
protected $nodes = [];
4548

46-
public function __construct(IRootFolder $rootFolder, IURLGenerator $urlGenerator) {
49+
public function __construct(IRootFolder $rootFolder,
50+
IPreview $preview,
51+
IURLGenerator $urlGenerator) {
4752
$this->rootFolder = $rootFolder;
53+
$this->preview = $preview;
4854
$this->urlGenerator = $urlGenerator;
4955
}
5056

@@ -61,21 +67,34 @@ private function getNode(IResource $resource): ?Node {
6167
}
6268

6369
/**
64-
* Get the display name of a resource
65-
*
6670
* @param IResource $resource
67-
* @return string
68-
* @since 15.0.0
71+
* @return array
72+
* @since 16.0.0
6973
*/
70-
public function getName(IResource $resource): string {
74+
public function getResourceRichObject(IResource $resource): array {
7175
if (isset($this->nodes[(int) $resource->getId()])) {
72-
return $this->nodes[(int) $resource->getId()]->getPath();
76+
$node = $this->nodes[(int) $resource->getId()]->getPath();
77+
} else {
78+
$node = $this->getNode($resource);
7379
}
74-
$node = $this->getNode($resource);
75-
if ($node) {
76-
return $node->getName();
80+
81+
if ($node instanceof Node) {
82+
$link = $this->urlGenerator->linkToRouteAbsolute(
83+
'files.viewcontroller.showFile',
84+
['fileid' => $resource->getId()]
85+
);
86+
return [
87+
'type' => 'file',
88+
'id' => $resource->getId(),
89+
'name' => $node->getName(),
90+
'path' => $node->getInternalPath(),
91+
'link' => $link,
92+
'mimetype' => $node->getMimetype(),
93+
'preview-available' => $this->preview->isAvailable($node),
94+
];
7795
}
78-
return '';
96+
97+
throw new ResourceException('File not found');
7998
}
8099

81100
/**
@@ -84,7 +103,7 @@ public function getName(IResource $resource): string {
84103
* @param IResource $resource
85104
* @param IUser $user
86105
* @return bool
87-
* @since 15.0.0
106+
* @since 16.0.0
88107
*/
89108
public function canAccessResource(IResource $resource, IUser $user = null): bool {
90109
if (!$user instanceof IUser) {
@@ -102,39 +121,13 @@ public function canAccessResource(IResource $resource, IUser $user = null): bool
102121
return false;
103122
}
104123

105-
/**
106-
* Get the icon class of a resource
107-
*
108-
* @param IResource $resource
109-
* @return string
110-
* @since 15.0.0
111-
*/
112-
public function getIconClass(IResource $resource): string {
113-
$node = $this->getNode($resource);
114-
if ($node && $node->getMimetype() === 'httpd/unix-directory') {
115-
return 'icon-files-dark';
116-
}
117-
return 'icon-filetype-file';
118-
}
119-
120124
/**
121125
* Get the resource type of the provider
122126
*
123127
* @return string
124-
* @since 15.0.0
128+
* @since 16.0.0
125129
*/
126130
public function getType(): string {
127131
return self::RESOURCE_TYPE;
128132
}
129-
130-
/**
131-
* Get the link to a resource
132-
*
133-
* @param IResource $resource
134-
* @return string
135-
* @since 15.0.0
136-
*/
137-
public function getLink(IResource $resource): string {
138-
return $this->urlGenerator->linkToRoute('files.viewcontroller.showFile', ['fileid' => $resource->getId()]);
139-
}
140133
}

apps/files_sharing/appinfo/app.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ function() {
4545
\OCP\Util::addScript('files_sharing', 'dist/additionalScripts');
4646
}
4747
);
48+
\OC::$server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', function () {
49+
\OCP\Util::addScript('files_sharing', 'dist/collaboration');
50+
});
4851

4952
$config = \OC::$server->getConfig();
5053
$shareManager = \OC::$server->getShareManager();

apps/files_sharing/js/dist/additionalScripts.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/additionalScripts.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/collaboration.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/collaboration.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/files_sharing.3.js

Lines changed: 563 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/files_sharing.3.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/files_sharing/js/dist/files_sharing.4.js

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)