Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed Jan 20, 2022
1 parent b0957db commit 1a5c0d8
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 25 deletions.
13 changes: 8 additions & 5 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
namespace OCA\DAV\AppInfo;

use Exception;
use OC\Files\AppData\Factory as AppDataFactory;
use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob;
use OCA\DAV\CalDAV\Activity\Backend;
use OCA\DAV\CalDAV\CalendarProvider;
Expand Down Expand Up @@ -122,7 +123,7 @@ public function register(IRegistrationContext $context): void {
$server = $c->get(IServerContainer::class);

return new PhotoCache(
$server->getAppDataDir('dav-photocache'),
$server->get(AppDataFactory::class)->get('dav-photocache'),
$c->get(LoggerInterface::class)
);
});
Expand Down Expand Up @@ -280,16 +281,18 @@ private function setupContactsProvider(IContactsManager $contactsManager,
IAppContainer $container,
string $userID): void {
/** @var ContactsManager $cm */
$cm = $container->query(ContactsManager::class);
$urlGenerator = $container->getServer()->get(IURLGenerator::class);
$cm = $container->get(ContactsManager::class);
/** @var IURLGenerator $urlGenerator */
$urlGenerator = $container->get(IURLGenerator::class);
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
}

private function setupSystemContactsProvider(IContactsManager $contactsManager,
IAppContainer $container): void {
/** @var ContactsManager $cm */
$cm = $container->query(ContactsManager::class);
$urlGenerator = $container->getServer()->get(IURLGenerator::class);
$cm = $container->get(ContactsManager::class);
/** @var IURLGenerator $urlGenerator */
$urlGenerator = $container->get(IURLGenerator::class);
$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
}

Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/CardDAV/CardDavBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function getAddressBooksForUser($principalUri) {
/**
* @throws Exception
*/
public function getUsersOwnAddressBooks($principalUri): array {
public function getUsersOwnAddressBooks(string $principalUri): array {
return array_values($this->getUserAddressBooks($principalUri));
}

Expand Down Expand Up @@ -377,10 +377,10 @@ public function updateAddressBook($addressBookId, PropPatch $propPatch) {
$query->where($query->expr()->eq('id', $query->createNamedParameter($addressBookId)))
->executeStatement();

$this->addChange($addressBookId, "", 2);
$this->addChange((int) $addressBookId, "", 2);

$addressBookRow = $this->getAddressBookById((int)$addressBookId);
$shares = $this->getShares($addressBookId);
$shares = $this->getShares((int) $addressBookId);
$this->dispatcher->dispatchTyped(new AddressBookUpdatedEvent((int)$addressBookId, $addressBookRow, $shares, $mutations));

return true;
Expand Down Expand Up @@ -536,7 +536,7 @@ public function getCards($addressBookId) {
*
* @param mixed $addressBookId
* @param string $cardUri
* @return array|false
* @return array
* @throws Exception
*/
public function getCard($addressBookId, $cardUri) {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CardDAV/ContactsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function setupSystemContactsProvider(IManager $cm, IURLGenerator $urlGene
*/
private function register(IManager $cm, $addressBooks, $urlGenerator) {
foreach ($addressBooks as $addressBookInfo) {
$addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo, $this->l10n);
$addressBook = new AddressBook($this->backend, $addressBookInfo, $this->l10n);
$cm->registerAddressBook(
new AddressBookImpl(
$addressBook,
Expand Down
12 changes: 9 additions & 3 deletions apps/dav/lib/CardDAV/UserAddressBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@
use OCP\IConfig;
use OCP\IL10N;
use OCP\L10N\IFactory;
use Sabre\CardDAV\AddressBookHome;
use Sabre\CardDAV\Backend;
use Sabre\DAV\Exception\InvalidResourceType;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\CardDAV\IAddressBook;
use function array_map;
use Sabre\DAV\MkCol;

class UserAddressBooks extends \Sabre\CardDAV\AddressBookHome {
class UserAddressBooks extends AddressBookHome {

/** @var IL10N */
/** @var IL10N|null */
protected $l10n;

/** @var IConfig */
/** @var IConfig|null */
protected $config;

/** @var PluginManager */
Expand Down Expand Up @@ -87,6 +89,10 @@ public function getChildren() {
return array_merge($objects, ...$objectsFromPlugins);
}

/**
* @throws InvalidResourceType
* @throws MethodNotAllowed
*/
public function createExtendedCollection($name, MkCol $mkCol) {
if (ExternalAddressBook::doesViolateReservedName($name)) {
throw new MethodNotAllowed('The resource you tried to create has a reserved name');
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/DAV/Sharing/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private function unshare($shareable, $element) {
* @param int $resourceId
* @return array
*/
public function getShares($resourceId) {
public function getShares(int $resourceId): array {
$query = $this->db->getQueryBuilder();
$result = $query->select(['principaluri', 'access'])
->from('dav_shares')
Expand Down
7 changes: 6 additions & 1 deletion apps/dav/lib/Files/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
*/
namespace OCA\DAV\Files;

use OC\User\NoUserException;
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\NotPermittedException;
use OCP\IUserSession;
use Sabre\DAV\INode;
use Sabre\DAV\SimpleCollection;
use Sabre\DAVACL\AbstractPrincipalCollection;
use function Sabre\Uri\split;

class RootCollection extends AbstractPrincipalCollection {

Expand All @@ -43,9 +46,11 @@ class RootCollection extends AbstractPrincipalCollection {
*
* @param array $principalInfo
* @return INode
* @throws NotPermittedException
* @throws NoUserException
*/
public function getChildForPrincipal(array $principalInfo) {
[,$name] = \Sabre\Uri\split($principalInfo['uri']);
[,$name] = split($principalInfo['uri']);
$user = \OC::$server->get(IUserSession::class)->getUser();
if (is_null($user) || $name !== $user->getUID()) {
// a user is only allowed to see their own home contents, so in case another collection
Expand Down
3 changes: 2 additions & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

use OC\Authentication\TwoFactorAuth\Manager as TwoFactorAuthManager;
use OC\EventDispatcher\SymfonyAdapter;
use OC\Files\AppData\Factory as AppDataFactory;
use OC\Security\Bruteforce\Throttler;
use OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin;
use OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin;
Expand Down Expand Up @@ -210,7 +211,7 @@ public function __construct(IRequest $request, $baseUri) {
$this->server->addPlugin(new MultiGetExportPlugin());
$this->server->addPlugin(new HasPhotoPlugin());
$this->server->addPlugin(new ImageExportPlugin(new PhotoCache(
\OC::$server->getAppDataDir('dav-photocache'),
\OC::$server->get(AppDataFactory::class)->get('dav-photocache'),
\OC::$server->get(LoggerInterface::class))
));
}
Expand Down
19 changes: 10 additions & 9 deletions apps/dav/lib/Traits/PrincipalProxyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use OCA\DAV\CalDAV\Proxy\Proxy;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use Sabre\DAV\Exception;
use function Sabre\Uri\split;

/**
* Trait PrincipalTrait
Expand Down Expand Up @@ -75,7 +76,7 @@ public function getGroupMemberSet($principal) {
* @throws Exception
*/
public function getGroupMembership($principal, $needGroups = false) {
[$prefix, $name] = \Sabre\Uri\split($principal);
[$prefix, $name] = split($principal);

if ($prefix !== $this->principalPrefix) {
return [];
Expand Down Expand Up @@ -111,7 +112,7 @@ public function getGroupMembership($principal, $needGroups = false) {
* @throws Exception|\OCP\DB\Exception
*/
public function setGroupMemberSet($principal, array $members) {
[$principalUri, $target] = \Sabre\Uri\split($principal);
[$principalUri, $target] = split($principal);

if ($target !== 'calendar-proxy-write' && $target !== 'calendar-proxy-read') {
throw new Exception('Setting members of the group is not supported yet');
Expand All @@ -127,11 +128,11 @@ public function setGroupMemberSet($principal, array $members) {
$permission |= ProxyMapper::PERMISSION_WRITE;
}

[$prefix, $owner] = \Sabre\Uri\split($principalUri);
[$prefix, $owner] = split($principalUri);
$proxies = $this->proxyMapper->getProxiesOf($principalUri);

foreach ($members as $member) {
[$prefix, $name] = \Sabre\Uri\split($member);
[$prefix, $name] = split($member);

if ($prefix !== $this->principalPrefix) {
throw new Exception('Invalid member group prefix: ' . $prefix);
Expand Down Expand Up @@ -180,8 +181,8 @@ public function setGroupMemberSet($principal, array $members) {
* @return bool
*/
private function isProxyPrincipal(string $principalUri):bool {
[$realPrincipalUri, $proxy] = \Sabre\Uri\split($principalUri);
[$prefix, $userId] = \Sabre\Uri\split($realPrincipalUri);
[$realPrincipalUri, $proxy] = split($principalUri);
[$prefix, $userId] = split($realPrincipalUri);

if (!isset($prefix, $userId)) {
return false;
Expand All @@ -199,7 +200,7 @@ private function isProxyPrincipal(string $principalUri):bool {
* @return bool
*/
private function isReadProxyPrincipal(string $principalUri):bool {
[, $proxy] = \Sabre\Uri\split($principalUri);
[, $proxy] = split($principalUri);
return $proxy === 'calendar-proxy-read';
}

Expand All @@ -208,7 +209,7 @@ private function isReadProxyPrincipal(string $principalUri):bool {
* @return bool
*/
private function isWriteProxyPrincipal(string $principalUri):bool {
[, $proxy] = \Sabre\Uri\split($principalUri);
[, $proxy] = split($principalUri);
return $proxy === 'calendar-proxy-write';
}

Expand All @@ -217,7 +218,7 @@ private function isWriteProxyPrincipal(string $principalUri):bool {
* @return string
*/
private function getPrincipalUriFromProxyPrincipal(string $principalUri):string {
[$realPrincipalUri, ] = \Sabre\Uri\split($principalUri);
[$realPrincipalUri, ] = split($principalUri);
return $realPrincipalUri;
}
}

0 comments on commit 1a5c0d8

Please sign in to comment.