diff --git a/config/application.config.php b/config/application.config.php
index 790e1bba..afc736eb 100644
--- a/config/application.config.php
+++ b/config/application.config.php
@@ -5,14 +5,14 @@
'modules' => [
'ZF\DevelopmentMode',
'AssetManager',
+ 'EdpModuleLayouts',
'ZfcBase',
'ZfcUser',
'ScnSocialAuth',
'EdpGithub',
'Application',
- 'User',
- 'EdpModuleLayouts',
'ZfModule',
+ 'User',
],
'module_listener_options' => [
'config_glob_paths' => [
diff --git a/config/autoload/global.php b/config/autoload/global.php
index e4c99b48..d9495399 100644
--- a/config/autoload/global.php
+++ b/config/autoload/global.php
@@ -1,7 +1,8 @@
[
- 'ZfcUser' => 'layout/layout-small-header.phtml',
+ 'ZfcUser' => 'layout/layout-small-header.phtml',
+ 'User' => 'layout/layout-small-header.phtml',
'ZfModule' => 'layout/layout-small-header.phtml',
],
'asset_manager' => [
diff --git a/config/autoload/zfcuser.global.php b/config/autoload/zfcuser.global.php
index ea40f743..98de5710 100644
--- a/config/autoload/zfcuser.global.php
+++ b/config/autoload/zfcuser.global.php
@@ -142,7 +142,7 @@
* Accepted values: A valid route name within your application
*
*/
- //'login_redirect_route' => 'zfcuser',
+ 'login_redirect_route' => 'user',
/**
* Logout Redirect Route
diff --git a/module/Application/view/layout/layout-small-header.phtml b/module/Application/view/layout/layout-small-header.phtml
index 4d502c0a..e3ca18bd 100644
--- a/module/Application/view/layout/layout-small-header.phtml
+++ b/module/Application/view/layout/layout-small-header.phtml
@@ -33,13 +33,13 @@
|
Hello escapeHtml(ucfirst($userDisplayName)); ?>
+ Hello escapeHtml(ucfirst($userDisplayName)); ?>
|
Logout
diff --git a/module/Application/view/layout/layout.phtml b/module/Application/view/layout/layout.phtml
index 8f70f01a..4a3c67cc 100644
--- a/module/Application/view/layout/layout.phtml
+++ b/module/Application/view/layout/layout.phtml
@@ -35,12 +35,12 @@
?>
|
- Hello escapeHtml(ucfirst($userDisplayName)) ?>
|
Logout
diff --git a/module/User/config/module.config.php b/module/User/config/module.config.php
index 3f11544a..fbdcf864 100644
--- a/module/User/config/module.config.php
+++ b/module/User/config/module.config.php
@@ -16,9 +16,78 @@
__DIR__ . '/../view',
],
],
+ 'router' => [
+ 'routes' => [
+ 'zfcuser' => [
+ 'options' => [
+ 'route' => '/auth',
+ ],
+ ],
+ 'scn-social-auth-user' => [
+ 'options' => [
+ 'route' => '/auth',
+ 'defaults' => [
+ 'controller' => 'User\Controller\Index',
+ ],
+ ],
+ ],
+ 'user' => [
+ 'type' => 'Literal',
+ 'options' => [
+ 'route' => '/user',
+ 'defaults' => [
+ 'controller' => 'User\Controller\Index',
+ 'action' => 'index',
+ ],
+ ],
+ 'may_terminate' => true,
+ 'child_routes' => [
+ 'module' => [
+ 'type' => 'Literal',
+ 'options' => [
+ 'route' => '/module',
+ ],
+ 'may_terminate' => false,
+ 'child_routes' => [
+ 'list' => [
+ 'type' => 'Literal',
+ 'options' => [
+ 'route' => '/render-list',
+ 'defaults' => [
+ 'action' => 'render-module-list',
+ ],
+ ],
+ ],
+ 'add' => [
+ 'type' => 'Literal',
+ 'options' => [
+ 'route' => '/add',
+ 'defaults' => [
+ 'action' => 'add',
+ ],
+ ],
+ ],
+ 'remove' => [
+ 'type' => 'Segment',
+ 'options' => [
+ 'route' => '/:module_id/remove',
+ 'constraints' => [
+ 'module_id' => '[0-9]+',
+ ],
+ 'defaults' => [
+ 'action' => 'remove',
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
'controllers' => [
- 'invokables' => [
- 'User\Controller\Module' => 'User\Controller\ModuleController',
+ 'factories' => [
+ 'User\Controller\Index' => 'User\Controller\IndexControllerFactory',
],
],
'view_helpers' => [
diff --git a/module/User/src/User/Controller/IndexController.php b/module/User/src/User/Controller/IndexController.php
new file mode 100644
index 00000000..3ac40170
--- /dev/null
+++ b/module/User/src/User/Controller/IndexController.php
@@ -0,0 +1,46 @@
+moduleMapper = $mapper;
+ }
+
+ public function indexAction()
+ {
+ $registeredModules = $this->renderModuleListAction();
+ $registeredModules->setTerminal(false);
+
+ $vm = new ViewModel();
+ $vm->addChild($registeredModules, 'registered_modules');
+
+ return $vm;
+ }
+
+ public function renderModuleListAction()
+ {
+ $modules = $this->moduleMapper->findByOwner($this->zfcUserAuthentication()->getIdentity()->getId());
+
+ $vm = new ViewModel();
+ $vm->setTemplate('user/index/render-module-list');
+ $vm->setVariable('modules', $modules);
+ $vm->setTerminal(true);
+
+ return $vm;
+ }
+}
diff --git a/module/User/src/User/Controller/IndexControllerFactory.php b/module/User/src/User/Controller/IndexControllerFactory.php
new file mode 100644
index 00000000..68698e92
--- /dev/null
+++ b/module/User/src/User/Controller/IndexControllerFactory.php
@@ -0,0 +1,27 @@
+getServiceLocator();
+
+ /* @var ModuleMapper $moduleMapper */
+ $moduleMapper = $serviceManager->get('zfmodule_mapper_module');
+
+ return new IndexController(
+ $moduleMapper
+ );
+ }
+}
diff --git a/module/User/test/UserTest/Integration/Controller/IndexControllerTest.php b/module/User/test/UserTest/Integration/Controller/IndexControllerTest.php
new file mode 100644
index 00000000..f4d88eba
--- /dev/null
+++ b/module/User/test/UserTest/Integration/Controller/IndexControllerTest.php
@@ -0,0 +1,78 @@
+setApplicationConfig(Bootstrap::getConfig());
+ $this->getApplicationServiceLocator()->setAllowOverride(true);
+
+ $mockTotalModules = $this->getMockBuilder(TotalModules::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->viewHelperManager = $this->getApplicationServiceLocator()->get('ViewHelperManager');
+ $this->viewHelperManager->setService('totalModules', $mockTotalModules);
+
+ $mockAuthService = $this->getMockBuilder(AuthenticationService::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockAuthService->expects($this->any())
+ ->method('hasIdentity')
+ ->will($this->returnValue(true));
+ $mockAuthService->expects($this->any())
+ ->method('getIdentity')
+ ->will($this->returnValue(new UserEntity()));
+ $this->getApplicationServiceLocator()->setService('zfcuser_auth_service', $mockAuthService);
+ $this->viewHelperManager->get('zfcUserIdentity')->setAuthService($mockAuthService);
+
+ $mockMapper = $this->getMockBuilder(ModuleMapper::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->getApplicationServiceLocator()->setService('zfmodule_mapper_module', $mockMapper);
+ }
+
+ /**
+ * @group integration
+ */
+ public function testIndexActionRendersUserModuleList()
+ {
+ $mockResultSet = new HydratingResultSet(new ClassMethods(false), new ModuleEntity());
+ $mockResultSet->initialize([[
+ 'id' => 123,
+ 'name' => 'FooModule',
+ 'description' => 'some random module',
+ 'url' => 'https://github.com/zendframework/modules.zendframework.com',
+ ]]);
+
+ $mockMapper = $this->getApplicationServiceLocator()->get('zfmodule_mapper_module');
+ $mockMapper->expects($this->once())
+ ->method('findByOwner')
+ ->willReturn($mockResultSet);
+
+ $this->dispatch('/user');
+
+ $this->assertControllerName('User\Controller\Index');
+ $this->assertActionName('index');
+ $this->assertTemplateName('user/index/index');
+ $this->assertResponseStatusCode(HttpResponse::STATUS_CODE_200);
+ $this->assertContains('FooModule', $this->getResponse()->getContent());
+ $this->assertContains('/user/module/123/remove', $this->getResponse()->getContent());
+ }
+}
diff --git a/module/User/view/user/index/index.phtml b/module/User/view/user/index/index.phtml
new file mode 100644
index 00000000..bf287c79
--- /dev/null
+++ b/module/User/view/user/index/index.phtml
@@ -0,0 +1,26 @@
+
+
+
->getPhotoUrl() ?>)
+
Hello, zfcUserDisplayName() ?>!
+
We should fill this space with some useful information...
+
+
+
+flashMessenger()->getMessages() as $message): ?>
+
+
+
+
+
+
+
+ registered_modules; ?>
+
+
+
+
+
+
diff --git a/module/User/view/user/index/render-module-list.phtml b/module/User/view/user/index/render-module-list.phtml
new file mode 100644
index 00000000..a39b3b74
--- /dev/null
+++ b/module/User/view/user/index/render-module-list.phtml
@@ -0,0 +1,17 @@
+modules->count() === 0) {
+ ?>
+ translate('You have not added any modules'); ?>
+ modules as $module) {
+ echo $this->moduleView([
+ 'id' => $module->getId(),
+ 'owner' => $module->getOwner(),
+ 'name' => $module->getName(),
+ 'created_at' => $module->getCreatedAt(),
+ 'url' => $module->getUrl(),
+ 'photo_url' => $module->getPhotoUrl(),
+ 'description' => $module->getDescription(),
+ ], 'remove');
+}
diff --git a/module/User/view/zfc-user/user/index.phtml b/module/User/view/zfc-user/user/index.phtml
deleted file mode 100644
index ad179ce0..00000000
--- a/module/User/view/zfc-user/user/index.phtml
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
-
-
-
-
-
Available Modules
-
Select which module you want to Submit for Listing
-
-
-
-
- flashMessenger()->getMessages() as $message): ?>
-
-
-
-
-
-
-
- listModule(['user' => true]);
- if (empty($modules)) {
- ?>
-
No modules was submitted yet
- moduleView([
- 'owner' => $module->getOwner(),
- 'name' => $module->getName(),
- 'created_at' => $module->getCreatedAt(),
- 'url' => $module->getUrl(),
- 'photo_url' => $module->getPhotoUrl(),
- 'description' => $module->getDescription(),
- ], 'remove');
- }
- ?>
-
-
-
Synchronizing with Github
 ?>)
