<commit_before><?php
/**
 * Permission to execute actions
 *
 * @author Anakeen 2000 
 * @version $Id: Class.Permission.php,v 1.10 2006/06/01 12:54:05 eric Exp $
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package WHAT
 * @subpackage CORE
 */
 /**
 */

include_once('Class.DbObj.php');
include_once('Class.QueryDb.php');
include_once('Class.Application.php');
include_once('Class.Action.php');
include_once('Class.Acl.php');
include_once('Class.User.php');
include_once('Class.Group.php');

Class Permission extends DbObj
{
  var $fields = array ( "id_user","id_application","id_acl", "computed");

  var $id_fields = array ( "id_user","id_application");

  var $dbtable = "permission";
  var $privileges = array(); // privileges array for a user (including group) in an application
  private $upprivileges = false; // specifific privileges array for a user in an application
  private $unprivileges = false; // specifific NO privileges array for a user in an application
  private $gprivileges = false; // privileges array for the group user

  var $sqlcreate = '
create table permission (id_user int not null,
                         id_application int not null,
                         id_acl int not null,
                         computed boolean default false);
create index permission_idx1 on permission(id_user);
create index permission_idx2 on permission(id_application);
create index permission_idx3 on permission(id_acl);
create index permission_idx4 on permission(computed);
                 ';

  var $actions = array(); // actions array for a user (including group) in an application

  function __construct($dbaccess='', $id='', $res='', $dbid=0, $computed=true)
    {
      parent::__construct($dbaccess, $id,$res,$dbid);
      if (! $this->isAffected()) {
      
	if (is_array($id)) {
	  $this->Affect(array("id_user" => $id[0],
			      "id_application" => $id[1],
			      "computed" => $id[2]));
	  $this-> GetPrivileges(false, $computed);
	}
      }

    }
  function PostSelect()
    {
      // init privileges
      $this-> GetPrivileges();
    }
  function PostDelete()
    {
      // update privileges
      $this-> GetPrivileges();
    }

  function PostUpdate()
    {
      // update privileges
      $this-> GetPrivileges();
    }

  function PreInsert( )
    {
      // no duplicate items
      if ($this->Exists($this->id_user,$this->id_application,$this->id_acl)) return "Permission ({$this->id_user},{$this->id_application},{$this->id_acl}) already exists...";  
  
      return "";
  
    }
  // Gives the list of Permission for a user on an application
  function ListUserPermissions($user,$app)
    {<commit_msg>correct permission ACCESS (closes #539)<commit_after><?php
/**
 * Permission to execute actions
 *
 * @author Anakeen 2000 
 * @version $Id: Class.Permission.php,v 1.10 2006/06/01 12:54:05 eric Exp $
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 * @package WHAT
 * @subpackage CORE
 */
 /**
 */

include_once('Class.DbObj.php');
include_once('Class.QueryDb.php');
include_once('Class.Application.php');
include_once('Class.Action.php');
include_once('Class.Acl.php');
include_once('Class.User.php');
include_once('Class.Group.php');

Class Permission extends DbObj
{
  var $fields = array ( "id_user","id_application","id_acl", "computed");

  var $id_fields = array ( "id_user","id_application");

  var $dbtable = "permission";
  var $privileges = array(); // privileges array for a user (including group) in an application
  private $upprivileges = false; // specifific privileges array for a user in an application
  private $unprivileges = false; // specifific NO privileges array for a user in an application
  private $gprivileges = false; // privileges array for the group user

  var $sqlcreate = '
create table permission (id_user int not null,
                         id_application int not null,
                         id_acl int not null,
                         computed boolean default false);
create index permission_idx1 on permission(id_user);
create index permission_idx2 on permission(id_application);
create index permission_idx3 on permission(id_acl);
create index permission_idx4 on permission(computed);
                 ';

  var $actions = array(); // actions array for a user (including group) in an application

  function __construct($dbaccess='', $id='', $res='', $dbid=0, $computed=true)
    {
      parent::__construct($dbaccess, $id,$res,$dbid);
      if (! $this->isAffected()) {
      
	if (is_array($id)) {
	  $this->Affect(array("id_user" => $id[0],
			      "id_application" => $id[1],
			      "computed" => $id[2]));
	  $this-> GetPrivileges(false, $computed);
	}
      }

    }
  function PostSelect()
    {
      // init privileges
      $this-> GetPrivileges();
    }
  function PostDelete()
    {
      // update privileges
      $this-> GetPrivileges();
    }

  function PostUpdate()
    {
      // update privileges
      $this-> GetPrivileges();
    }

  function PreInsert( )
    {
      // no duplicate items
      if ($this->Exists($this->id_user,$this->id_application,$this->id_acl)) return "Permission ({$this->id_user},{$this->id_application},{$this->id_acl}) already exists...";  
  
      return "";
  
    }
  function postInsert( )    {
    if (! $this->computed) {
      $this->exec_query(sprintf("delete from permission where id_user=%d and id_application=%d and abs(id_acl)=%d and computed",
				$this->id_user,
				$this->id_application,
				$this->id_acl));      
    }
  
      return "";
  
    }
  // Gives the list of Permission for a user on an application
  function ListUserPermissions($user,$app)
    {
{'fraction_non_alphanumeric': 0.13866947516236616, 'fraction_numerical': 0.010707389854309286, 'mean_word_length': 3.174358974358974, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5915979', 'n_tokens_mistral': 1807, 'n_tokens_neox': 1699, 'n_words': 451}