public function show($id, $fileId) { if ($this->projectService->checkProjectPermissions($id) === false) { return ['error' => 'Access Forbidden']; } return $this->repository->find($fileId); }
public function delete($id) { $projectFile = $this->repository->skipPresenter()->find($id); if ($this->storage->exists($projectFile->getFileName())) { $this->storage->delete($projectFile->getFileName()); return $projectFile->delete(); } /* // recupera somente os Files $files = $this->repository->skipPresenter()->find($projectId)->files; //dd($files); $deletar = []; foreach ($files as $file) { $path = $file->id . '.' . $file->extension; // deletar da bd if($file->delete($file->id)) $deletar[] = $path; } //dd($deletar); $r = $this->storage->delete($deletar); if($r) return ['error' => false]; else return ['error' => true]; */ }
/** * @param int $id * @return Response */ public function show($id, $idFile) { $result = $this->repository->findWhere(['project_id' => $id, 'id' => $idFile]); if (isset($result['data']) && count($result['data']) == 1) { $result = ['data' => $result['data'][0]]; } return $result; }
public function delete($id) { $projectFile = $this->repository->skipPresenter()->find($id); if ($this->storage->exists($projectFile->getFileName())) { $this->storage->delete($projectFile->getFileName()); return $projectFile->delete(); } }
public function destroyFile($data) { foreach ($data as $files) { $arquivo = $files->name . '.' . $files->extension; if ($this->storage->disk()->exists($arquivo)) { $this->storage->disk()->delete($arquivo); $this->repository->delete($files->id); return ['error' => true, 'message' => 'Arquivo ' . $arquivo . ' do Projeto Excluido']; } } }
/** * @param int $id * @return Response */ public function show($id, $idFile) { $result = $this->repository->findWhere(['project_id' => $id, 'id' => $idFile]); if (isset($result['data']) && count($result['data']) == 1) { $result = ['data' => $result['data'][0]]; } return $result; /* if($this->service->checkProjectPermissions($id) == false){ return ['error' => 'Access Forbidden']; } return $this->repository->find($id); */ }
public function destroy($id, $fileId) { $projectFile = $this->repository->skipPresenter()->findWhere(['project_id' => $id, 'id' => $fileId])->first(); try { if ($projectFile->delete($fileId)) { $this->storage->delete($projectFile->id . '.' . $projectFile->extension); } } catch (ErrorException $e) { return ['error' => true, 'message' => $e->getMessage()]; } }
public function download($project_id, $file_id) { /*if( $this->service->checkProjectPermissions($project_id) == false ){ return ['error' => 'Acesso negado']; }*/ #return response()->download($this->service->show($file_id)); $model = $this->repository->skipPresenter()->find($file_id); $file_path = $this->service->show($file_id); $file_content = file_get_contents($file_path); $file64 = base64_encode($file_content); return ['file' => $file64, 'size' => filesize($file_path), 'name' => $this->service->getFileName($file_id), 'mime_type' => $this->storage->mimeType($this->service->getFileName($file_id))]; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { try { if (!$this->service->checkProjectOwner($id)) { return $this->erroMsgm("O usuário não é onwer desse projeto"); } return $this->repository->update($request->all(), $id); } catch (ModelNotFoundException $e) { return $this->erroMsgm('Projeto não encontrado.'); } catch (NoActiveAccessTokenException $e) { return $this->erroMsgm('Usuário não está logado.'); } catch (\Exception $e) { return $this->erroMsgm('Ocorreu um erro ao atualizar o projeto.'); } }
public function delete($file_id) { $projectFile = ProjectFile::find($file_id); if (is_null($projectFile)) { return Errors::invalidId($file_id); } $user_id = \Authorizer::getResourceOwnerId(); if (!$this->projectRepository->isMember($projectFile->project_id, $user_id)) { return Errors::basic('Acesso negado. Você não é membro do projeto deste arquivo.'); } $nome = $projectFile->id . '.' . $projectFile->extension; $this->repository->delete($file_id); $this->storage->delete($nome); return ['message' => "Registro e arquivo deletados!"]; }
public function update(array $data, $file_id) { $file = ProjectFile::find($file_id); if (is_null($file)) { return Errors::invalidId($file_id); } try { $this->validator->with($data)->passesOrFail(ValidatorInterface::RULE_UPDATE); if ($data['project_id'] != $file->project_id) { return Errors::basic('Você não pode alterar o projeto do arquivo.'); } if ($data['extension'] != $file->extension) { return Errors::basic('Você não pode alterar a extensão do arquivo.'); } $user_id = \Authorizer::getResourceOwnerId(); if (!$this->projectRepository->isMember($file->project_id, $user_id)) { return Errors::basic('Acesso negado. Você não é membro do projeto selecionado.'); } return $this->repository->update($data, $file_id); } catch (ValidatorException $e) { return Errors::basic($e->getMessageBag()); } }
public function show($id, $fileId) { return $this->repository->findWhere(['project_id' => $id, 'id' => $fileId]); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($projectId, $id) { return $this->repository->find($id); }
public function getFileName($id) { $projectFile = $this->repository->skipPresenter()->find($id); return $projectFile->getFileName(); }
private function setPresenter() { $this->repository->setPresenter('CodeProject\\Presenters\\ProjectFilePresenter'); }
public function checkProjectMember($projectFileId) { $userId = \Authorizer::getResourceOwnerId(); $projectId = $this->repository->skipPresenter()->find($projectFileId)->project_id; return $this->projectRepository->hasMember($projectId, $userId); }