-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sync carddav delete contact requests (#5835)
- Loading branch information
Showing
14 changed files
with
500 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace App\Jobs\Dav; | ||
|
||
use Illuminate\Bus\Batch; | ||
use Illuminate\Bus\Batchable; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use App\Models\Account\AddressBookSubscription; | ||
|
||
class DeleteMultipleVCard implements ShouldQueue | ||
{ | ||
use Batchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* @var AddressBookSubscription | ||
*/ | ||
private $subscription; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $hrefs; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @param AddressBookSubscription $subscription | ||
* @param array $hrefs | ||
* @return void | ||
*/ | ||
public function __construct(AddressBookSubscription $subscription, array $hrefs) | ||
{ | ||
$this->subscription = $subscription->withoutRelations(); | ||
$this->hrefs = $hrefs; | ||
} | ||
|
||
/** | ||
* Update the Last Consulted At field for the given contact. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
if (! $this->batching()) { | ||
return; // @codeCoverageIgnore | ||
} | ||
|
||
$batch = $this->batch(); | ||
|
||
collect($this->hrefs) | ||
->each(function ($href) use ($batch) { | ||
$this->deleteVCard($href, $batch); | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the contact. | ||
* | ||
* @param string $href | ||
* @param \Illuminate\Bus\Batch $batch | ||
* @return void | ||
*/ | ||
private function deleteVCard(string $href, Batch $batch): void | ||
{ | ||
$batch->add([ | ||
new DeleteVCard($this->subscription, $href), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace App\Jobs\Dav; | ||
|
||
use Illuminate\Bus\Batchable; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use App\Models\Account\AddressBookSubscription; | ||
|
||
class DeleteVCard implements ShouldQueue | ||
{ | ||
use Batchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
/** | ||
* @var AddressBookSubscription | ||
*/ | ||
private $subscription; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $uri; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @param AddressBookSubscription $subscription | ||
* @param string $uri | ||
* @return void | ||
*/ | ||
public function __construct(AddressBookSubscription $subscription, string $uri) | ||
{ | ||
$this->subscription = $subscription->withoutRelations(); | ||
$this->uri = $uri; | ||
} | ||
|
||
/** | ||
* Send Delete contact. | ||
* | ||
* @return void | ||
*/ | ||
public function handle(): void | ||
{ | ||
if (! $this->batching()) { | ||
return; | ||
} | ||
|
||
Log::info(__CLASS__.' '.$this->uri); | ||
|
||
$this->subscription->getClient() | ||
->request('DELETE', $this->uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace App\Services\DavClient\Utils\Model; | ||
|
||
class ContactDeleteDto extends ContactDto | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Jobs\Dav; | ||
|
||
use Tests\TestCase; | ||
use App\Models\User\User; | ||
use App\Jobs\Dav\DeleteVCard; | ||
use Illuminate\Bus\PendingBatch; | ||
use Illuminate\Support\Facades\Bus; | ||
use App\Jobs\Dav\DeleteMultipleVCard; | ||
use Illuminate\Bus\DatabaseBatchRepository; | ||
use App\Models\Account\AddressBookSubscription; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
|
||
class DeleteMultipleVCardTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function it_delete_cards() | ||
{ | ||
$fake = Bus::fake(); | ||
|
||
$user = factory(User::class)->create(); | ||
$addressBookSubscription = AddressBookSubscription::factory()->create([ | ||
'account_id' => $user->account_id, | ||
'user_id' => $user->id, | ||
]); | ||
|
||
$pendingBatch = $fake->batch([ | ||
$job = new DeleteMultipleVCard($addressBookSubscription, ['https://test/dav/uri']), | ||
]); | ||
$batch = $pendingBatch->dispatch(); | ||
|
||
$fake->assertBatched(function (PendingBatch $pendingBatch) { | ||
$this->assertCount(1, $pendingBatch->jobs); | ||
$this->assertInstanceOf(DeleteMultipleVCard::class, $pendingBatch->jobs->first()); | ||
|
||
return true; | ||
}); | ||
|
||
$batch = app(DatabaseBatchRepository::class)->store($pendingBatch); | ||
$job->withBatchId($batch->id)->handle(); | ||
|
||
$fake->assertDispatched(function (DeleteVCard $updateVCard) { | ||
$uri = $this->getPrivateValue($updateVCard, 'uri'); | ||
$this->assertEquals('https://test/dav/uri', $uri); | ||
|
||
return true; | ||
}); | ||
} | ||
} |
Oops, something went wrong.