From 07a850ffbcd86d04fb70793b9591cbb5a85f20e8 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 31 Jul 2024 01:08:16 -0400 Subject: [PATCH 1/2] refact: message cache --- .../FilesystemManagementMutation.php | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php b/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php index d52075606..d4141af38 100644 --- a/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php +++ b/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php @@ -44,27 +44,47 @@ public function attachFile(mixed $rootValue, array $request): string */ public function deAttachFile(mixed $rootValue, array $request): bool { + $app = app(Apps::class); + $user = auth()->user(); + $fileEntity = FilesystemEntities::where('uuid', $request['uuid']) - ->fromCompany(auth()->user()->getCurrentCompany()) + ->when(! $user->isAdmin(), function ($query) use ($user) { + $query->fromCompany($user->getCurrentCompany()); + }) ->notDeleted() ->firstOrFail(); + if ($fileEntity->filesystem->apps_id != $app->getId()) { + return false; + } + return $fileEntity->softDelete(); } public function deAttachFiles(mixed $rootValue, array $request): bool { - $company = auth()->user()->getCurrentCompany(); + $app = app(Apps::class); + $user = auth()->user(); + $i = 0; + $fileEntities = FilesystemEntities::whereIn('uuid', $request['uuids']) - ->fromCompany($company) + ->when(! $user->isAdmin(), function ($query) use ($user) { + $query->fromCompany($user->getCurrentCompany()); + }) ->notDeleted() ->get(); foreach ($fileEntities as $fileEntity) { - $fileEntity->softDelete(); + if ($fileEntity->filesystem->apps_id != $app->getId()) { + continue; + } + + if($fileEntity->softDelete()) { + $i++; + } } - return true; + return $i == count($request['uuids']); } /** From fa2dab60521037b3e41db4efdaf183f6e03e11e5 Mon Sep 17 00:00:00 2001 From: kaioken Date: Wed, 31 Jul 2024 01:11:59 -0400 Subject: [PATCH 2/2] refact: message cache --- .../Mutations/Filesystem/FilesystemManagementMutation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php b/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php index d4141af38..1122f565f 100644 --- a/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php +++ b/app/GraphQL/Ecosystem/Mutations/Filesystem/FilesystemManagementMutation.php @@ -79,7 +79,7 @@ public function deAttachFiles(mixed $rootValue, array $request): bool continue; } - if($fileEntity->softDelete()) { + if ($fileEntity->softDelete()) { $i++; } }