Merge pull request #19986 from nextcloud/bugfix/19980/fix_uid_as_uri
RefreshWebcalService: randomly generate calendar-object uri
This commit is contained in:
commit
3427653676
|
@ -47,6 +47,7 @@ use Sabre\VObject\InvalidDataException;
|
||||||
use Sabre\VObject\ParseException;
|
use Sabre\VObject\ParseException;
|
||||||
use Sabre\VObject\Reader;
|
use Sabre\VObject\Reader;
|
||||||
use Sabre\VObject\Splitter\ICalendar;
|
use Sabre\VObject\Splitter\ICalendar;
|
||||||
|
use Sabre\VObject\UUIDUtil;
|
||||||
use function count;
|
use function count;
|
||||||
|
|
||||||
class RefreshWebcalService {
|
class RefreshWebcalService {
|
||||||
|
@ -113,7 +114,6 @@ class RefreshWebcalService {
|
||||||
|
|
||||||
while ($vObject = $splitter->getNext()) {
|
while ($vObject = $splitter->getNext()) {
|
||||||
/** @var Component $vObject */
|
/** @var Component $vObject */
|
||||||
$uid = null;
|
|
||||||
$compName = null;
|
$compName = null;
|
||||||
|
|
||||||
foreach ($vObject->getComponents() as $component) {
|
foreach ($vObject->getComponents() as $component) {
|
||||||
|
@ -121,7 +121,6 @@ class RefreshWebcalService {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = $component->{'UID'}->getValue();
|
|
||||||
$compName = $component->name;
|
$compName = $component->name;
|
||||||
|
|
||||||
if ($stripAlarms) {
|
if ($stripAlarms) {
|
||||||
|
@ -136,7 +135,7 @@ class RefreshWebcalService {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uri = $uid . '.ics';
|
$uri = $this->getRandomCalendarObjectUri();
|
||||||
$calendarData = $vObject->serialize();
|
$calendarData = $vObject->serialize();
|
||||||
try {
|
try {
|
||||||
$this->calDavBackend->createCalendarObject($subscription['id'], $uri, $calendarData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
|
$this->calDavBackend->createCalendarObject($subscription['id'], $uri, $calendarData, CalDavBackend::CALENDAR_TYPE_SUBSCRIPTION);
|
||||||
|
@ -413,4 +412,13 @@ class RefreshWebcalService {
|
||||||
|
|
||||||
return $cleanURL;
|
return $cleanURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a random uri for a calendar-object
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRandomCalendarObjectUri():string {
|
||||||
|
return UUIDUtil::getUUID() . '.ics';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,14 @@ class RefreshWebcalServiceTest extends TestCase {
|
||||||
* @dataProvider runDataProvider
|
* @dataProvider runDataProvider
|
||||||
*/
|
*/
|
||||||
public function testRun(string $body, string $contentType, string $result) {
|
public function testRun(string $body, string $contentType, string $result) {
|
||||||
$refreshWebcalService = new RefreshWebcalService($this->caldavBackend,
|
$refreshWebcalService = $this->getMockBuilder(RefreshWebcalService::class)
|
||||||
$this->clientService, $this->config, $this->logger);
|
->setMethods(['getRandomCalendarObjectUri'])
|
||||||
|
->setConstructorArgs([$this->caldavBackend, $this->clientService, $this->config, $this->logger])
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$refreshWebcalService
|
||||||
|
->method('getRandomCalendarObjectUri')
|
||||||
|
->willReturn('uri-1.ics');
|
||||||
|
|
||||||
$this->caldavBackend->expects($this->once())
|
$this->caldavBackend->expects($this->once())
|
||||||
->method('getSubscriptionsForUser')
|
->method('getSubscriptionsForUser')
|
||||||
|
@ -130,7 +136,7 @@ class RefreshWebcalServiceTest extends TestCase {
|
||||||
|
|
||||||
$this->caldavBackend->expects($this->once())
|
$this->caldavBackend->expects($this->once())
|
||||||
->method('createCalendarObject')
|
->method('createCalendarObject')
|
||||||
->with(42, '12345.ics', $result, 1);
|
->with(42, 'uri-1.ics', $result, 1);
|
||||||
|
|
||||||
$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
|
$refreshWebcalService->refreshSubscription('principals/users/testuser', 'sub123');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue