/** * Usuwanie uprawnień do kontrolerów/akcji * * Wszystkie zasoby dziedziczą po swoich przodkach (kontroler.akcja po kontrolerze, kontroler po module), podobnie role i grupy uprawnień. * Rola użytkownika (w sensie ACL) to "profil_{id_profilu}" i do profilu przywiązane są grupy uprawnień i role. * * @return Zend_Acl */ public function getAcl() { $oddzial = ODDZIAL_ID; $profil = $this->getCurrentProfile(); $aclProfileId = $profil ? $profil->id : 'none'; if ($aclProfileId !== "none") { $cm = $this->getBootstrap()->getResource('cachemanager'); $cache = $cm->getCache('rolecache'); $front = Zend_Controller_Front::getInstance(); $pluginAcl = $front->getPlugin('Base_Controller_Plugin_Acl'); $branch_name = is_numeric(ODDZIAL_ID) && ODDZIAL_ID > 0 ? '_' . ODDZIAL_ID : ''; $this->acl = $cache->load('acl_profile_' . $aclProfileId . $branch_name); if (!$this->acl) { $this->acl = $front->getPlugin('Base_Controller_Plugin_Acl')->getAcl(); $this->_groups = $all_groups = $grupy = $this->getGroups(); $profileResourceDenyModel = new ProfileResourceDeny(); $profileResourceDeny = $profileResourceDenyModel->fetchAll("id_profile=" . $aclProfileId)->toArray(); $rup = array(); foreach ($profileResourceDeny as $gpr) { $rupModel = new GroupLinkResource(); $rup = array_merge($rup, $rupModel->fetchAll("id_group=" . $gpr['id_group'])->toArray()); } $tmp = $this->getResources(); $up = $tmp['mvc']->toArray(); $upArray = array(); /** * Dla każdego zasobu dodajemy resource z odpowiednim przodkiem */ foreach ($up as $u) { $upArray[$u['id']] = $u; $module = $u['module']; $controller = $u['controller']; $action = $u['action']; if ('*' == $controller) { $resource = $this->buildResourceName('mvc', $module); $parent = null; } if ('*' == $action) { $resource = $this->buildResourceName('mvc', $module, $controller); $parent = $this->buildResourceName('mvc', $module); if (!$this->acl->has($parent)) { $this->acl->add(new Zend_Acl_Resource($parent), null); } } if ('*' != $action and $action) { $resource = $this->buildResourceName('mvc', $module, $controller, $action); $parent = $this->buildResourceName('mvc', $module, $controller); if (!$this->acl->has($parent)) { $this->acl->add(new Zend_Acl_Resource($parent), null); } } if (!$this->acl->has($resource)) { $this->acl->add(new Zend_Acl_Resource($resource), $parent); } } /** * Usuwanie resource'ów z ról/grup */ foreach ($rup as $r) { $module = $upArray[$r['id_resource']]['module']; $controller = $upArray[$r['id_resource']]['controller']; $action = $upArray[$r['id_resource']]['action']; $role = 'group_' . (int) $all_groups[$r['id_group']]['priority'] . "_" . $r['id_group']; if ('*' == $controller) { $resource = $this->buildResourceName('mvc', $module); } elseif ('*' == $action) { $resource = $this->buildResourceName('mvc', $module, $controller); } elseif ('*' != $action and $action) { $resource = $this->buildResourceName('mvc', $module, $controller, $action); } /** * Usuwanie grup z profilu */ $this->acl->deny($role, $resource); $cache->save($this->acl, 'acl_profile_' . $aclProfileId . $branch_name); } } return $this->acl; } }
/** * Budowanie uprawnień do kontrolerów/akcji * * Wszystkie zasoby dziedziczą po swoich przodkach (kontroler.akcja po kontrolerze, kontroler po module), podobnie role i grupy uprawnień. * Rola użytkownika (w sensie ACL) to "profil_{id_profilu}" i do profilu przywiązane są grupy uprawnień i role. * * @return Zend_Acl */ public function getAcl() { $oddzial = ODDZIAL_ID; $profil = $this->getCurrentProfile(); $aclProfileId = $profil ? $profil->id : 'none'; $cm = $this->getBootstrap()->getResource('cachemanager'); $cache = $cm->getCache('rolecache'); $front = Zend_Controller_Front::getInstance(); $pluginAcl = $front->getPlugin('Base_Controller_Plugin_Acl'); $branch_name = is_numeric(ODDZIAL_ID) && ODDZIAL_ID > 0 ? '_' . ODDZIAL_ID : ''; $this->acl = $cache->load('acl_profile_' . $aclProfileId . $branch_name); if (!$this->acl) { $this->acl = new Base_Acl(); $this->_groups = $all_groups = $grupy = $this->getGroups(); $this->_roles = $all_roles = $role = $this->getRoles($profil); foreach ($grupy as $grupa) { $this->addAclRole($grupa, 'group'); } foreach ($role as $rola) { $this->addAclRole($rola, 'role'); } $rupModel = new GroupLinkResource(); $rup = $rupModel->fetchAll()->toArray(); $tmp = $this->getResources(); $up = $tmp['mvc']->toArray(); $upArray = array(); /** * Dla każdego zasobu dodajemy resource z odpowiednim przodkiem */ foreach ($up as $u) { $upArray[$u['id']] = $u; $module = $u['module']; $controller = $u['controller']; $action = $u['action']; if ('*' == $controller) { $resource = $this->buildResourceName('mvc', $module); $parent = null; } if ('*' == $action) { $resource = $this->buildResourceName('mvc', $module, $controller); $parent = $this->buildResourceName('mvc', $module); if (!$this->acl->has($parent)) { $this->acl->add(new Zend_Acl_Resource($parent), null); } } if ('*' != $action and $action) { $resource = $this->buildResourceName('mvc', $module, $controller, $action); $parent = $this->buildResourceName('mvc', $module, $controller); if (!$this->acl->has($parent)) { $this->acl->add(new Zend_Acl_Resource($parent), null); } } if (!$this->acl->has($resource)) { $this->acl->add(new Zend_Acl_Resource($resource), $parent); } } /** * Dodawanie resource'ów do ról/grup */ foreach ($rup as $r) { $module = $upArray[$r['id_resource']]['module']; $controller = $upArray[$r['id_resource']]['controller']; $action = $upArray[$r['id_resource']]['action']; $role = 'group_' . (int) $all_groups[$r['id_group']]['priority'] . "_" . $r['id_group']; if ('*' == $controller) { $resource = $this->buildResourceName('mvc', $module); } elseif ('*' == $action) { $resource = $this->buildResourceName('mvc', $module, $controller); } elseif ('*' != $action and $action) { $resource = $this->buildResourceName('mvc', $module, $controller, $action); } $this->acl->allow($role, $resource); } $cache->save($this->acl, 'acl_profile_' . $aclProfileId . $branch_name); } $identity = Zend_Auth::getInstance()->getIdentity(); /** * Budowanie uprawnień dla danego profilu, jeśli istnieje. * Jeśli nie istnieje ustawienie roli na domyślną (ustawioną w configu). */ $data = array(); $data['roles'] = array(); $roles = array(); if (!$identity) { $defaultRole = $this->getDefaultRole(); $data['roles'][] = $defaultRole; $pluginAcl->setRole(new Zend_Acl_Role($defaultRole)); } else { $data = $cache->load('user_data_' . $identity->id . '_profile_' . $aclProfileId . $branch_name); if (!$data) { if ($profil->id) { $profil = $profil->toArray(); $profil['parents']['role'] = array(); $profil['parents']['group'] = array(); $profilRola = new ProfileRole(); $ru = $profilRola->fetchAll("ghost = false and id_profile = {$profil['id']}")->toArray(); foreach ($ru as $r) { $roles[] = 'role_' . (int) $all_roles[$r['id_role']]['priority'] . '_' . $r['id_role']; $profil['parents']['role'][] = array('id' => $r['id_role'], 'priority' => (int) $all_roles[$r['id_role']]['priority']); } $profilGrupa = new ProfileGroup(); $gu = $profilGrupa->fetchAll("ghost = false and id_profile = {$profil['id']}")->toArray(); foreach ($gu as $g) { $roles[] = 'group_' . (int) $all_groups[$g['id_group']]['priority'] . "_" . $g['id_group']; $profil['parents']['group'][] = array('id' => $g['id_group'], 'priority' => (int) $all_groups[$g['id_group']]['priority']); } $this->addAclRole($profil, 'profile'); $pluginAcl->setRole(new Zend_Acl_Role('profile_' . $profil['id'])); $identity->profile_id = $profil['id']; } else { $pluginAcl->setRole(new Zend_Acl_Role($defaultRole)); } $data['roles'] = $roles; $data['profil'] = $profil; $cache->save($data, 'user_data_' . $identity->id . '_profile_' . $aclProfileId . $branch_name); } else { // diee($data); // FROM CACHE if ($data['profil']['id']) { $this->addAclRole($data['profil'], 'profile'); $pluginAcl->setRole(new Zend_Acl_Role('profile_' . $data['profil']['id'])); $identity->profile_id = $data['profil']['id']; } else { $pluginAcl->setRole(new Zend_Acl_Role($defaultRole)); } } } $pluginAcl->setAcl($this->acl); $pluginAcl->setErrorHandlerModule('default'); $pluginAcl->setErrorHandlerController('error'); $pluginAcl->setErrorHandlerAction('error'); $pluginAcl->setResourcePrefix('mvc:'); $pluginAcl->setResourceSeparator('.'); $pluginAcl->setLoginPage('login', 'auth'); $config = Zend_Registry::get('config'); if ($oddzial < 0) { if ($config['resources']['branch']['branch_after_login']) { if (isset($_GET['set_login_page']) && $_GET['set_login_page'] == true) { $pluginAcl->setLoginPage('selectbranchafterlogin', 'branch'); } } else { $pluginAcl->setLoginPage('select', 'branch'); } } return $this->acl; }
public function delete($id) { $model = new GroupLinkResource(); $delete = $model->delete($id); return $delete; }