aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulius Knorr <jus@bitgrid.net>2024-12-12 15:18:47 +0100
committerGitHub <noreply@github.com>2024-12-12 15:18:47 +0100
commitcba556d641d07218916e97be3e94d17cad0406fb (patch)
treeb1fd40f6fa31598c83520f3367246fd9180f5c19 /lib
parent290c3472295c704d89a22b87d885e0eb9f523633 (diff)
parenteb61a3ae4480d8d07210e91fc2037e2887f9663e (diff)
downloadnextcloud-server-cba556d641d07218916e97be3e94d17cad0406fb.tar.gz
nextcloud-server-cba556d641d07218916e97be3e94d17cad0406fb.zip
Merge pull request #48612 from nextcloud/fix/activity-log-for-favorites-in-dav
add activity logging for favorites in dav
Diffstat (limited to 'lib')
-rw-r--r--lib/private/TagManager.php19
-rw-r--r--lib/private/Tags.php39
2 files changed, 31 insertions, 27 deletions
diff --git a/lib/private/TagManager.php b/lib/private/TagManager.php
index f99653f2c05..5c346e14430 100644
--- a/lib/private/TagManager.php
+++ b/lib/private/TagManager.php
@@ -11,6 +11,7 @@ use OC\Tagging\TagMapper;
use OCP\Db\Exception as DBException;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
use OCP\IDBConnection;
use OCP\ITagManager;
@@ -23,16 +24,14 @@ use Psr\Log\LoggerInterface;
* @template-implements IEventListener<UserDeletedEvent>
*/
class TagManager implements ITagManager, IEventListener {
- private TagMapper $mapper;
- private IUserSession $userSession;
- private IDBConnection $connection;
- private LoggerInterface $logger;
- public function __construct(TagMapper $mapper, IUserSession $userSession, IDBConnection $connection, LoggerInterface $logger) {
- $this->mapper = $mapper;
- $this->userSession = $userSession;
- $this->connection = $connection;
- $this->logger = $logger;
+ public function __construct(
+ private TagMapper $mapper,
+ private IUserSession $userSession,
+ private IDBConnection $connection,
+ private LoggerInterface $logger,
+ private IEventDispatcher $dispatcher,
+ ) {
}
/**
@@ -57,7 +56,7 @@ class TagManager implements ITagManager, IEventListener {
}
$userId = $this->userSession->getUser()->getUId();
}
- return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $defaultTags);
+ return new Tags($this->mapper, $userId, $type, $this->logger, $this->connection, $this->dispatcher, $this->userSession, $defaultTags);
}
/**
diff --git a/lib/private/Tags.php b/lib/private/Tags.php
index d59c1bd6928..0a37f4c9f4e 100644
--- a/lib/private/Tags.php
+++ b/lib/private/Tags.php
@@ -11,8 +11,12 @@ use OC\Tagging\Tag;
use OC\Tagging\TagMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\Events\NodeAddedToFavorite;
+use OCP\Files\Events\NodeRemovedFromFavorite;
use OCP\IDBConnection;
use OCP\ITags;
+use OCP\IUserSession;
use OCP\Share_Backend;
use Psr\Log\LoggerInterface;
@@ -21,10 +25,6 @@ class Tags implements ITags {
* Used for storing objectid/categoryname pairs while rescanning.
*/
private static array $relations = [];
- private string $type;
- private string $user;
- private IDBConnection $db;
- private LoggerInterface $logger;
private array $tags = [];
/**
@@ -39,11 +39,6 @@ class Tags implements ITags {
private array $owners = [];
/**
- * The Mapper we are using to communicate our Tag objects to the database.
- */
- private TagMapper $mapper;
-
- /**
* The sharing backend for objects of $this->type. Required if
* $this->includeShared === true to determine ownership of items.
*/
@@ -62,14 +57,18 @@ class Tags implements ITags {
*
* since 20.0.0 $includeShared isn't used anymore
*/
- public function __construct(TagMapper $mapper, string $user, string $type, LoggerInterface $logger, IDBConnection $connection, array $defaultTags = []) {
- $this->mapper = $mapper;
- $this->user = $user;
- $this->type = $type;
+ public function __construct(
+ private TagMapper $mapper,
+ private string $user,
+ private string $type,
+ private LoggerInterface $logger,
+ private IDBConnection $db,
+ private IEventDispatcher $dispatcher,
+ private IUserSession $userSession,
+ array $defaultTags = [],
+ ) {
$this->owners = [$this->user];
$this->tags = $this->mapper->loadTags($this->owners, $this->type);
- $this->db = $connection;
- $this->logger = $logger;
if (count($defaultTags) > 0 && count($this->tags) === 0) {
$this->addMultiple($defaultTags, true);
@@ -502,7 +501,7 @@ class Tags implements ITags {
* @param string $tag The id or name of the tag
* @return boolean Returns false on error.
*/
- public function tagAs($objid, $tag) {
+ public function tagAs($objid, $tag, string $path = '') {
if (is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag);
if ($tag === '') {
@@ -532,6 +531,9 @@ class Tags implements ITags {
]);
return false;
}
+ if ($tag === ITags::TAG_FAVORITE) {
+ $this->dispatcher->dispatchTyped(new NodeAddedToFavorite($this->userSession->getUser(), $objid, $path));
+ }
return true;
}
@@ -542,7 +544,7 @@ class Tags implements ITags {
* @param string $tag The id or name of the tag
* @return boolean
*/
- public function unTag($objid, $tag) {
+ public function unTag($objid, $tag, string $path = '') {
if (is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag);
if ($tag === '') {
@@ -569,6 +571,9 @@ class Tags implements ITags {
]);
return false;
}
+ if ($tag === ITags::TAG_FAVORITE) {
+ $this->dispatcher->dispatchTyped(new NodeRemovedFromFavorite($this->userSession->getUser(), $objid, $path));
+ }
return true;
}