MCPcopy Create free account
hub / github.com/error311/FileRise / opCopyFiles

Method opCopyFiles

src/FileRise/Domain/McpCoreOpsService.php:860–1018  ·  view source on GitHub ↗

* @param array $payload * @return array */

(McpOpsContext $ctx, array $payload)

Source from the content-addressed store, hash-verified

858 * @return array<string,mixed>
859 */
860 private static function opCopyFiles(McpOpsContext $ctx, array $payload): array
861 {
862 self::assertWritableAccount($ctx, true);
863
864 $sourceFolder = self::normalizeFolder((string)($payload['source'] ?? 'root'));
865 $destinationFolder = self::normalizeFolder((string)($payload['destination'] ?? 'root'));
866 $files = self::normalizeFileList($payload['files'] ?? []);
867
868 $sourcePair = self::resolveSourcePair($payload);
869 $sourceId = $sourcePair['sourceId'];
870 $destSourceId = $sourcePair['destSourceId'];
871 $crossSource = $sourcePair['crossSource'];
872
873 if ($crossSource && (!class_exists(SourceContext::class) || !SourceContext::sourcesEnabled())) {
874 throw new RuntimeException('Cross-source operations require sources to be enabled.', 400);
875 }
876
877 if ($crossSource) {
878 if ($sourceId === '' || $destSourceId === '') {
879 throw new RuntimeException('Cross-source copy requires both source ids.', 400);
880 }
881
882 $username = $ctx->username();
883 $perms = $ctx->permissions();
884
885 self::withSourceContext(
886 $ctx,
887 ['sourceId' => $sourceId],
888 true,
889 function () use ($ctx, $sourceFolder, $files, $username, $perms): array {
890 $hasSourceView = ACL::canReadOwn($username, $perms, $sourceFolder)
891 || ACL::ownsFolderOrAncestor($username, $perms, $sourceFolder);
892 if (!$hasSourceView) {
893 throw new RuntimeException('Forbidden: no read access to source.', 403);
894 }
895
896 $needScope = ACL::canRead($username, $perms, $sourceFolder) ? 'read' : 'read_own';
897 self::assertFolderScope($ctx, $sourceFolder, $needScope);
898
899 if (
900 !$ctx->canBypassOwnership()
901 && !ACL::canRead($username, $perms, $sourceFolder)
902 && ACL::hasGrant($username, $sourceFolder, 'read_own')
903 ) {
904 self::assertFilesOwnedByUser($sourceFolder, $files, $username);
905 }
906
907 return ['ok' => true];
908 }
909 );
910
911 self::withSourceContext(
912 $ctx,
913 ['sourceId' => $destSourceId],
914 true,
915 function () use ($ctx, $destinationFolder, $username, $perms): array {
916 $hasDestCopy = ACL::canCopy($username, $perms, $destinationFolder)
917 || ACL::ownsFolderOrAncestor($username, $perms, $destinationFolder);

Callers 1

dispatchMethod · 0.95

Calls 15

assertWritableAccountMethod · 0.95
normalizeFolderMethod · 0.95
normalizeFileListMethod · 0.95
resolveSourcePairMethod · 0.95
withSourceContextMethod · 0.95
assertFolderScopeMethod · 0.95
usernameMethod · 0.80
permissionsMethod · 0.80
canReadOwnMethod · 0.80
canReadMethod · 0.80

Tested by

no test coverage detected