summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/private/group/backend.php2
-rw-r--r--lib/private/group/database.php39
-rw-r--r--lib/private/group/interface.php65
-rw-r--r--lib/private/share20/defaultshareprovider.php34
-rw-r--r--lib/private/user.php4
-rw-r--r--lib/private/user/backend.php2
-rw-r--r--lib/private/user/interface.php64
-rw-r--r--lib/private/user/user.php5
-rw-r--r--lib/public/groupinterface.php70
-rw-r--r--lib/public/userinterface.php70
-rw-r--r--tests/lib/share20/defaultshareprovidertest.php3
11 files changed, 186 insertions, 172 deletions
diff --git a/lib/private/group/backend.php b/lib/private/group/backend.php
index 29f24fb3070..ed059f63aaf 100644
--- a/lib/private/group/backend.php
+++ b/lib/private/group/backend.php
@@ -53,7 +53,7 @@ define('OC_GROUP_BACKEND_COUNT_USERS', 0x00100000);
/**
* Abstract base class for user management
*/
-abstract class OC_Group_Backend implements OC_Group_Interface {
+abstract class OC_Group_Backend implements \OCP\GroupInterface {
/**
* error code for functions not provided by the group backend
*/
diff --git a/lib/private/group/database.php b/lib/private/group/database.php
index b769e69b4ba..21e7b103554 100644
--- a/lib/private/group/database.php
+++ b/lib/private/group/database.php
@@ -85,44 +85,15 @@ class OC_Group_Database extends OC_Group_Backend {
public function createGroup( $gid ) {
$this->fixDI();
- // Check cache first
- if (isset($this->groupCache[$gid])) {
- return false;
- } else {
- // Check for existence in DB
- $qb = $this->dbConn->getQueryBuilder();
- $cursor = $qb->select('gid')
- ->from('groups')
- ->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
- ->execute();
-
- $result = $cursor->fetch();
- $cursor->closeCursor();
-
- if($result) {
- // Can not add an existing group
-
- // Add to cache
- $this->groupCache[$gid] = $gid;
-
- return false;
- }
- }
-
- // Add group and exit
- $qb = $this->dbConn->getQueryBuilder();
- $result = $qb->insert('groups')
- ->setValue('gid', $qb->createNamedParameter($gid))
- ->execute();
-
- if (!$result) {
- return false;
- }
+ // Add group
+ $result = $this->dbConn->insertIfNotExist('*PREFIX*groups', [
+ 'gid' => $gid,
+ ]);
// Add to cache
$this->groupCache[$gid] = $gid;
- return true;
+ return $result === 1;
}
/**
diff --git a/lib/private/group/interface.php b/lib/private/group/interface.php
index 5c7d4cf0b39..240a50fe961 100644
--- a/lib/private/group/interface.php
+++ b/lib/private/group/interface.php
@@ -24,63 +24,8 @@
*
*/
-interface OC_Group_Interface {
- /**
- * Check if backend implements actions
- * @param int $actions bitwise-or'ed actions
- * @return boolean
- *
- * Returns the supported actions as int to be
- * compared with \OC_Group_Backend::CREATE_GROUP etc.
- */
- public function implementsActions($actions);
-
- /**
- * is user in group?
- * @param string $uid uid of the user
- * @param string $gid gid of the group
- * @return bool
- *
- * Checks whether the user is member of a group or not.
- */
- public function inGroup($uid, $gid);
-
- /**
- * Get all groups a user belongs to
- * @param string $uid Name of the user
- * @return array an array of group names
- *
- * This function fetches all groups a user belongs to. It does not check
- * if the user exists at all.
- */
- public function getUserGroups($uid);
-
- /**
- * get a list of all groups
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array an array of group names
- *
- * Returns a list with all groups
- */
- public function getGroups($search = '', $limit = -1, $offset = 0);
-
- /**
- * check if a group exists
- * @param string $gid
- * @return bool
- */
- public function groupExists($gid);
-
- /**
- * get a list of all users in a group
- * @param string $gid
- * @param string $search
- * @param int $limit
- * @param int $offset
- * @return array an array of user ids
- */
- public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0);
-
-}
+/**
+ * Interface OC_Group_Interface
+ * @deprecated use the public \OCP\GroupInterface instead
+ */
+interface OC_Group_Interface extends \OCP\GroupInterface {}
diff --git a/lib/private/share20/defaultshareprovider.php b/lib/private/share20/defaultshareprovider.php
index 7a08ecb1210..f4c33d68b46 100644
--- a/lib/private/share20/defaultshareprovider.php
+++ b/lib/private/share20/defaultshareprovider.php
@@ -36,6 +36,9 @@ use OCP\Files\Node;
*/
class DefaultShareProvider implements IShareProvider {
+ // Special share type for user modified group shares
+ const SHARE_TYPE_USERGROUP = 2;
+
/** @var IDBConnection */
private $dbConn;
@@ -185,8 +188,18 @@ class DefaultShareProvider implements IShareProvider {
$qb = $this->dbConn->getQueryBuilder();
$qb->select('*')
->from('share')
- ->where($qb->expr()->eq('parent', $qb->createParameter('parent')))
- ->setParameter(':parent', $parent->getId())
+ ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
+ ->andWhere(
+ $qb->expr()->in(
+ 'share_type',
+ [
+ $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
+ $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
+ $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
+ $qb->expr()->literal(self::SHARE_TYPE_USERGROUP),
+ ]
+ )
+ )
->orderBy('id');
$cursor = $qb->execute();
@@ -210,8 +223,7 @@ class DefaultShareProvider implements IShareProvider {
$qb = $this->dbConn->getQueryBuilder();
$qb->delete('share')
- ->where($qb->expr()->eq('id', $qb->createParameter('id')))
- ->setParameter(':id', $share->getId());
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
try {
$qb->execute();
@@ -244,8 +256,18 @@ class DefaultShareProvider implements IShareProvider {
$qb->select('*')
->from('share')
- ->where($qb->expr()->eq('id', $qb->createParameter('id')))
- ->setParameter(':id', $id);
+ ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
+ ->andWhere(
+ $qb->expr()->in(
+ 'share_type',
+ [
+ $qb->expr()->literal(\OCP\Share::SHARE_TYPE_USER),
+ $qb->expr()->literal(\OCP\Share::SHARE_TYPE_GROUP),
+ $qb->expr()->literal(\OCP\Share::SHARE_TYPE_LINK),
+ $qb->expr()->literal(self::SHARE_TYPE_USERGROUP),
+ ]
+ )
+ );
$cursor = $qb->execute();
$data = $cursor->fetch();
diff --git a/lib/private/user.php b/lib/private/user.php
index 7f42374e2e3..7d1f21cc409 100644
--- a/lib/private/user.php
+++ b/lib/private/user.php
@@ -76,13 +76,13 @@ class OC_User {
/**
* Adds the backend to the list of used backends
*
- * @param string|OC_User_Interface $backend default: database The backend to use for user management
+ * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
* @return bool
*
* Set the User Authentication Module
*/
public static function useBackend($backend = 'database') {
- if ($backend instanceof OC_User_Interface) {
+ if ($backend instanceof \OCP\UserInterface) {
self::$_usedBackends[get_class($backend)] = $backend;
\OC::$server->getUserManager()->registerBackend($backend);
} else {
diff --git a/lib/private/user/backend.php b/lib/private/user/backend.php
index 075ff9e6e24..c8e3577d112 100644
--- a/lib/private/user/backend.php
+++ b/lib/private/user/backend.php
@@ -63,7 +63,7 @@ define('OC_USER_BACKEND_COUNT_USERS', 1 << 28);
* Abstract base class for user management. Provides methods for querying backend
* capabilities.
*/
-abstract class OC_User_Backend implements OC_User_Interface {
+abstract class OC_User_Backend implements \OCP\UserInterface {
/**
* error code for functions not provided by the user backend
*/
diff --git a/lib/private/user/interface.php b/lib/private/user/interface.php
index c935a92820b..b487a046c72 100644
--- a/lib/private/user/interface.php
+++ b/lib/private/user/interface.php
@@ -25,62 +25,8 @@
*
*/
-interface OC_User_Interface {
-
- /**
- * Check if backend implements actions
- * @param int $actions bitwise-or'ed actions
- * @return boolean
- *
- * Returns the supported actions as int to be
- * compared with \OC_User_Backend::CREATE_USER etc.
- */
- public function implementsActions($actions);
-
- /**
- * delete a user
- * @param string $uid The username of the user to delete
- * @return bool
- */
- public function deleteUser($uid);
-
- /**
- * Get a list of all users
- *
- * @param string $search
- * @param null|int $limit
- * @param null|int $offset
- * @return string[] an array of all uids
- */
- public function getUsers($search = '', $limit = null, $offset = null);
-
- /**
- * check if a user exists
- * @param string $uid the username
- * @return boolean
- */
- public function userExists($uid);
-
- /**
- * get display name of the user
- * @param string $uid user ID of the user
- * @return string display name
- */
- public function getDisplayName($uid);
-
- /**
- * Get a list of all display names and user ids.
- *
- * @param string $search
- * @param string|null $limit
- * @param string|null $offset
- * @return array an array of all displayNames (value) and the corresponding uids (key)
- */
- public function getDisplayNames($search = '', $limit = null, $offset = null);
-
- /**
- * Check if a user list is available or not
- * @return boolean if users can be listed or not
- */
- public function hasUserListings();
-}
+/**
+ * Interface OC_User_Interface
+ * @deprecated use the public \OCP\UserInterface instead
+ */
+interface OC_User_Interface extends \OCP\UserInterface {}
diff --git a/lib/private/user/user.php b/lib/private/user/user.php
index c6c608703eb..c2a6acc7664 100644
--- a/lib/private/user/user.php
+++ b/lib/private/user/user.php
@@ -35,6 +35,7 @@ use OCP\IImage;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IConfig;
+use OCP\UserInterface;
class User implements IUser {
/** @var string $uid */
@@ -43,7 +44,7 @@ class User implements IUser {
/** @var string $displayName */
private $displayName;
- /** @var \OC_User_Interface $backend */
+ /** @var UserInterface $backend */
private $backend;
/** @var bool $enabled */
@@ -69,7 +70,7 @@ class User implements IUser {
/**
* @param string $uid
- * @param \OC_User_Interface $backend
+ * @param UserInterface $backend
* @param \OC\Hooks\Emitter $emitter
* @param IConfig|null $config
* @param IURLGenerator $urlGenerator
diff --git a/lib/public/groupinterface.php b/lib/public/groupinterface.php
index dbadbfb0dcb..142b3dea046 100644
--- a/lib/public/groupinterface.php
+++ b/lib/public/groupinterface.php
@@ -32,9 +32,75 @@
namespace OCP;
/**
- * Interface GroupInterface
+ * TODO actually this is a IGroupBackend
*
* @package OCP
* @since 4.5.0
*/
-interface GroupInterface extends \OC_Group_Interface {}
+interface GroupInterface {
+
+ /**
+ * Check if backend implements actions
+ * @param int $actions bitwise-or'ed actions
+ * @return boolean
+ * @since 4.5.0
+ *
+ * Returns the supported actions as int to be
+ * compared with \OC_Group_Backend::CREATE_GROUP etc.
+ */
+ public function implementsActions($actions);
+
+ /**
+ * is user in group?
+ * @param string $uid uid of the user
+ * @param string $gid gid of the group
+ * @return bool
+ * @since 4.5.0
+ *
+ * Checks whether the user is member of a group or not.
+ */
+ public function inGroup($uid, $gid);
+
+ /**
+ * Get all groups a user belongs to
+ * @param string $uid Name of the user
+ * @return array an array of group names
+ * @since 4.5.0
+ *
+ * This function fetches all groups a user belongs to. It does not check
+ * if the user exists at all.
+ */
+ public function getUserGroups($uid);
+
+ /**
+ * get a list of all groups
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array an array of group names
+ * @since 4.5.0
+ *
+ * Returns a list with all groups
+ */
+ public function getGroups($search = '', $limit = -1, $offset = 0);
+
+ /**
+ * check if a group exists
+ * @param string $gid
+ * @return bool
+ * @since 4.5.0
+ */
+ public function groupExists($gid);
+
+ /**
+ * get a list of all users in a group
+ * @param string $gid
+ * @param string $search
+ * @param int $limit
+ * @param int $offset
+ * @return array an array of user ids
+ * @since 4.5.0
+ */
+ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0);
+
+}
diff --git a/lib/public/userinterface.php b/lib/public/userinterface.php
index 22f8d02c4f1..68831dcb503 100644
--- a/lib/public/userinterface.php
+++ b/lib/public/userinterface.php
@@ -32,9 +32,75 @@
namespace OCP;
/**
- * Interface UserInterface
+ * TODO actually this is a IUserBackend
*
* @package OCP
* @since 4.5.0
*/
-interface UserInterface extends \OC_User_Interface {}
+interface UserInterface {
+
+ /**
+ * Check if backend implements actions
+ * @param int $actions bitwise-or'ed actions
+ * @return boolean
+ *
+ * Returns the supported actions as int to be
+ * compared with \OC_User_Backend::CREATE_USER etc.
+ * @since 4.5.0
+ */
+ public function implementsActions($actions);
+
+ /**
+ * delete a user
+ * @param string $uid The username of the user to delete
+ * @return bool
+ * @since 4.5.0
+ */
+ public function deleteUser($uid);
+
+ /**
+ * Get a list of all users
+ *
+ * @param string $search
+ * @param null|int $limit
+ * @param null|int $offset
+ * @return string[] an array of all uids
+ * @since 4.5.0
+ */
+ public function getUsers($search = '', $limit = null, $offset = null);
+
+ /**
+ * check if a user exists
+ * @param string $uid the username
+ * @return boolean
+ * @since 4.5.0
+ */
+ public function userExists($uid);
+
+ /**
+ * get display name of the user
+ * @param string $uid user ID of the user
+ * @return string display name
+ * @since 4.5.0
+ */
+ public function getDisplayName($uid);
+
+ /**
+ * Get a list of all display names and user ids.
+ *
+ * @param string $search
+ * @param string|null $limit
+ * @param string|null $offset
+ * @return array an array of all displayNames (value) and the corresponding uids (key)
+ * @since 4.5.0
+ */
+ public function getDisplayNames($search = '', $limit = null, $offset = null);
+
+ /**
+ * Check if a user list is available or not
+ * @return boolean if users can be listed or not
+ * @since 4.5.0
+ */
+ public function hasUserListings();
+
+}
diff --git a/tests/lib/share20/defaultshareprovidertest.php b/tests/lib/share20/defaultshareprovidertest.php
index 166fbd25f17..4db6b2b14e7 100644
--- a/tests/lib/share20/defaultshareprovidertest.php
+++ b/tests/lib/share20/defaultshareprovidertest.php
@@ -375,9 +375,6 @@ class DefaultShareProviderTest extends \Test\TestCase {
->method('where')
->will($this->returnSelf());
$qb->expects($this->once())
- ->method('setParameter')
- ->will($this->returnSelf());
- $qb->expects($this->once())
->method('execute')
->will($this->throwException(new \Exception));