From 44e996b4d181b299930d955985f8a7bf75e5b71c Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Mon, 16 Oct 2023 19:22:35 +0200 Subject: [PATCH 1/3] fix: fix uploadcare --- .../Web/ViewHelpers/ContactShowViewHelper.php | 4 ++-- .../Web/ViewHelpers/ModuleDocumentsViewHelper.php | 2 +- .../ViewHelpers/ContactPhotosIndexViewHelper.php | 2 +- .../Web/ViewHelpers/ModulePhotosViewHelper.php | 2 +- .../Web/ViewHelpers/PostEditViewHelper.php | 2 +- .../Web/ViewHelpers/SliceOfLifeShowViewHelper.php | 2 +- app/Helpers/StorageHelper.php | 15 +++++++++++++++ resources/js/Pages/Vault/Contact/Photos/Index.vue | 7 ++++--- resources/js/Pages/Vault/Contact/Show.vue | 7 ++++--- resources/js/Pages/Vault/Journal/Post/Edit.vue | 11 ++++++----- resources/js/Pages/Vault/Journal/Slices/Show.vue | 9 +++++---- resources/js/Shared/Modules/Documents.vue | 9 +++++---- resources/js/Shared/Modules/Photos.vue | 9 +++++---- .../ViewHelpers/ModuleDocumentsViewHelperTest.php | 4 ++-- .../ContactPhotosIndexViewHelperTest.php | 2 +- .../ViewHelpers/ModulePhotosViewHelperTest.php | 4 ++-- .../Web/ViewHelpers/PostEditViewHelperTest.php | 2 +- .../ViewHelpers/SliceOfLifeShowViewHelperTest.php | 2 +- 18 files changed, 58 insertions(+), 37 deletions(-) diff --git a/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php b/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php index 0764e0b7886..f796b440e94 100644 --- a/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php +++ b/app/Domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php @@ -55,7 +55,7 @@ public static function data(Contact $contact, User $user): array 'quick_fact_template_entries' => self::quickFacts($contact), 'modules' => $firstPage ? self::modules($firstPage, $contact, $user) : [], 'avatar' => [ - 'uploadcarePublicKey' => config('services.uploadcare.public_key'), + 'uploadcare' => StorageHelper::uploadcare(), 'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account), 'hasFile' => $contact->avatar['type'] === 'url', ], @@ -109,7 +109,7 @@ public static function dataForTemplatePage(Contact $contact, User $user, Templat 'quick_fact_template_entries' => self::quickFacts($contact), 'modules' => self::modules($templatePage, $contact, $user), 'avatar' => [ - 'uploadcarePublicKey' => config('services.uploadcare.public_key'), + 'uploadcare' => StorageHelper::uploadcare(), 'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account), 'hasFile' => $contact->avatar['type'] === 'url', ], diff --git a/app/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelper.php b/app/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelper.php index 8f129eb1832..6bfebb62d44 100644 --- a/app/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelper.php +++ b/app/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelper.php @@ -21,7 +21,7 @@ public static function data(Contact $contact): array return [ 'documents' => $documentsCollection, - 'uploadcarePublicKey' => config('services.uploadcare.public_key'), + 'uploadcare' => StorageHelper::uploadcare(), 'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account), 'url' => [ 'store' => route('contact.document.store', [ diff --git a/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelper.php b/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelper.php index 3c6b500e087..3a5d046e853 100644 --- a/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelper.php +++ b/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelper.php @@ -20,7 +20,7 @@ public static function data($files, Contact $contact): array 'name' => $contact->name, ], 'photos' => $photosCollection, - 'uploadcarePublicKey' => config('services.uploadcare.public_key'), + 'uploadcare' => StorageHelper::uploadcare(), 'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account), 'url' => [ 'show' => route('contact.show', [ diff --git a/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelper.php b/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelper.php index bf18610de79..343501ac177 100644 --- a/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelper.php +++ b/app/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelper.php @@ -19,7 +19,7 @@ public static function data(Contact $contact): array return [ 'photos' => $photosCollection, - 'uploadcarePublicKey' => config('services.uploadcare.public_key'), + 'uploadcare' => StorageHelper::uploadcare(), 'canUploadFile' => StorageHelper::canUploadFile($contact->vault->account), 'url' => [ 'index' => route('contact.photo.index', [ diff --git a/app/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php b/app/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php index b0d0281914f..14807b676cb 100644 --- a/app/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php +++ b/app/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelper.php @@ -74,7 +74,7 @@ public static function data(Journal $journal, Post $post, User $user): array 'tags_in_post' => $tagsAssociatedWithPostCollection, 'tags_in_vault' => $tagsInVaultCollection, 'journal_metrics' => self::journalMetrics($post), - 'uploadcarePublicKey' => config('services.uploadcare.public_key'), + 'uploadcare' => StorageHelper::uploadcare(), 'canUploadFile' => StorageHelper::canUploadFile($journal->vault->account), 'journal' => [ 'name' => $journal->name, diff --git a/app/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelper.php b/app/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelper.php index 6a155e73149..8595c22d3cf 100644 --- a/app/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelper.php +++ b/app/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelper.php @@ -58,7 +58,7 @@ public static function data(SliceOfLife $slice): array 'slice' => self::dtoSlice($slice), 'posts' => $postsCollection, 'contacts' => $contactsCollection, - 'uploadcarePublicKey' => config('services.uploadcare.public_key'), + 'uploadcare' => StorageHelper::uploadcare(), 'canUploadFile' => StorageHelper::canUploadFile($slice->journal->vault->account), 'url' => [ 'slices_index' => route('slices.index', [ diff --git a/app/Helpers/StorageHelper.php b/app/Helpers/StorageHelper.php index 2da356e2b36..84cb0feb878 100644 --- a/app/Helpers/StorageHelper.php +++ b/app/Helpers/StorageHelper.php @@ -4,6 +4,7 @@ use App\Models\Account; use App\Models\File; +use Uploadcare\Security\Signature; class StorageHelper { @@ -23,4 +24,18 @@ public static function canUploadFile(Account $account): bool return $totalSizeInBytes < $accountLimit; } + + /** + * Get the Uploadcare data needed for the views. + */ + public static function uploadcare(): array + { + $signature = new Signature(config('services.uploadcare.private_key')); + + return [ + 'publicKey' => config('services.uploadcare.public_key'), + 'signature' => $signature->getSignature(), + 'expire' => $signature->getExpire()->getTimestamp(), + ]; + } } diff --git a/resources/js/Pages/Vault/Contact/Photos/Index.vue b/resources/js/Pages/Vault/Contact/Photos/Index.vue index 37c104728c6..7f05962fd40 100644 --- a/resources/js/Pages/Vault/Contact/Photos/Index.vue +++ b/resources/js/Pages/Vault/Contact/Photos/Index.vue @@ -82,10 +82,11 @@ diff --git a/resources/js/Pages/Vault/Contact/Show.vue b/resources/js/Pages/Vault/Contact/Show.vue index 5f35213a9bd..4b245573a1b 100644 --- a/resources/js/Pages/Vault/Contact/Show.vue +++ b/resources/js/Pages/Vault/Contact/Show.vue @@ -229,10 +229,11 @@ const download = () => {
  • diff --git a/resources/js/Pages/Vault/Journal/Post/Edit.vue b/resources/js/Pages/Vault/Journal/Post/Edit.vue index ee5b5f27b8a..21fae700972 100644 --- a/resources/js/Pages/Vault/Journal/Post/Edit.vue +++ b/resources/js/Pages/Vault/Journal/Post/Edit.vue @@ -246,10 +246,11 @@ const destroy = () => { @@ -276,7 +277,7 @@ const destroy = () => {

    + class="inline-block cursor-pointer rounded-lg border bg-slate-200 dark:bg-slate-700 px-1 py-1 text-xs hover:bg-slate-300 hover:dark:bg-slate-800"> {{ $t('+ add another photo') }}

    @@ -284,7 +285,7 @@ const destroy = () => {

    {{ $t('The keys to manage uploads have not been set in this Monica instance.') }} diff --git a/resources/js/Pages/Vault/Journal/Slices/Show.vue b/resources/js/Pages/Vault/Journal/Slices/Show.vue index 711f17fe654..12fed2f3a52 100644 --- a/resources/js/Pages/Vault/Journal/Slices/Show.vue +++ b/resources/js/Pages/Vault/Journal/Slices/Show.vue @@ -121,10 +121,11 @@ const destroy = () => {

    @@ -149,7 +150,7 @@ const destroy = () => {

    {{ $t('The keys to manage uploads have not been set in this Monica instance.') }} diff --git a/resources/js/Shared/Modules/Documents.vue b/resources/js/Shared/Modules/Documents.vue index b3821ea0cce..87c77197bce 100644 --- a/resources/js/Shared/Modules/Documents.vue +++ b/resources/js/Shared/Modules/Documents.vue @@ -23,10 +23,11 @@

    @@ -87,7 +88,7 @@

    {{ $t('The keys to manage uploads have not been set in this Monica instance.') }} diff --git a/resources/js/Shared/Modules/Photos.vue b/resources/js/Shared/Modules/Photos.vue index 899f1f946fe..436d5918c85 100644 --- a/resources/js/Shared/Modules/Photos.vue +++ b/resources/js/Shared/Modules/Photos.vue @@ -23,10 +23,11 @@

    @@ -76,7 +77,7 @@

    {{ $t('The keys to manage uploads have not been set in this Monica instance.') }} diff --git a/tests/Unit/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelperTest.php b/tests/Unit/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelperTest.php index 819f2605685..ba29162c844 100644 --- a/tests/Unit/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelperTest.php +++ b/tests/Unit/Domains/Contact/ManageDocuments/Web/ViewHelpers/ModuleDocumentsViewHelperTest.php @@ -30,13 +30,13 @@ public function it_gets_the_data_needed_for_the_view(): void ); $this->assertArrayHasKey('documents', $array); - $this->assertArrayHasKey('uploadcarePublicKey', $array); + $this->assertArrayHasKey('uploadcare', $array); $this->assertArrayHasKey('canUploadFile', $array); $this->assertArrayHasKey('url', $array); $this->assertEquals( '123', - $array['uploadcarePublicKey'] + $array['uploadcare']['publicKey'] ); $this->assertFalse($array['canUploadFile']); $this->assertEquals( diff --git a/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelperTest.php b/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelperTest.php index 96e81366207..e0fe5ad63f9 100644 --- a/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelperTest.php +++ b/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ContactPhotosIndexViewHelperTest.php @@ -41,7 +41,7 @@ public function it_gets_the_data_needed_for_the_view(): void ); $this->assertEquals( '123', - $array['uploadcarePublicKey'] + $array['uploadcare']['publicKey'] ); $this->assertTrue($array['canUploadFile']); $this->assertEquals( diff --git a/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelperTest.php b/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelperTest.php index 14d5bb62776..6b5557049c1 100644 --- a/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelperTest.php +++ b/tests/Unit/Domains/Contact/ManagePhotos/Web/ViewHelpers/ModulePhotosViewHelperTest.php @@ -31,13 +31,13 @@ public function it_gets_the_data_needed_for_the_view(): void ); $this->assertArrayHasKey('photos', $array); - $this->assertArrayHasKey('uploadcarePublicKey', $array); + $this->assertArrayHasKey('uploadcare', $array); $this->assertArrayHasKey('canUploadFile', $array); $this->assertArrayHasKey('url', $array); $this->assertEquals( '123', - $array['uploadcarePublicKey'] + $array['uploadcare']['publicKey'] ); $this->assertFalse($array['canUploadFile']); $this->assertEquals( diff --git a/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelperTest.php b/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelperTest.php index 1faef38a548..c6a93491088 100644 --- a/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelperTest.php +++ b/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/PostEditViewHelperTest.php @@ -85,7 +85,7 @@ public function it_gets_the_data_needed_for_the_view(): void ); $this->assertEquals( '123', - $array['uploadcarePublicKey'] + $array['uploadcare']['publicKey'] ); $this->assertTrue( $array['canUploadFile'] diff --git a/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelperTest.php b/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelperTest.php index 263b776ecda..f97c2965736 100644 --- a/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelperTest.php +++ b/tests/Unit/Domains/Vault/ManageJournals/Web/ViewHelpers/SliceOfLifeShowViewHelperTest.php @@ -43,7 +43,7 @@ public function it_gets_the_data_needed_for_the_view(): void ); $this->assertEquals( '123', - $array['uploadcarePublicKey'] + $array['uploadcare']['publicKey'] ); $this->assertTrue( $array['canUploadFile'] From ea4c30b5db95bc3eddcdf823eb76a1ef3a848400 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Mon, 16 Oct 2023 19:32:37 +0200 Subject: [PATCH 2/3] fix test --- app/Helpers/StorageHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Helpers/StorageHelper.php b/app/Helpers/StorageHelper.php index 84cb0feb878..d33ca58a6ca 100644 --- a/app/Helpers/StorageHelper.php +++ b/app/Helpers/StorageHelper.php @@ -30,12 +30,12 @@ public static function canUploadFile(Account $account): bool */ public static function uploadcare(): array { - $signature = new Signature(config('services.uploadcare.private_key')); + $signature = config('services.uploadcare.private_key') != '' ? new Signature(config('services.uploadcare.private_key')) : null; return [ 'publicKey' => config('services.uploadcare.public_key'), - 'signature' => $signature->getSignature(), - 'expire' => $signature->getExpire()->getTimestamp(), + 'signature' => optional($signature)->getSignature(), + 'expire' => optional($signature)->getExpire()->getTimestamp(), ]; } } From 618e3800b1a8d2b5ac8a7eb81835423126f79b60 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Mon, 16 Oct 2023 19:40:38 +0200 Subject: [PATCH 3/3] fix --- app/Helpers/StorageHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Helpers/StorageHelper.php b/app/Helpers/StorageHelper.php index d33ca58a6ca..cfa17e5dbfe 100644 --- a/app/Helpers/StorageHelper.php +++ b/app/Helpers/StorageHelper.php @@ -35,7 +35,7 @@ public static function uploadcare(): array return [ 'publicKey' => config('services.uploadcare.public_key'), 'signature' => optional($signature)->getSignature(), - 'expire' => optional($signature)->getExpire()->getTimestamp(), + 'expire' => optional(optional($signature)->getExpire())->getTimestamp(), ]; } }