fixed moving issue when user move folder with files into team folder

This commit is contained in:
Čarodej
2022-03-29 12:28:22 +02:00
parent 32d4873715
commit af3f08e728

View File

@@ -1,24 +1,54 @@
<?php
namespace Domain\Items\Actions;
use Gate;
use Domain\Teams\Actions\SetTeamFolderPropertyForAllChildrenAction;
use Domain\Folders\Models\Folder;
use Domain\Sharing\Models\Share;
use Gate;
class MoveFileOrFolderAction
{
public function __construct(
public SetTeamFolderPropertyForAllChildrenAction $setTeamFolderPropertyForAllChildren,
) {}
/**
* Move folder or file to new location
*/
public function __invoke($request, ?Share $share = null): void
{
foreach ($request->input('items') as $item) {
$item = get_item($item['type'], $item['id']);
Gate::authorize('can-edit', [$item, $share]);
$entry = get_item($item['type'], $item['id']);
$item->update([
'parent_id' => $request->input('to_id'),
]);
// Check permission
Gate::authorize('can-edit', [$entry, $share]);
// Process folder
if ($item['type'] === 'folder') {
// Determine, if we are moving folder into the team folder or not
$isTeamFolder = is_null($request->input('to_id'))
? false
: Folder::find($request->input('to_id'))->getLatestParent()->team_folder;
// Change team_folder mark for all children folders
($this->setTeamFolderPropertyForAllChildren)($entry, $isTeamFolder);
// Update folder
$entry->update([
'parent_id' => $request->input('to_id'),
'team_folder' => $isTeamFolder,
]);
}
// Process file
if ($item['type'] !== 'folder') {
// Update file
$entry->update([
'parent_id' => $request->input('to_id'),
]);
}
}
}
}