public function testCreateExceptionFromInsufficientPermissions() { $exception = Exception\RepositoryException::fromInsufficientPermissions('fooPublicMessage', 'foo/name', ['fooPermission', 'barPermission']); $this->assertInstanceOf(Exception\RepositoryException::class, $exception); $this->assertSame('fooPublicMessage', $exception->getPublicMessage()); $this->assertSame('Invalid Repository permission [foo/name] required [fooPermission,barPermission]', $exception->getMessage()); $this->assertSame(Http\Response::STATUS_CODE_403, $exception->getCode()); }
/** * Removes a Module * * @return Http\Response * @throws Exception\InvalidDataException * @throws Exception\RepositoryException */ public function removeAction() { if (!$this->zfcUserAuthentication()->hasIdentity()) { return $this->redirect()->toRoute('zfcuser/login'); } $request = $this->getRequest(); if (!$request->isPost()) { throw Exception\InvalidDataException::fromInvalidRequest('Something went wrong with the post values of the request...', $request); } $postParams = $request->getPost(); $repo = $postParams->get('repo'); $owner = $postParams->get('owner'); $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo); if (!$repository instanceof \stdClass) { throw Exception\RepositoryException::fromNotFoundRepository('Not able to fetch the repository from GitHub due to an unknown error.', $owner, $repo); } if ($repository->fork || !$repository->permissions->push) { throw Exception\RepositoryException::fromInsufficientPermissions('You have no permission to remove this module. The reason might be that you are neither the owner nor a collaborator of this repository.', $repository->full_name, ['pushAccess', 'noFork']); } $module = $this->moduleMapper->findByUrl($repository->html_url); if (!$module) { throw Exception\RepositoryException::fromNotFoundRepositoryUrl($repository->name . ' was not found', $repository->html_url); } $this->moduleMapper->delete($module); $this->flashMessenger()->addSuccessMessage($repository->name . ' has been removed from ZF Modules'); return $this->redirect()->toRoute('zfcuser'); }