summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-04-27 15:24:28 +0200
committerVincent Petry <pvince81@owncloud.com>2016-05-20 17:56:02 +0200
commit09b3883d9ceae77793e524209090f2e36ab61260 (patch)
treea85b527783e3df487900b43ae9fb86018d695750 /lib
parent8343cfb64b8297035987bc4980ec72015c8e1a04 (diff)
downloadnextcloud-server-09b3883d9ceae77793e524209090f2e36ab61260.tar.gz
nextcloud-server-09b3883d9ceae77793e524209090f2e36ab61260.zip
Updated canUser* functions in SystemTagManager to accept objects
Diffstat (limited to 'lib')
-rw-r--r--lib/private/SystemTag/ManagerFactory.php1
-rw-r--r--lib/private/SystemTag/SystemTagManager.php38
-rw-r--r--lib/public/SystemTag/ISystemTagManager.php23
3 files changed, 15 insertions, 47 deletions
diff --git a/lib/private/SystemTag/ManagerFactory.php b/lib/private/SystemTag/ManagerFactory.php
index e6938e494bc..6b238e3c428 100644
--- a/lib/private/SystemTag/ManagerFactory.php
+++ b/lib/private/SystemTag/ManagerFactory.php
@@ -59,7 +59,6 @@ class ManagerFactory implements ISystemTagManagerFactory {
public function getManager() {
return new SystemTagManager(
$this->serverContainer->getDatabaseConnection(),
- $this->serverContainer->getUserManager(),
$this->serverContainer->getGroupManager(),
$this->serverContainer->getEventDispatcher()
);
diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php
index 0e4bdad078e..495df674a03 100644
--- a/lib/private/SystemTag/SystemTagManager.php
+++ b/lib/private/SystemTag/SystemTagManager.php
@@ -34,6 +34,7 @@ use OCP\IUserManager;
use OCP\IGroupManager;
use OCP\SystemTag\ISystemTag;
use OCP\UserNotFoundException;
+use OCP\IUser;
/**
* Manager class for system tags
@@ -48,9 +49,6 @@ class SystemTagManager implements ISystemTagManager {
/** @var EventDispatcherInterface */
protected $dispatcher;
- /** @var IUserManager */
- protected $userManager;
-
/** @var IGroupManager */
protected $groupManager;
@@ -69,12 +67,10 @@ class SystemTagManager implements ISystemTagManager {
*/
public function __construct(
IDBConnection $connection,
- IUserManager $userManager,
IGroupManager $groupManager,
EventDispatcherInterface $dispatcher
) {
$this->connection = $connection;
- $this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->dispatcher = $dispatcher;
@@ -339,23 +335,12 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function canUserAssignTag($tag, $userId) {
- if (!$tag instanceof ISystemTag) {
- $tags = $this->getTagsByIds([$tag]);
- /** @var ISystemTag $tag */
- $tag = current($tags);
- }
-
- if ($tag->isUserAssignable()) {
+ public function canUserAssignTag(ISystemTag $tag, IUser $user) {
+ if ($tag->isUserAssignable() && $tag->isUserVisible()) {
return true;
}
- $user = $this->userManager->get($userId);
- if ($user === null) {
- throw new UserNotFoundException($userId);
- }
-
- if ($this->groupManager->isAdmin($userId)) {
+ if ($this->groupManager->isAdmin($user->getUID())) {
return true;
}
@@ -365,23 +350,12 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function canUserSeeTag($tag, $userId) {
- if (!$tag instanceof ISystemTag) {
- $tags = $this->getTagsByIds([$tag]);
- /** @var ISystemTag $tag */
- $tag = current($tags);
- }
-
+ public function canUserSeeTag(ISystemTag $tag, IUser $user) {
if ($tag->isUserVisible()) {
return true;
}
- $user = $this->userManager->get($userId);
- if ($user === null) {
- throw new UserNotFoundException($userId);
- }
-
- if ($this->groupManager->isAdmin($userId)) {
+ if ($this->groupManager->isAdmin($user->getUID())) {
return true;
}
diff --git a/lib/public/SystemTag/ISystemTagManager.php b/lib/public/SystemTag/ISystemTagManager.php
index 7fb0c21436c..283ca63e4f6 100644
--- a/lib/public/SystemTag/ISystemTagManager.php
+++ b/lib/public/SystemTag/ISystemTagManager.php
@@ -22,6 +22,9 @@
namespace OCP\SystemTag;
+use OCP\IUser;
+use OCP\SystemTag\ISystemTag;
+
/**
* Public interface to access and manage system-wide tags.
*
@@ -117,33 +120,25 @@ interface ISystemTagManager {
* Checks whether the given user is allowed to assign/unassign the tag with the
* given id.
*
- * @param string|\OCP\SystemTag\ISystemTag $tag tag id or system tag
- * @param string $userId user id
+ * @param ISystemTag $tag tag to check permission for
+ * @param IUser $user user to check permission for
*
* @return true if the user is allowed to assign/unassign the tag, false otherwise
*
- * @throws \OCP\SystemTag\TagNotFoundException if tag with the given id does not exist
- * @throws \OCP\UserNotFoundException if the given user id does not exist
- * @throws \InvalidArgumentException if the tag id is invalid (string instead of integer, etc.)
- *
* @since 9.1.0
*/
- public function canUserAssignTag($tag, $userId);
+ public function canUserAssignTag(ISystemTag $tag, IUser $user);
/**
* Checks whether the given user is allowed to see the tag with the given id.
*
- * @param string|\OCP\SystemTag\ISystemTag $tag tag id or system tag
- * @param string $userId user id
+ * @param ISystemTag $tag tag to check permission for
+ * @param IUser $user user to check permission for
*
* @return true if the user is allowed to assign/unassign the tag, false otherwise
*
- * @throws \OCP\SystemTag\TagNotFoundException if tag with the given id does not exist
- * @throws \OCP\UserNotFoundException if the given user id does not exist
- * @throws \InvalidArgumentException if the tag id is invalid (string instead of integer, etc.)
- *
* @since 9.1.0
*/
- public function canUserSeeTag($tag, $userId);
+ public function canUserSeeTag(ISystemTag $tag, IUser $userId);
}