mirror of https://github.com/nextcloud/bookmarks
fix: drop collaboration resources integration to be compatible with nc 28
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
parent
2416a8d5be
commit
29e1e938d5
|
@ -8,11 +8,7 @@
|
|||
|
||||
namespace OCA\Bookmarks\AppInfo;
|
||||
|
||||
use Closure;
|
||||
use OC\EventDispatcher\SymfonyAdapter;
|
||||
use OCA\Bookmarks\Activity\ActivityPublisher;
|
||||
use OCA\Bookmarks\Collaboration\Resources\FolderResourceProvider;
|
||||
use OCA\Bookmarks\Collaboration\Resources\ResourceProvider;
|
||||
use OCA\Bookmarks\Dashboard\Frequent;
|
||||
use OCA\Bookmarks\Dashboard\Recent;
|
||||
use OCA\Bookmarks\Events\BeforeDeleteEvent;
|
||||
|
@ -32,7 +28,6 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
|
|||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
||||
use OCP\Collaboration\Reference\RenderReferenceEvent;
|
||||
use OCP\Collaboration\Resources\IProviderManager;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Group\Events\UserAddedEvent;
|
||||
use OCP\Group\Events\UserRemovedEvent;
|
||||
|
@ -101,17 +96,7 @@ class Application extends App implements IBootstrap {
|
|||
* @throws \Throwable
|
||||
*/
|
||||
public function boot(IBootContext $context): void {
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerCollaborationResources']));
|
||||
$container = $context->getServerContainer();
|
||||
CreateBookmark::register($container->get(IEventDispatcher::class));
|
||||
}
|
||||
|
||||
protected function registerCollaborationResources(IProviderManager $resourceManager, SymfonyAdapter $symfonyAdapter): void {
|
||||
$resourceManager->registerResourceProvider(ResourceProvider::class);
|
||||
$resourceManager->registerResourceProvider(FolderResourceProvider::class);
|
||||
|
||||
$symfonyAdapter->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () {
|
||||
Util::addScript('bookmarks', 'bookmarks-collections');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) 2022. The Nextcloud Bookmarks contributors.
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
||||
*/
|
||||
|
||||
namespace OCA\Bookmarks\Collaboration\Resources;
|
||||
|
||||
use OCA\Bookmarks\Db\Folder;
|
||||
use OCA\Bookmarks\Db\FolderMapper;
|
||||
use OCA\Bookmarks\Service\Authorizer;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
use OCP\Collaboration\Resources\IProvider;
|
||||
use OCP\Collaboration\Resources\IResource;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
|
||||
class FolderResourceProvider implements IProvider {
|
||||
public const RESOURCE_TYPE = 'bookmarks-folder';
|
||||
/**
|
||||
* @var IURLGenerator
|
||||
*/
|
||||
private $url;
|
||||
/**
|
||||
* @var Authorizer
|
||||
*/
|
||||
private $authorizer;
|
||||
/**
|
||||
* @var FolderMapper
|
||||
*/
|
||||
private $folderMapper;
|
||||
|
||||
public function __construct(IURLGenerator $url, Authorizer $authorizer, FolderMapper $folderMapper) {
|
||||
$this->url = $url;
|
||||
$this->authorizer = $authorizer;
|
||||
$this->folderMapper = $folderMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getType(): string {
|
||||
return self::RESOURCE_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getResourceRichObject(IResource $resource): array {
|
||||
$folder = $this->getFolder($resource);
|
||||
$favicon = $this->url->imagePath('bookmarks', 'bookmarks-black.svg');
|
||||
$resourceUrl = $this->url->linkToRouteAbsolute('bookmarks.web_view.indexfolder', ['folder' => $folder->getId()]);
|
||||
|
||||
return [
|
||||
'type' => self::RESOURCE_TYPE,
|
||||
'id' => $resource->getId(),
|
||||
'name' => $folder->getTitle(),
|
||||
'link' => $resourceUrl,
|
||||
'iconUrl' => $favicon,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function canAccessResource(IResource $resource, ?IUser $user): bool {
|
||||
if ($resource->getType() !== self::RESOURCE_TYPE || !($user instanceof IUser)) {
|
||||
return false;
|
||||
}
|
||||
$folder = $this->getFolder($resource);
|
||||
if ($folder === null) {
|
||||
return false;
|
||||
}
|
||||
if ($folder->getUserId() === $user->getUID()) {
|
||||
return true;
|
||||
}
|
||||
$permissions = $this->authorizer->getUserPermissionsForFolder($user->getUID(), $folder->getId());
|
||||
return Authorizer::hasPermission(Authorizer::PERM_READ, $permissions);
|
||||
}
|
||||
|
||||
private function getFolder(IResource $resource) : ?Folder {
|
||||
try {
|
||||
return $this->folderMapper->find((int) $resource->getId());
|
||||
} catch (MultipleObjectsReturnedException|DoesNotExistException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (c) 2022. The Nextcloud Bookmarks contributors.
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
||||
*/
|
||||
|
||||
namespace OCA\Bookmarks\Collaboration\Resources;
|
||||
|
||||
use OCA\Bookmarks\Db\Bookmark;
|
||||
use OCA\Bookmarks\Db\BookmarkMapper;
|
||||
use OCA\Bookmarks\Service\Authorizer;
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
use OCP\Collaboration\Resources\IProvider;
|
||||
use OCP\Collaboration\Resources\IResource;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUser;
|
||||
|
||||
class ResourceProvider implements IProvider {
|
||||
public const RESOURCE_TYPE = 'bookmarks';
|
||||
/**
|
||||
* @var BookmarkMapper
|
||||
*/
|
||||
private $bookmarkMapper;
|
||||
/**
|
||||
* @var IURLGenerator
|
||||
*/
|
||||
private $url;
|
||||
/**
|
||||
* @var Authorizer
|
||||
*/
|
||||
private $authorizer;
|
||||
|
||||
public function __construct(BookmarkMapper $bookmarkMapper, IURLGenerator $url, Authorizer $authorizer) {
|
||||
$this->bookmarkMapper = $bookmarkMapper;
|
||||
$this->url = $url;
|
||||
$this->authorizer = $authorizer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getType(): string {
|
||||
return self::RESOURCE_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getResourceRichObject(IResource $resource): array {
|
||||
$bookmark = $this->getBookmark($resource);
|
||||
$favicon = $this->url->linkToRouteAbsolute('bookmarks.internal_bookmark.get_bookmark_favicon', ['id' => $bookmark->getId()]);
|
||||
$resourceUrl = $this->url->linkToRouteAbsolute('bookmarks.web_view.indexbookmark', ['bookmark' => $bookmark->getId()]);
|
||||
|
||||
return [
|
||||
'type' => self::RESOURCE_TYPE,
|
||||
'id' => $resource->getId(),
|
||||
'name' => $bookmark->getTitle(),
|
||||
'link' => $resourceUrl,
|
||||
'iconUrl' => $favicon,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function canAccessResource(IResource $resource, ?IUser $user): bool {
|
||||
if ($resource->getType() !== self::RESOURCE_TYPE || !($user instanceof IUser)) {
|
||||
return false;
|
||||
}
|
||||
$bookmark = $this->getBookmark($resource);
|
||||
if ($bookmark === null) {
|
||||
return false;
|
||||
}
|
||||
if ($bookmark->getUserId() === $user->getUID()) {
|
||||
return true;
|
||||
}
|
||||
$permissions = $this->authorizer->getUserPermissionsForBookmark($user->getUID(), $bookmark->getId());
|
||||
return Authorizer::hasPermission(Authorizer::PERM_READ, $permissions);
|
||||
}
|
||||
|
||||
private function getBookmark(IResource $resource) : ?Bookmark {
|
||||
try {
|
||||
return $this->bookmarkMapper->find((int) $resource->getId());
|
||||
} catch (MultipleObjectsReturnedException|DoesNotExistException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2022. The Nextcloud Bookmarks contributors.
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or later. See the COPYING file.
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import FolderPickerDialog from './components/FolderPickerDialog.vue'
|
||||
import { Store } from 'vuex'
|
||||
import deepClone from 'clone-deep'
|
||||
import store, { actions } from './store/index.js'
|
||||
import AppGlobal from './mixins/AppGlobal.js'
|
||||
import { Tooltip } from '@nextcloud/vue'
|
||||
|
||||
// eslint-disable-next-line
|
||||
__webpack_nonce__ = btoa(OC.requestToken)
|
||||
// eslint-disable-next-line
|
||||
__webpack_public_path__ = OC.linkTo('bookmarks', 'js/')
|
||||
|
||||
Vue.mixin(AppGlobal)
|
||||
Vue.directive('tooltip', Tooltip)
|
||||
|
||||
OCP.Collaboration.registerType('bookmarks-folder', {
|
||||
action: () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const container = document.createElement('div')
|
||||
container.id = 'bookmarks-bookmark-folder-select'
|
||||
const body = document.getElementById('body-user')
|
||||
body.appendChild(container)
|
||||
const ComponentVM = new Vue({
|
||||
render: h => h(FolderPickerDialog),
|
||||
store: new Store(deepClone(store)),
|
||||
})
|
||||
ComponentVM.$store.dispatch(actions.LOAD_FOLDERS, true)
|
||||
ComponentVM.$mount(container)
|
||||
window.bookmarksPicker = ComponentVM
|
||||
ComponentVM.$root.$on('close', () => {
|
||||
ComponentVM.$el.remove()
|
||||
ComponentVM.$destroy()
|
||||
reject(new Error('User cancelled resource selection'))
|
||||
})
|
||||
ComponentVM.$root.$on('select', (id) => {
|
||||
resolve(id)
|
||||
ComponentVM.$el.remove()
|
||||
ComponentVM.$destroy()
|
||||
})
|
||||
})
|
||||
},
|
||||
typeString: t('bookmarks', 'Link to a bookmark folder'),
|
||||
typeIconClass: 'icon-favorite',
|
||||
})
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
script('bookmarks', 'bookmarks-main');
|
||||
\OC::$server->getEventDispatcher()->dispatch('\OCP\Collaboration\Resources::loadAdditionalScripts');
|
||||
?>
|
||||
<div id="vue-content"></div>
|
||||
|
|
|
@ -8,5 +8,4 @@ webpackConfig.entry['service-worker'] = path.join(__dirname, 'src', 'service-wor
|
|||
webpackConfig.entry.flow = path.join(__dirname, 'src', 'flow.js')
|
||||
webpackConfig.entry.dashboard = path.join(__dirname, 'src', 'dashboard.js')
|
||||
webpackConfig.entry.talk = path.join(__dirname, 'src', 'talk.js')
|
||||
webpackConfig.entry.collections = path.join(__dirname, 'src', 'collections.js')
|
||||
webpackConfig.entry.references = path.join(__dirname, 'src', 'references.js')
|
||||
|
|
Loading…
Reference in New Issue