Esempio n. 1
0
 /**
  * Copies permissions from one role id to other
  * @param int $fromRoleId
  * @param int $toRoleId
  */
 public function copyRole($fromRoleId, $toRoleId)
 {
     $permission = new Permission();
     $permissions = $permission->getPermissions($fromRoleId);
     $set = $permission->createPermissionSet($permissions, $toRoleId);
     \DB::table(PREFIX . 'codo_permissions')->insert($set);
 }
Esempio n. 2
0
 function getPermissions($user_id = NULL, $company_id = NULL)
 {
     if ($user_id == NULL or $user_id == '') {
         global $current_user;
         $user_id = $current_user->getId();
     }
     if ($company_id == NULL or $company_id == '') {
         global $current_company;
         $company_id = $current_company->getId();
     }
     $permission = new Permission();
     return $this->returnHandler($permission->getPermissions($user_id, $company_id));
 }
Esempio n. 3
0
 /**
  * Charge les permissions pour le rang
  */
 private function loadPermissions()
 {
     $this->aPermissions = array();
     $this->aPermissions = Permission::getPermissions($this->iId);
 }
Esempio n. 4
0
 /**
  * Build and return admin interface
  *
  * Any module providing an admin interface is required to have this function, which
  * returns a string containing the (x)html of it's admin interface.
  * @return string
  */
 function getAdminInterface()
 {
     $this->template = 'admin/user.tpl';
     $this->addJS('/modules/User/js/admin.js');
     if (!$this->user->hasPerm('viewusermodule')) {
         return false;
     }
     switch (@$_REQUEST['section']) {
         case 'deleteUser':
             $user = new User($_REQUEST['id']);
             $user->delete();
             $this->setupMainList();
             $this->template = 'admin/user.tpl';
             break;
         case 'deleteGroup':
             $group = new Group($_REQUEST['id']);
             $group->delete();
             $groups = Group::getGroups();
             $this->smarty->assign('groups', $groups);
             return $this->smarty->fetch('admin/groups.tpl');
             break;
         case 'groups':
             $this->template = 'admin/groups.tpl';
             $groups = Group::getGroups();
             $this->smarty->assign('groups', $groups);
             break;
         case 'groupsaddedit':
             $form = Group::getAddEditForm();
             if ($form->validate() && $form->isSubmitted() && isset($_REQUEST['submit'])) {
                 $groups = Group::getGroups();
                 $this->smarty->assign('groups', $groups);
                 return $this->smarty->fetch('admin/groups.tpl');
             } else {
                 return $form->display();
             }
             break;
         case 'permissions':
             if (isset($_REQUEST['perm']) && isset($_REQUEST['group'])) {
                 $group = new Group($_REQUEST['group']);
                 $group->togglePerm($_REQUEST['perm']);
             }
             if (is_numeric(@$_REQUEST['group_view'])) {
                 $groups = array();
                 $groups[] = new Group($_REQUEST['group_view']);
                 $groupsView = Group::getGroups();
                 $this->smarty->assign('selectedGroup', $_REQUEST['group_view']);
             } else {
                 $groups = Group::getGroups();
                 $groupsView = $groups;
                 $this->smarty->assign('selectedGroup', null);
             }
             $this->template = 'admin/permissions.tpl';
             $permissions = Permission::getPermissions();
             $this->smarty->assign('permissions', $permissions);
             $this->smarty->assign('groups', $groups);
             $this->smarty->assign('groupsView', $groupsView);
             break;
         case 'userTable':
             $this->setupMainList();
             $this->template = 'admin/user_table.tpl';
             break;
         case 'addedit':
             $form = $this->getUserAddEditForm('/admin/User', true);
             if ($form->validate() && $form->isSubmitted() && (isset($_REQUEST['a_submit']) || isset($_REQUEST['a_cancel']))) {
                 $this->setupMainList();
                 return $this->smarty->fetch('admin/user.tpl');
             } else {
                 return $form->display();
             }
             break;
         default:
             $this->setupMainList();
             break;
     }
     return $this->smarty->fetch($this->template);
 }
Esempio n. 5
0
 /**
  * Process admin interface of this object
  *
  * @return void
  */
 public function processAdminUI()
 {
     Security::requirePermission(Permission::P('SERVER_PERM_EDIT_ROLES'), Server::getServer());
     $db = AbstractDb::getObject();
     $errmsg = "";
     // role_id
     $value = htmlspecialchars($this->getId(), ENT_QUOTES);
     // role_description_content_id
     if (empty($this->_row['role_description_content_id'])) {
         $name = "role_{$this->id}_description_new";
         $description = Content::processNewContentUI($name);
         if ($description != null) {
             $description_id = $description->GetId();
             $db->execSqlUpdate("UPDATE roles SET role_description_content_id = '{$description_id}' WHERE role_id = '{$this->id}'", FALSE);
         }
     } else {
         $description = Content::getObject($this->_row['role_description_content_id']);
         $name = "role_{$this->id}_description_erase";
         if (!empty($_REQUEST[$name]) && $_REQUEST[$name] == true) {
             $db->execSqlUpdate("UPDATE roles SET role_description_content_id = NULL WHERE role_id = '{$this->id}'", FALSE);
             $description->delete($errmsg);
         } else {
             $description->processAdminUI();
         }
     }
     // Permissions
     $permissionsArray = Permission::getPermissions(array('stakeholderTypeId' => $this->_row['stakeholder_type_id']));
     $idStr = $db->escapeString($this->getId());
     $stakeholderTypeIdStr = $db->escapeString($this->_row['stakeholder_type_id']);
     $sql = "SELECT permissions.permission_id, stakeholder_type_id, role_id FROM permissions LEFT JOIN role_has_permissions  ON (role_has_permissions.permission_id = permissions.permission_id AND role_id = '{$idStr}') WHERE stakeholder_type_id='{$stakeholderTypeIdStr}'";
     $db->execSql($sql, $permission_rows, false);
     $sql = null;
     if ($permission_rows) {
         foreach ($permission_rows as $row) {
             $permissionIdStr = $db->escapeString($row['permission_id']);
             $name = "role_{$this->id}_permission_" . htmlspecialchars($row['permission_id'], ENT_QUOTES) . "_included";
             if (empty($row['role_id']) && !empty($_REQUEST[$name]) && $_REQUEST[$name] == 'included') {
                 $sql = "INSERT INTO role_has_permissions (permission_id, role_id) VALUES ('{$permissionIdStr}','{$idStr}');\n";
             } else {
                 if (!empty($row['role_id']) && empty($_REQUEST[$name])) {
                     $sql = "DELETE FROM role_has_permissions WHERE permission_id='{$permissionIdStr}' AND role_id='{$idStr}';\n";
                 } else {
                     //echo "Do nothing for {$row['permission_id']}<br/>";
                 }
             }
         }
     }
     if ($sql) {
         $db->execSqlUpdate("BEGIN;\n{$sql}COMMIT;", false);
     }
     $this->refresh();
 }
Esempio n. 6
0
 /**
  * @param Permission $permission
  *
  * @return $this|self
  */
 public function merge(Permission $permission) : self
 {
     // merge filters
     foreach ($permission->getFilters() as $filter) {
         $found = false;
         foreach ($this->getFilters() as $current) {
             if ($current->getKey() == $filter->getKey()) {
                 $found = true;
                 $current->setFilters(array_unique(array_merge($filter->getFilters(), $current->getFilters())));
             }
         }
         if (!$found) {
             $this->childs[] = $filter;
         }
     }
     $this->childs = Permission::listMerge($this->childs, $permission->getPermissions());
     return $this;
 }