-
-
-
- userOrganizations() ?>
-
-
-
-
-
-
-
-
-url('zf-module');
-$this->inlineScript()->appendScript(<< [
- 'type' => 'Segment',
- 'options' => [
- 'route' => '/module',
- 'defaults' => [
- 'controller' => Controller\IndexController::class,
- 'action' => 'index',
- ],
- ],
- 'may_terminate' => true,
- 'child_routes' => [
- 'list' => [
- 'type' => 'Segment',
- 'options' => [
- 'route' => '/list[/:owner]',
- 'constrains' => [
- 'owner' => '[a-zA-Z][a-zA-Z0-9_-]*',
- ],
- 'defaults' => [
- 'action' => 'organization',
- ],
- ],
- ],
- 'add' => [
- 'type' => 'Literal',
- 'options' => [
- 'route' => '/add',
- 'defaults' => [
- 'action' => 'add',
- ],
- ],
- ],
- 'remove' => [
- 'type' => 'Literal',
- 'options' => [
- 'route' => '/remove',
- 'defaults' => [
- 'action' => 'remove',
- ],
- ],
- ],
- ],
- ],
],
],
'view_manager' => [
diff --git a/module/ZfModule/src/ZfModule/Controller/IndexController.php b/module/ZfModule/src/ZfModule/Controller/IndexController.php
index 5431a979..9157bec8 100644
--- a/module/ZfModule/src/ZfModule/Controller/IndexController.php
+++ b/module/ZfModule/src/ZfModule/Controller/IndexController.php
@@ -3,12 +3,9 @@
namespace ZfModule\Controller;
use Application\Service\RepositoryRetriever;
-use EdpGithub\Collection\RepositoryCollection;
-use Zend\Http;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use ZfModule\Mapper;
-use ZfModule\Service;
class IndexController extends AbstractActionController
{
@@ -17,11 +14,6 @@ class IndexController extends AbstractActionController
*/
private $moduleMapper;
- /**
- * @var Service\Module
- */
- private $moduleService;
-
/**
* @var RepositoryRetriever
*/
@@ -29,16 +21,13 @@ class IndexController extends AbstractActionController
/**
* @param Mapper\Module $moduleMapper
- * @param Service\Module $moduleService
* @param RepositoryRetriever $repositoryRetriever
*/
public function __construct(
Mapper\Module $moduleMapper,
- Service\Module $moduleService,
RepositoryRetriever $repositoryRetriever
) {
$this->moduleMapper = $moduleMapper;
- $this->moduleService = $moduleService;
$this->repositoryRetriever = $repositoryRetriever;
}
@@ -74,170 +63,4 @@ public function viewAction()
return $viewModel;
}
-
- public function indexAction()
- {
- if (!$this->zfcUserAuthentication()->hasIdentity()) {
- return $this->redirect()->toRoute('zfcuser/login');
- }
-
- $params = [
- 'type' => 'all',
- 'per_page' => 100,
- 'sort' => 'updated',
- 'direction' => 'desc',
- ];
-
- $repos = $this->repositoryRetriever->getAuthenticatedUserRepositories($params);
- $repositories = $this->fetchModules($repos);
-
- $viewModel = new ViewModel(['repositories' => $repositories]);
- $viewModel->setTerminal(true);
-
- return $viewModel;
- }
-
- public function organizationAction()
- {
- if (!$this->zfcUserAuthentication()->hasIdentity()) {
- return $this->redirect()->toRoute('zfcuser/login');
- }
-
- $owner = $this->params()->fromRoute('owner', null);
- $params = [
- 'per_page' => 100,
- 'sort' => 'updated',
- 'direction' => 'desc',
- ];
-
- $repos = $this->repositoryRetriever->getUserRepositories($owner, $params);
- $repositories = $this->fetchModules($repos);
-
- $viewModel = new ViewModel(['repositories' => $repositories]);
- $viewModel->setTerminal(true);
- $viewModel->setTemplate('zf-module/index/index.phtml');
-
- return $viewModel;
- }
-
- /**
- * @param RepositoryCollection $repos
- * @return array
- */
- private function fetchModules(RepositoryCollection $repos)
- {
- $repositories = [];
-
- foreach ($repos as $repo) {
- $isModule = $this->moduleService->isModule($repo);
- if (!$repo->fork && $repo->permissions->push && $isModule && !$this->moduleMapper->findByName($repo->name)) {
- $repositories[] = $repo;
- }
- }
-
- return $repositories;
- }
-
- /**
- * This function is used to submit a module from the site
- * @throws Exception\UnexpectedValueException
- * @return
- **/
- public function addAction()
- {
- if (!$this->zfcUserAuthentication()->hasIdentity()) {
- return $this->redirect()->toRoute('zfcuser/login');
- }
-
- $request = $this->getRequest();
- if ($request->isPost()) {
- $repo = $request->getPost()->get('repo');
- $owner = $request->getPost()->get('owner');
-
- $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo);
-
- if (!($repository instanceof \stdClass)) {
- throw new Exception\RuntimeException(
- 'Not able to fetch the repository from github due to an unknown error.',
- Http\Response::STATUS_CODE_500
- );
- }
-
- if (!$repository->fork && $repository->permissions->push) {
- if ($this->moduleService->isModule($repository)) {
- $module = $this->moduleService->register($repository);
- $this->flashMessenger()->addMessage($module->getName() . ' has been added to ZF Modules');
- } else {
- throw new Exception\UnexpectedValueException(
- $repository->name . ' is not a Zend Framework Module',
- Http\Response::STATUS_CODE_403
- );
- }
- } else {
- throw new Exception\UnexpectedValueException(
- 'You have no permission to add this module. The reason might be that you are' .
- 'neither the owner nor a collaborator of this repository.',
- Http\Response::STATUS_CODE_403
- );
- }
- } else {
- throw new Exception\UnexpectedValueException(
- 'Something went wrong with the post values of the request...'
- );
- }
-
- return $this->redirect()->toRoute('zfcuser');
- }
-
- /**
- * This function is used to remove a module from the site
- * @throws Exception\UnexpectedValueException
- * @return
- **/
- public function removeAction()
- {
- if (!$this->zfcUserAuthentication()->hasIdentity()) {
- return $this->redirect()->toRoute('zfcuser/login');
- }
-
- $request = $this->getRequest();
- if ($request->isPost()) {
- $repo = $request->getPost()->get('repo');
- $owner = $request->getPost()->get('owner');
-
- $repository = $this->repositoryRetriever->getUserRepositoryMetadata($owner, $repo);
-
- if (!$repository instanceof \stdClass) {
- throw new Exception\RuntimeException(
- 'Not able to fetch the repository from github due to an unknown error.',
- Http\Response::STATUS_CODE_500
- );
- }
-
- if (!$repository->fork && $repository->permissions->push) {
- $module = $this->moduleMapper->findByUrl($repository->html_url);
- if ($module instanceof \ZfModule\Entity\Module) {
- $this->moduleMapper->delete($module);
- $this->flashMessenger()->addMessage($repository->name . ' has been removed from ZF Modules');
- } else {
- throw new Exception\UnexpectedValueException(
- $repository->name . ' was not found',
- Http\Response::STATUS_CODE_403
- );
- }
- } else {
- throw new Exception\UnexpectedValueException(
- 'You have no permission to add this module. The reason might be that you are' .
- 'neither the owner nor a collaborator of this repository.',
- Http\Response::STATUS_CODE_403
- );
- }
- } else {
- throw new Exception\UnexpectedValueException(
- 'Something went wrong with the post values of the request...'
- );
- }
-
- return $this->redirect()->toRoute('zfcuser');
- }
}
diff --git a/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php b/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php
index f5ee3cd4..bfef465d 100644
--- a/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php
+++ b/module/ZfModule/src/ZfModule/Controller/IndexControllerFactory.php
@@ -3,11 +3,9 @@
namespace ZfModule\Controller;
use Application\Service\RepositoryRetriever;
-use Zend\Mvc\Controller\ControllerManager;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use ZfModule\Mapper;
-use ZfModule\Service;
class IndexControllerFactory implements FactoryInterface
{
@@ -23,15 +21,11 @@ public function createService(ServiceLocatorInterface $controllerManager)
/* @var Mapper\Module $moduleMapper */
$moduleMapper = $serviceManager->get('zfmodule_mapper_module');
- /* @var Service\Module $moduleService */
- $moduleService = $serviceManager->get('zfmodule_service_module');
-
/* @var RepositoryRetriever $repositoryRetriever */
$repositoryRetriever = $serviceManager->get(RepositoryRetriever::class);
return new IndexController(
$moduleMapper,
- $moduleService,
$repositoryRetriever
);
}
diff --git a/module/ZfModule/src/ZfModule/Mapper/Module.php b/module/ZfModule/src/ZfModule/Mapper/Module.php
index b493d381..ffb6f053 100644
--- a/module/ZfModule/src/ZfModule/Mapper/Module.php
+++ b/module/ZfModule/src/ZfModule/Mapper/Module.php
@@ -87,12 +87,12 @@ public function findByLike($query, $limit = null, $orderBy = null, $sort = 'ASC'
return $entity;
}
- /**
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
public function findByOwner($owner, $limit = null, $orderBy = null, $sort = 'ASC')
{
$select = $this->getSelect();
+ if ($owner) {
+ $select->where(['owner' => $owner]);
+ }
if ($orderBy) {
$select->order($orderBy . ' ' . $sort);
diff --git a/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php b/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php
index 5c5e51c3..78654f36 100644
--- a/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php
+++ b/module/ZfModule/test/ZfModuleTest/Integration/Controller/IndexControllerTest.php
@@ -18,29 +18,6 @@ protected function setUp()
$this->setApplicationConfig(Bootstrap::getConfig());
}
- public function testIndexActionCanBeAccessed()
- {
- $this->dispatch('/module');
-
- $this->assertControllerName(Controller\IndexController::class);
- $this->assertActionName('index');
- }
-
- public function testOrganizationActionCanBeAccessed()
- {
- $owner = 'foo';
-
- $url = sprintf(
- '/module/list/%s',
- $owner
- );
-
- $this->dispatch($url);
-
- $this->assertControllerName(Controller\IndexController::class);
- $this->assertActionName('organization');
- }
-
public function testViewActionCanBeAccessed()
{
$vendor = 'foo';
diff --git a/module/ZfModule/view/zf-module/helper/module-view.phtml b/module/ZfModule/view/zf-module/helper/module-view.phtml
index 4b82fae5..24f163f9 100644
--- a/module/ZfModule/view/zf-module/helper/module-view.phtml
+++ b/module/ZfModule/view/zf-module/helper/module-view.phtml
@@ -26,13 +26,13 @@
-
-