Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
Maxence Lange 2021-05-20 23:27:07 -01:00
parent e2979b01c4
commit 04805b2e7f
7 changed files with 63 additions and 190 deletions

View file

@ -1,112 +0,0 @@
<?php
/**
* Circles - Bring cloud-users closer together.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2017
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Circles\Api;
use OCA\Circles\AppInfo\Application;
use OCA\Circles\Model\DeprecatedCircle;
use OCA\Circles\Model\DeprecatedMember;
use OCA\Circles\Service\CirclesService;
use OCA\Circles\Service\MiscService;
use OCP\Share;
/**
* ############### WARNING #################
* ###
* ### This file is needed and used by Nextcloud 12 and lower.
* ###
*
* @package OCA\Circles\Api
*/
class Sharees {
protected static function getContainer() {
$app = \OC::$server->query(Application::class);
return $app->getContainer();
}
/**
* returns circles with
*
* @param $search
*
* @return array<string,array>
*/
// public static function search($search, $limit, $offset) {
public static function search($search) {
$c = self::getContainer();
$userId = \OC::$server->getUserSession()
->getUser()
->getUID();
$data = $c->query(CirclesService::class)
->listCircles($userId, DeprecatedCircle::CIRCLES_ALL, $search, DeprecatedMember::LEVEL_MEMBER);
$result = array(
'exact' => ['circles'],
'circles' => []
);
foreach ($data as $entry) {
self::addResultEntry(
$result, $entry, (strtolower($entry->getName()) === strtolower($search))
);
}
return $result;
}
/**
* @param $result
* @param DeprecatedCircle $entry
* @param bool $exact
*
*/
private static function addResultEntry(&$result, $entry, $exact = false) {
$arr = [
'label' => $entry->getName(),
'value' => [
'shareType' => Share::SHARE_TYPE_CIRCLE,
'shareWith' => $entry->getUniqueId(),
'circleInfo' => $entry->getInfo(),
'circleOwner' => $entry->getOwner()
->getCachedName()
],
];
if ($exact) {
$result['exact']['circles'][] = $arr;
} else {
$result['circles'][] = $arr;
}
}
}

View file

