Ejemplo n.º 1
0
 /**
  * Load acl fixture
  * 
  * @access public
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     $userModule = "Users";
     $userEditRoute = "userEdit";
     $courseModule = "Courses";
     $coursesCalendarRoute = "coursesCalendar";
     $coursesMoreRoute = "coursesMore";
     $courseOutlines = "courseOutlines";
     $coursesEnrollRoute = "coursesEnroll";
     $coursesLeaveRoute = "coursesLeave";
     $coursesEditRoute = "coursesEdit";
     $coursesNewRoute = "coursesNew";
     $coursesPendingRoute = "coursesPending";
     $coursesListRoute = "courses";
     $coursesVoteRoute = "studentEvaluation";
     $courseEvaluation = "courseEvaluations";
     $newCourseEvaluation = "newCourseEvaluation";
     $editCourseEvaluation = "editCourseEvaluation";
     $instructorCalendar = "coursesInstructorCalendar";
     $coursesInstructorTrainingRoute = "coursesInstructorTraining";
     $examBookingRoute = "examBooking";
     $resourcesListPerCourseRoute = "resourcesListPerCourse";
     $resourcesResourceDownloadRoute = "resourcesResourceDownload";
     $resourcesNewPerCourseRoute = "resourcesNewPerCourse";
     $resourcesEditRoute = "resourcesEdit";
     $organizationModule = "Organizations";
     $organizationUsersRoute = "organizationUsers";
     $organizationUsersListRoute = "organizationUsersList";
     $organizationUsersNewRoute = "organizationUsersNew";
     $organizationUsersEditRoute = "organizationUsersEdit";
     $organizationUsersDeleteRoute = "organizationUsersDelete";
     $organizationsPendingRoute = "organizationsPending";
     $organizationsDownloadRoute = "organizationsDownload";
     $listAtcOrgsRoute = "list_atc_orgs";
     $listAtpOrgsRoute = "list_atp_orgs";
     $orgTypeRoute = "org_type";
     $orgMoreRoute = "more";
     $orgNewRoute = "new_org";
     $orgEditRoute = "edit_org";
     $saveStateRoute = "saveState";
     $acls = array(array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $userModule, 'route' => $userEditRoute), array('role' => RoleEntity::PROCTOR_ROLE, 'module' => $userModule, 'route' => $userEditRoute), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $userModule, 'route' => $userEditRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $userModule, 'route' => $userEditRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $userModule, 'route' => $userEditRoute), array('role' => RoleEntity::USER_ROLE, 'module' => $userModule, 'route' => $userEditRoute), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $coursesCalendarRoute), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $coursesMoreRoute), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $coursesEnrollRoute), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $coursesLeaveRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesNewRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesEditRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesListRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $coursesPendingRoute), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $courseModule, 'route' => $coursesVoteRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $courseEvaluation), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $newCourseEvaluation), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $editCourseEvaluation), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $coursesInstructorTrainingRoute), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $instructorCalendar), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $courseOutlines), array('role' => RoleEntity::USER_ROLE, 'module' => $courseModule, 'route' => $courseOutlines), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $courseOutlines), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $courseModule, 'route' => $courseOutlines), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $courseModule, 'route' => $courseOutlines), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $courseModule, 'route' => $examBookingRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $resourcesListPerCourseRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $resourcesNewPerCourseRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $resourcesEditRoute), array('role' => RoleEntity::STUDENT_ROLE, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $resourcesResourceDownloadRoute), array('role' => RoleEntity::INSTRUCTOR_ROLE, 'module' => $courseModule, 'route' => $resourcesListPerCourseRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $organizationsDownloadRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $organizationsDownloadRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $organizationsPendingRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $organizationsPendingRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersListRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersListRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersNewRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersNewRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersEditRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersEditRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersDeleteRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $organizationUsersDeleteRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $listAtcOrgsRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $listAtpOrgsRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $orgTypeRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $orgTypeRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $saveStateRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $saveStateRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $orgEditRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $orgEditRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $orgNewRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $orgNewRoute), array('role' => RoleEntity::TEST_CENTER_ADMIN_ROLE, 'module' => $organizationModule, 'route' => $orgMoreRoute), array('role' => RoleEntity::TRAINING_MANAGER_ROLE, 'module' => $organizationModule, 'route' => $orgMoreRoute));
     foreach ($acls as $aclData) {
         $acl = new AclEntity();
         $acl->setModule($aclData["module"])->setRoute($aclData["route"])->setRole($this->getReference($aclData["role"]));
         $manager->persist($acl);
     }
     $manager->flush();
 }
Ejemplo n.º 2
0
 /**
  * Define role privileges ( ACL role <-> module <-> route )
  * 
  * @access public
  * @return ViewModel 
  */
 public function privilegesAction()
 {
     $id = $this->params('id');
     /* @var $query \Utilities\Service\Query\Query */
     $query = $this->getServiceLocator()->get('wrapperQuery');
     $em = $query->entityManager;
     $roleObj = $query->find('Users\\Entity\\Role', $id);
     $rolePrivileges = $query->findBy('Users\\Entity\\Acl', array('role' => $roleObj));
     $request = $this->getRequest();
     if ($request->isPost()) {
         // delete old privileges
         foreach ($rolePrivileges as $p) {
             $query->remove($p);
         }
         // insert new privileges
         $data = $request->getPost()->toArray();
         if (isset($data['privileges'])) {
             foreach ($data['privileges'] as $p) {
                 list($module, $route) = explode("-", $p);
                 $aclEntity = new AclEntity();
                 $aclEntity->setModule($module);
                 $aclEntity->setRoute($route);
                 $aclEntity->setRole($roleObj);
                 $em->persist($aclEntity);
             }
         }
         $em->flush();
         $url = $this->getEvent()->getRouter()->assemble(array('action' => 'index'), array('name' => 'roles'));
         $this->redirect()->toUrl($url);
     }
     $manager = $this->getServiceLocator()->get('ModuleManager');
     $loadedModules = $manager->getLoadedModules();
     $excludedModules = $loadedModules['CertigateAcl']->getConfig()['roles_management']['excluded_modules'];
     $filtereModules = [];
     foreach ($loadedModules as $k => $v) {
         if (!in_array($k, $excludedModules)) {
             $filtereModules[$k] = $v;
         }
     }
     $roleRoutes = [];
     foreach ($rolePrivileges as $p) {
         $roleRoutes[] = implode("-", [$p->getModule(), $p->getRoute()]);
     }
     foreach ($filtereModules as $module => $object) {
         $routes = array_keys($object->getConfig()['router']['routes']);
         $newRoutes = [];
         foreach ($routes as $r) {
             if (in_array(implode("-", [$module, $r]), $roleRoutes)) {
                 $newRoutes[] = ['name' => $r, 'checked' => true];
             } else {
                 $newRoutes[] = ['name' => $r, 'checked' => false];
             }
         }
         $modulesRoutes[] = ['module' => $module, 'routes' => $newRoutes];
     }
     return new ViewModel(['modulesRoutes' => $modulesRoutes, 'role' => $roleObj]);
 }