Skip to content

Commit

Permalink
feat: Implement sharing with circles
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed May 24, 2024
1 parent 2598a7b commit cbc6481
Show file tree
Hide file tree
Showing 9 changed files with 393 additions and 213 deletions.
18 changes: 14 additions & 4 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@
use OCA\Bookmarks\Events\UpdateEvent;
use OCA\Bookmarks\Flow\CreateBookmark;
use OCA\Bookmarks\Hooks\BeforeTemplateRenderedListener;
use OCA\Bookmarks\Hooks\UserGroupListener;
use OCA\Bookmarks\Hooks\UsersGroupsCirclesListener;
use OCA\Bookmarks\Middleware\ExceptionMiddleware;
use OCA\Bookmarks\Reference\BookmarkReferenceProvider;
use OCA\Bookmarks\Search\Provider;
use OCA\Bookmarks\Service\TreeCacheManager;
use OCA\Circles\Events\CircleDestroyedEvent;
use OCA\Circles\Events\CircleMemberAddedEvent;
use OCA\Circles\Events\CircleMemberRemovedEvent;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\BeforeGroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\IRequest;
Expand Down Expand Up @@ -81,9 +85,15 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeDeleteEvent::class, ActivityPublisher::class);
$context->registerEventListener(MoveEvent::class, ActivityPublisher::class);

$context->registerEventListener(BeforeUserDeletedEvent::class, UserGroupListener::class);
$context->registerEventListener(UserAddedEvent::class, UserGroupListener::class);
$context->registerEventListener(UserRemovedEvent::class, UserGroupListener::class);
$context->registerEventListener(BeforeUserDeletedEvent::class, UsersGroupsCirclesListener::class);

Check failure on line 88 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

InvalidArgument

lib/AppInfo/Application.php:88:66: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)

Check failure on line 88 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

InvalidArgument

lib/AppInfo/Application.php:88:66: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)
$context->registerEventListener(UserAddedEvent::class, UsersGroupsCirclesListener::class);

Check failure on line 89 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

InvalidArgument

lib/AppInfo/Application.php:89:58: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)

Check failure on line 89 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

InvalidArgument

lib/AppInfo/Application.php:89:58: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)
$context->registerEventListener(UserRemovedEvent::class, UsersGroupsCirclesListener::class);

Check failure on line 90 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

InvalidArgument

lib/AppInfo/Application.php:90:60: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)

Check failure on line 90 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

InvalidArgument

lib/AppInfo/Application.php:90:60: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)
$context->registerEventListener(BeforeGroupDeletedEvent::class, UsersGroupsCirclesListener::class);

Check failure on line 91 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

InvalidArgument

lib/AppInfo/Application.php:91:67: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)

Check failure on line 91 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

InvalidArgument

lib/AppInfo/Application.php:91:67: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)
if (class_exists('\OCA\Circles\Model\Circle')) {
$context->registerEventListener(CircleMemberAddedEvent::class, UsersGroupsCirclesListener::class);

Check failure on line 93 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

UndefinedClass

lib/AppInfo/Application.php:93:36: UndefinedClass: Class, interface or enum named OCA\Circles\Events\CircleMemberAddedEvent does not exist (see https://psalm.dev/019)

Check failure on line 93 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

InvalidArgument

lib/AppInfo/Application.php:93:67: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)

Check failure on line 93 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

UndefinedClass

lib/AppInfo/Application.php:93:36: UndefinedClass: Class, interface or enum named OCA\Circles\Events\CircleMemberAddedEvent does not exist (see https://psalm.dev/019)

Check failure on line 93 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

InvalidArgument

lib/AppInfo/Application.php:93:67: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)
$context->registerEventListener(CircleMemberRemovedEvent::class, UsersGroupsCirclesListener::class);

Check failure on line 94 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

UndefinedClass

lib/AppInfo/Application.php:94:36: UndefinedClass: Class, interface or enum named OCA\Circles\Events\CircleMemberRemovedEvent does not exist (see https://psalm.dev/019)

Check failure on line 94 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

InvalidArgument

lib/AppInfo/Application.php:94:69: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)

Check failure on line 94 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

UndefinedClass

lib/AppInfo/Application.php:94:36: UndefinedClass: Class, interface or enum named OCA\Circles\Events\CircleMemberRemovedEvent does not exist (see https://psalm.dev/019)

Check failure on line 94 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

InvalidArgument

lib/AppInfo/Application.php:94:69: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)
$context->registerEventListener(CircleDestroyedEvent::class, UsersGroupsCirclesListener::class);

Check failure on line 95 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

UndefinedClass

lib/AppInfo/Application.php:95:36: UndefinedClass: Class, interface or enum named OCA\Circles\Events\CircleDestroyedEvent does not exist (see https://psalm.dev/019)

Check failure on line 95 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v28.x

InvalidArgument

lib/AppInfo/Application.php:95:65: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)

Check failure on line 95 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

UndefinedClass

lib/AppInfo/Application.php:95:36: UndefinedClass: Class, interface or enum named OCA\Circles\Events\CircleDestroyedEvent does not exist (see https://psalm.dev/019)

Check failure on line 95 in lib/AppInfo/Application.php

View workflow job for this annotation

GitHub Actions / Nextcloud v29.x

InvalidArgument

lib/AppInfo/Application.php:95:65: InvalidArgument: Argument 2 of OCP\AppFramework\Bootstrap\IRegistrationContext::registerEventListener expects class-string<OCP\EventDispatcher\IEventListener<OCP\EventDispatcher\Event>>, but OCA\Bookmarks\Hooks\UsersGroupsCirclesListener::class provided (see https://psalm.dev/004)
}

$context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);

Expand Down
34 changes: 33 additions & 1 deletion lib/Db/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

namespace OCA\Bookmarks\Db;

use OCA\Bookmarks\Service\CirclesService;
use OCP\AppFramework\Db\Entity;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\Share\IShare;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* Class Share
Expand Down Expand Up @@ -58,6 +64,32 @@ public function __construct() {
* @psalm-return array{id: mixed, folderId: mixed, owner: mixed, participant: mixed, type: mixed, canWrite: mixed, canShare: mixed, createdAt: mixed}
*/
public function toArray(): array {
return ['id' => $this->id, 'folderId' => $this->folderId, 'owner' => $this->owner, 'participant' => $this->participant, 'type' => $this->type, 'canWrite' => $this->canWrite, 'canShare' => $this->canShare, 'createdAt' => $this->createdAt];
return [
'id' => $this->id,
'folderId' => $this->folderId,
'owner' => $this->owner,
'participant' => $this->participant,
'type' => $this->type,
'canWrite' => $this->canWrite,
'canShare' => $this->canShare,
'createdAt' => $this->createdAt,
'participantDisplayName' => self::getParticipantDisplayName($this->type, $this->participant),
];
}

private static function getParticipantDisplayName($type, $participant) {
try {
if ($type === IShare::TYPE_USER) {
return \OCP\Server::get(IUserManager::class)->get($participant)->getDisplayName();
}
if ($type === IShare::TYPE_GROUP) {
return \OCP\Server::get(IGroupManager::class)->get($participant)->getDisplayName();
}
if ($type === IShare::TYPE_CIRCLE) {
return \OCP\Server::get(CirclesService::class)->getCircle($participant)->getName();
}
} catch (NotFoundExceptionInterface|ContainerExceptionInterface $e) {
return $participant;
}
}
}
142 changes: 0 additions & 142 deletions lib/Hooks/UserGroupListener.php

This file was deleted.

Loading

0 comments on commit cbc6481

Please sign in to comment.