@ -33,15 +33,9 @@ namespace OCA\Circles\Collaboration\v2;
use daita\MySmallPhpTools\Model\SimpleDataStore;
use Exception;
use OC\Share20\Share;
use OC\User\NoUserException;
use OCA\Circles\Exceptions\FederatedUserException;
use OCA\Circles\Exceptions\FederatedUserNotFoundException;
use OCA\Circles\Exceptions\InitiatorNotFoundException;
use OCA\Circles\Exceptions\InvalidIdException;
use OCA\Circles\Exceptions\SingleCircleNotFoundException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\FederatedUserService;
use OCP\Collaboration\Collaborators\ISearchPlugin;
@ -83,42 +77,31 @@ class CollaboratorSearchPlugin implements ISearchPlugin {
* @param ISearchResult $searchResult
*
* @return bool
* @throws FederatedUserException
* @throws FederatedUserNotFoundException
* @throws InitiatorNotFoundException
* @throws InvalidIdException
* @throws SingleCircleNotFoundException
*/
public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
$this->federatedUserService->initCurrentUser();
$wide = $exact = [];
$filterCircle = new Circle();
$filterCircle->setName($search)
->setDisplayName($search);
$filterMember = new Member();
$filterMember->importFromIFederatedUser($this->federatedUserService->getCurrentUser());
$filterMember->setLevel(Member::LEVEL_MEMBER);
$circles = $this->circleService->getCircles(
$filterCircle, $filterMember,
new SimpleDataStore(
[
'limit' => $limit,
'offset' => $offset
]
)
);
try {
$this->federatedUserService->initCurrentUser();
$circles = $this->circleService->getCircles(
$filterCircle, null,
new SimpleDataStore(
[
'limit' => $limit,
'offset' => $offset
]
)
);
} catch (Exception $e) {
return false;
}
foreach ($circles as $circle) {
try {
$entry = $this->addResultEntry($circle);
} catch (NoUserException $e) {
continue;
}
$entry = $this->addResultEntry($circle);
if (strtolower($circle->getName()) === strtolower($search)) {
$exact[] = $entry;
} else {

View file

@ -36,8 +36,6 @@ use OCA\Circles\Exceptions\SingleCircleNotFoundException;
use OCA\Circles\Model\Member;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\FederatedUserService;
use OCP\IL10N;
use OCP\IUserManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@ -52,12 +50,6 @@ use Symfony\Component\Console\Output\OutputInterface;
class CirclesCreate extends Base {
/** @var IL10N */
private $l10n;
/** @var IUserManager */
private $userManager;
/** @var FederatedUserService */
private $federatedUserService;
@ -68,18 +60,14 @@ class CirclesCreate extends Base {
/**
* CirclesCreate constructor.
*
* @param IL10N $l10n
* @param IUserManager $userManager
* @param FederatedUserService $federatedUserService
* @param CircleService $circleService
*/
public function __construct(
IL10N $l10n, IUserManager $userManager, FederatedUserService $federatedUserService,
FederatedUserService $federatedUserService,
CircleService $circleService
) {
parent::__construct();
$this->l10n = $l10n;
$this->userManager = $userManager;
$this->federatedUserService = $federatedUserService;
$this->circleService = $circleService;
@ -130,7 +118,9 @@ class CirclesCreate extends Base {
throw $e;
}
$output->writeln(json_encode($outcome, JSON_PRETTY_PRINT));
if (strtolower($input->getOption('output')) !== 'none') {
$output->writeln(json_encode($outcome, JSON_PRETTY_PRINT));
}
return 0;
}

View file

@ -146,7 +146,9 @@ class MembersAdd extends Base {
throw $e;
}
$output->writeln(json_encode($outcome, JSON_PRETTY_PRINT));
if (strtolower($input->getOption('output')) !== 'none') {
$output->writeln(json_encode($outcome, JSON_PRETTY_PRINT));
}
return 0;
}

View file

@ -1085,7 +1085,7 @@ class CoreQueryBuilder extends NC22ExtendedQueryBuilder {
*
* @return ICompositeExpression
*/
private function limitRemoteVisibility_Sensitive_Members(string $alias = 'ri'): ICompositeExpression {
private function limitRemoteVisibility_Sensitive_Members(string $alias): ICompositeExpression {
$expr = $this->expr();
$andPassive = $expr->andX();
$andPassive->add(
@ -1137,12 +1137,17 @@ class CoreQueryBuilder extends NC22ExtendedQueryBuilder {
$aliasStorages = $this->generateAlias($aliasFileCache, self::STORAGES);
$this->generateSelectAlias(
CoreRequestBuilder::$outsideTables[self::FILE_CACHE],
CoreRequestBuilder::$outsideTables[CoreRequestBuilder::TABLE_FILE_CACHE],
$aliasFileCache,
$aliasFileCache,
[]
)
->generateSelectAlias(CoreRequestBuilder::$outsideTables[self::STORAGES], $aliasStorages, $aliasStorages, [])
->generateSelectAlias(
CoreRequestBuilder::$outsideTables[CoreRequestBuilder::TABLE_STORAGES],
$aliasStorages,
$aliasStorages,
[]
)
->leftJoin(
$aliasShare, CoreRequestBuilder::TABLE_FILE_CACHE, $aliasFileCache,
$expr->eq($aliasShare . '.file_source', $aliasFileCache . '.fileid')
@ -1176,8 +1181,13 @@ class CoreQueryBuilder extends NC22ExtendedQueryBuilder {
)
);
$this->selectAlias($aliasShareChild . '.id', 'child_id');
$this->selectAlias($aliasShareChild . '.file_target', 'child_file_target');
$this->generateSelectAlias(
['id', 'file_target', 'permissions'],
$aliasShareChild,
'child_',
[]
);
// $this->selectAlias($aliasShareParent . '.permissions', 'parent_perms');
}

View file

@ -390,6 +390,30 @@ class CircleService {
}
/**
* @param string $circleId
* @param int $filter
*
* @return Circle
* @throws CircleNotFoundException
* @throws InitiatorNotFoundException
* @throws RequestBuilderException
*/
public function getCircle(
string $circleId,
int $filter = Circle::CFG_BACKEND | Circle::CFG_SINGLE | Circle::CFG_HIDDEN
): Circle {
$this->federatedUserService->mustHaveCurrentUser();
return $this->circleRequest->getCircle(
$circleId,
$this->federatedUserService->getCurrentUser(),
$this->federatedUserService->getRemoteInstance(),
$filter
);
}
/**
* @param Circle|null $circleFilter
* @param Member|null $memberFilter
@ -397,6 +421,7 @@ class CircleService {
*
* @return Circle[]
* @throws InitiatorNotFoundException
* @throws RequestBuilderException
*/
public function getCircles(
?Circle $circleFilter = null,
@ -426,30 +451,6 @@ class CircleService {
}
/**
* @param string $circleId
* @param int $filter
*
* @return Circle
* @throws CircleNotFoundException
* @throws InitiatorNotFoundException
* @throws RequestBuilderException
*/
public function getCircle(
string $circleId,
int $filter = Circle::CFG_BACKEND | Circle::CFG_SINGLE | Circle::CFG_HIDDEN
): Circle {
$this->federatedUserService->mustHaveCurrentUser();
return $this->circleRequest->getCircle(
$circleId,
$this->federatedUserService->getCurrentUser(),
$this->federatedUserService->getRemoteInstance(),
$filter
);
}
/**
* @param Circle $circle
*

View file

@ -402,7 +402,6 @@ class FederatedEventService extends NC22Signature {
if ($event->isAsync()) {
$wrapper->setInstance($this->configService->getLoopbackInstance());
$this->eventWrapperRequest->save($wrapper);
echo json_encode($wrapper);
}
foreach ($instances as $instance) {