Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions apps/dav/lib/CalDAV/Schedule/IMipService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
use OC\URLGenerator;
use OCA\DAV\CalDAV\EventReader;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
Expand Down Expand Up @@ -41,12 +42,13 @@ class IMipService {

public function __construct(
private URLGenerator $urlGenerator,
private IConfig $config,
private IDBConnection $db,
private ISecureRandom $random,
private L10NFactory $l10nFactory,
private ITimeFactory $timeFactory,
private readonly IUserManager $userManager,
private readonly IUserConfig $userConfig,
private readonly IAppConfig $appConfig,
) {
$language = $this->l10nFactory->findGenericLanguage();
$locale = $this->l10nFactory->findLocale($language);
Expand Down Expand Up @@ -887,8 +889,8 @@ public function setL10nFromAttendee(Property $attendee) {
$users = $this->userManager->getByEmail($userAddress);
if ($users !== []) {
$user = array_shift($users);
$language = $this->config->getUserValue($user->getUID(), 'core', 'lang', null);
$locale = $this->config->getUserValue($user->getUID(), 'core', 'locale', null);
$language = $this->userConfig->getValueString($user->getUID(), 'core', 'lang', '') ?: null;
$locale = $this->userConfig->getValueString($user->getUID(), 'core', 'locale', '') ?: null;
}
// fallback to attendee LANGUAGE parameter if language not set
if ($language === null && isset($attendee['LANGUAGE']) && $attendee['LANGUAGE'] instanceof Parameter) {
Expand Down Expand Up @@ -996,20 +998,20 @@ public function getAbsoluteImagePath($path): string {
* The default is 'no', which matches old behavior, and is privacy preserving.
*
* To enable including attendees in invitation emails:
* % php occ config:app:set dav invitation_list_attendees --value yes
* % php occ config:app:set dav invitation_list_attendees --value yes --type bool
*
* @param IEMailTemplate $template
* @param IL10N $this->l10n
* @param VEvent $vevent
* @author brad2014 on github.com
*/
public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
if ($this->config->getAppValue('dav', 'invitation_list_attendees', 'no') === 'no') {
if (!$this->appConfig->getValueBool('dav', 'invitation_list_attendees')) {
return;
}

if (isset($vevent->ORGANIZER)) {
/** @var Property | Property\ICalendar\CalAddress $organizer */
/** @var Property&Property\ICalendar\CalAddress $organizer */
$organizer = $vevent->ORGANIZER;
$organizerEmail = substr($organizer->getNormalizedValue(), 7);
/** @var string|null $organizerName */
Expand Down Expand Up @@ -1039,8 +1041,14 @@ public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
$attendeesHTML = [];
$attendeesText = [];
foreach ($attendees as $attendee) {
/** @var Property&Property\ICalendar\CalAddress $attendee */
$attendeeEmail = substr($attendee->getNormalizedValue(), 7);
$attendeeName = isset($attendee['CN']) ? $attendee['CN']->getValue() : null;
$attendeeName = null;
if (isset($attendee['CN'])) {
/** @var Parameter $cn */
$cn = $attendee['CN'];
$attendeeName = $cn->getValue();
}
$attendeeHTML = sprintf('<a href="%s">%s</a>',
htmlspecialchars($attendee->getNormalizedValue()),
htmlspecialchars($attendeeName ?: $attendeeEmail));
Expand Down
6 changes: 4 additions & 2 deletions apps/dav/lib/CalDAV/TimezoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendar;
use OCP\Calendar\IManager;
use OCP\Config\IUserConfig;
use OCP\IConfig;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VTimeZone;
Expand All @@ -22,13 +23,14 @@ class TimezoneService {

public function __construct(
private IConfig $config,
private IUserConfig $userConfig,
private PropertyMapper $propertyMapper,
private IManager $calendarManager,
) {
}

public function getUserTimezone(string $userId): ?string {
$fromConfig = $this->config->getUserValue(
$fromConfig = $this->userConfig->getValueString(
$userId,
'core',
'timezone',
Expand All @@ -51,7 +53,7 @@ public function getUserTimezone(string $userId): ?string {
}

$principal = 'principals/users/' . $userId;
$uri = $this->config->getUserValue($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
$uri = $this->userConfig->getValueString($userId, 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI);
$calendars = $this->calendarManager->getCalendarsForPrincipal($principal);

/** @var ?VTimeZone $personalCalendarTimezone */
Expand Down
22 changes: 14 additions & 8 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipPluginCharsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use OCA\DAV\CalDAV\Schedule\IMipPlugin;
use OCA\DAV\CalDAV\Schedule\IMipService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Config\IUserConfig;
use OCP\Defaults;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IURLGenerator;
use OCP\IUser;
Expand Down Expand Up @@ -46,7 +46,7 @@ class IMipPluginCharsetTest extends TestCase {
// Dependencies
private Defaults&MockObject $defaults;
private IAppConfig&MockObject $appConfig;
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private IDBConnection&MockObject $db;
private IFactory $l10nFactory;
private IManager&MockObject $mailManager;
Expand Down Expand Up @@ -77,7 +77,8 @@ protected function setUp(): void {

// IMipService
$this->urlGenerator = $this->createMock(URLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->db = $this->createMock(IDBConnection::class);
$this->random = $this->createMock(ISecureRandom::class);
$l10n = $this->createMock(L10N::class);
Expand All @@ -92,19 +93,19 @@ protected function setUp(): void {
$this->userManager->method('getByEmail')->willReturn([]);
$this->imipService = new IMipService(
$this->urlGenerator,
$this->config,
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory,
$this->userManager
$this->userManager,
$this->userConfig,
$this->appConfig,
);

// EventComparisonService
$this->eventComparisonService = new EventComparisonService();

// IMipPlugin
$this->appConfig = $this->createMock(IAppConfig::class);
$message = new \OC\Mail\Message(new Email(), false);
$this->mailer = $this->createMock(IMailer::class);
$this->mailer->method('createMessage')
Expand Down Expand Up @@ -177,8 +178,13 @@ public function testCharsetMailer(): void {
public function testCharsetMailProvider(): void {
// Arrange
$this->appConfig->method('getValueBool')
->with('core', 'mail_providers_enabled', true)
->willReturn(true);
->willReturnCallback(function ($app, $key, $default) {
if ($app === 'core') {
$this->assertEquals($key, 'mail_providers_enabled');
return true;
}
return $default;
});
$mailMessage = new MailProviderMessage();
$mailService = $this->createMockForIntersectionOfInterfaces([IService::class, IMessageSend::class]);
$mailService->method('initiateMessage')
Expand Down
14 changes: 9 additions & 5 deletions apps/dav/tests/unit/CalDAV/Schedule/IMipServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
use OCA\DAV\CalDAV\EventReader;
use OCA\DAV\CalDAV\Schedule\IMipService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
use OCP\Config\IUserConfig;
use OCP\IAppConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\IUserManager;
Expand All @@ -26,7 +27,8 @@

class IMipServiceTest extends TestCase {
private URLGenerator&MockObject $urlGenerator;
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private IAppConfig&MockObject $appConfig;
private IDBConnection&MockObject $db;
private ISecureRandom&MockObject $random;
private IFactory&MockObject $l10nFactory;
Expand All @@ -47,7 +49,8 @@ protected function setUp(): void {
parent::setUp();

$this->urlGenerator = $this->createMock(URLGenerator::class);
$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->appConfig = $this->createMock(IAppConfig::class);
$this->db = $this->createMock(IDBConnection::class);
$this->random = $this->createMock(ISecureRandom::class);
$this->l10nFactory = $this->createMock(IFactory::class);
Expand All @@ -63,12 +66,13 @@ protected function setUp(): void {
->willReturn($this->l10n);
$this->service = new IMipService(
$this->urlGenerator,
$this->config,
$this->db,
$this->random,
$this->l10nFactory,
$this->timeFactory,
$this->userManager
$this->userManager,
$this->userConfig,
$this->appConfig,
);

// construct calendar with a 1 hour event and same start/end time zones
Expand Down
29 changes: 17 additions & 12 deletions apps/dav/tests/unit/CalDAV/TimezoneServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
namespace OCA\DAV\Tests\unit\CalDAV;

use DateTimeZone;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\CalendarImpl;
use OCA\DAV\CalDAV\TimezoneService;
use OCA\DAV\Db\Property;
use OCA\DAV\Db\PropertyMapper;
use OCP\Calendar\ICalendar;
use OCP\Calendar\IManager;
use OCP\Config\IUserConfig;
use OCP\IConfig;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\VObject\Component\VTimeZone;
use Test\TestCase;

class TimezoneServiceTest extends TestCase {
private IConfig&MockObject $config;
private IUserConfig&MockObject $userConfig;
private PropertyMapper&MockObject $propertyMapper;
private IManager&MockObject $calendarManager;
private TimezoneService $service;
Expand All @@ -30,19 +33,21 @@ protected function setUp(): void {
parent::setUp();

$this->config = $this->createMock(IConfig::class);
$this->userConfig = $this->createMock(IUserConfig::class);
$this->propertyMapper = $this->createMock(PropertyMapper::class);
$this->calendarManager = $this->createMock(IManager::class);

$this->service = new TimezoneService(
$this->config,
$this->userConfig,
$this->propertyMapper,
$this->calendarManager,
);
}

public function testGetUserTimezoneFromSettings(): void {
$this->config->expects(self::once())
->method('getUserValue')
$this->userConfig->expects(self::once())
->method('getValueString')
->with('test123', 'core', 'timezone', '')
->willReturn('Europe/Warsaw');

Expand All @@ -52,8 +57,8 @@ public function testGetUserTimezoneFromSettings(): void {
}

public function testGetUserTimezoneFromAvailability(): void {
$this->config->expects(self::once())
->method('getUserValue')
$this->userConfig->expects(self::once())
->method('getValueString')
->with('test123', 'core', 'timezone', '')
->willReturn('');
$property = new Property();
Expand All @@ -76,11 +81,11 @@ public function testGetUserTimezoneFromAvailability(): void {
}

public function testGetUserTimezoneFromPersonalCalendar(): void {
$this->config->expects(self::exactly(2))
->method('getUserValue')
$this->userConfig->expects(self::exactly(2))
->method('getValueString')
->willReturnMap([
['test123', 'core', 'timezone', '', ''],
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
['test123', 'core', 'timezone', '', false, ''],
['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');
Expand All @@ -105,11 +110,11 @@ public function testGetUserTimezoneFromPersonalCalendar(): void {
}

public function testGetUserTimezoneFromAny(): void {
$this->config->expects(self::exactly(2))
->method('getUserValue')
$this->userConfig->expects(self::exactly(2))
->method('getValueString')
->willReturnMap([
['test123', 'core', 'timezone', '', ''],
['test123', 'dav', 'defaultCalendar', '', 'personal-1'],
['test123', 'core', 'timezone', '', false, ''],
['test123', 'dav', 'defaultCalendar', CalDavBackend::PERSONAL_CALENDAR_URI, false, 'personal-1'],
]);
$other = $this->createMock(ICalendar::class);
$other->method('getUri')->willReturn('other');
Expand Down
10 changes: 7 additions & 3 deletions apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use OCP\App\IAppManager;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Command\IBus;
use OCP\Config\IUserConfig;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -38,6 +39,7 @@
use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage;
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IRequest;
Expand Down Expand Up @@ -368,12 +370,14 @@ public static function move2trash($file_path, $ownerOnly = false) {
}

private static function getConfiguredTrashbinSize(string $user): int|float {
$config = Server::get(IConfig::class);
$userTrashbinSize = $config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1');
$userConfig = Server::get(IUserConfig::class);
$userTrashbinSize = $userConfig->getValueString($user, 'files_trashbin', 'trashbin_size', '-1');
if (is_numeric($userTrashbinSize) && ($userTrashbinSize > -1)) {
return Util::numericToNumber($userTrashbinSize);
}
$systemTrashbinSize = $config->getAppValue('files_trashbin', 'trashbin_size', '-1');

$appConfig = Server::get(IAppConfig::class);
$systemTrashbinSize = $appConfig->getValueString('files_trashbin', 'trashbin_size', '-1');
if (is_numeric($systemTrashbinSize)) {
return Util::numericToNumber($systemTrashbinSize);
}
Expand Down
Loading
Loading