Cannot assign permissions for custom form

Scriptcase v8.1.0005

To reproduce the issue:

  1. Sync Applications (adds custom form to sec_apps and sec_groups_apps)
  2. Choose Groups/Applications" to assign permissions for the new form; you will find that all of the priv_ fields are greyed out - except for priv_access (the user cannot assign privileges to these fields)

The issue is that the code (sec_sync_apps > events > OnValidate) is not writing the field “app_type” to the sec_apps table. In the “sec_form_sec_groups_apps” application / onscriptinit, it is trying to set arr_apps to the result set field “1” (app_type) - which is empty.

To verify that this is the problem:

  1. Sync Applications (adds custom form to sec_apps and sec_groups_apps)
  2. Choose Groups/Applications" to assign permissions for the new form; you will see that all of the priv_ fields are greyed out - except for priv_access.
  3. Now edit the database table sec_apps to add the word “form” in the app_type for the newly added application
  4. Choose Groups/Applications" to assign permissions for the new form; you will see that all of the priv_ fields are are now accessible.

It works with applications loaded into sec_apps by the security module but not with other (custom) applications.

It (sec_sync_apps > events > OnValidate) also does not read the contents of the ini file to get the friendly url which is used to populate the description field in sec_apps.

hi betty, if you mean by custom form = control then i guess it must have the options working, not greyed

please anybody from bugs team can confirm this for us? it is essential to have permissions for control application

(I am using the scriptcase group security module)

Scriptcase is using scandir to populate sec_apps with the list of files in the “…_lib\friendly_url” directory. They use the first 4 characters of that file name to populate the app_type field (but that’s not working).

So … when I say ‘custom form’ I am saying that I built a form to add employees to a database table; ie. “form_employee”. When I sync applications, it adds that new form to the sec_apps table and to the sec_groups_apps table; it does not populate the ‘app_type’ field in the sec_apps table. As a result, the options to set Permissions for insert, update, delete, export and print (in sec_groups_apps) are not active. To activate them, you have to add a value (ie. the word “form”) to the app_type field in sec_apps.

Further - if I later decide that I don’t need that application “form_employee” and I delete it from scriptcase, scriptcase removes it from the “app” directory - but not from the friendly_url directory. So when you sync apps again, it loads those (no longer existing) applications back into the sec_apps table. You have to remove them from the “…_lib\friendly_url” directory manually AND, even after you do that, you have to remove them manually from the Applications (sec_apps) table (but you can use the “Applications” app to do that).

[QUOTE=betty;40016]
Further - if I later decide that I don’t need that application “form_employee” and I delete it from scriptcase, scriptcase removes it from the “app” directory - but not from the friendly_url directory. So when you sync apps again, it loads those (no longer existing) applications back into the sec_apps table. You have to remove them from the “…_lib\friendly_url” directory manually AND, even after you do that, you have to remove them manually from the Applications (sec_apps) table (but you can use the “Applications” app to do that).[/QUOTE]

this issue is since very long time back, we discussed it here over and over, I remember Albert Aducom made it very short and straight forward, don’t play with security module, add it to the project at the last :slight_smile:

about the other issue, the friendly url, i didn’t like the way it works, it is supposed to make this better, but as you could see (and I encountered the same exactly earlier) it is making things worse, it is just useless feature accordingly to the name it has :slight_smile: so i just stopped using it, any app finally has its own folder, so why the bother!?

but for the permissions, if I understood your description correctly, then it is again the friendly-url as well, as in friendly-url obviously takes the first 4 chars to determine the application type!! is that even possible!!! however, i use many application types without first 4 chars as form or grid but without the friendly url… i do the same as you do (employees_form) or whatever, so this works ok with the permission… i guess if works ok without the friendly url then at least do not use it and keep this bug thread clear to flag it by SC guys and take the friendly url issues more seriously

I, too, considered not using the friendly_url … still not sure that I will … but it was driving me crazy that this does not work! Still not sure that I am going to use this - also not sure that I’ve done it ‘right’ or what the implications may be … brand new at PHP … but here is what I have working …

PROBLEM 1: The original code did nothing with applications that exist in sec_apps but no longer exist in the project. I added a function (PHP method) to remove deleted apps:

//Array of SEC_APPS Table ===============
sc_select(rs, “SELECT app_name FROM sec_apps”);

$arr_apx = array();
while(!$rs->EOF)
{
$arr_apx[] = $rs->fields[0] ;
$rs->MoveNext();
}
$rs->Close();

//Scan the master directory
$path_parts = pathinfo($this->Ini->path_aplicacao);
$dir = $path_parts[‘dirname’];
$master_directory = array_diff(scandir($dir), array(’…’, ‘.’, ‘_lib’));

//Difference between the two
$arr_gone=array_diff($arr_apx, $master_directory) ; //Records deleted from the project

foreach ($arr_gone as $k => $vc_gone)
{
//delete those records from sec_groups_apps
$sql = “DELETE from sec_groups_apps WHERE app_name = ‘$vc_gone’” ;
sc_exec_sql($sql);

//delete those records from sec_apps
$sql = "DELETE from sec_apps WHERE app_name = '$vc_gone'" ;
sc_exec_sql($sql);

}

PROBLEM 2:App_type was not getting populated in the sec_apps table and I was not able to apply insert, update, delete privileges to those applications. (As it turns out, it does not use the first 4 characters like I originally thought - but the 4th line of the ini file in the application directory). Essentially, I put a ‘foreach’ inside a ‘foreach’:

//Remove apps that are no longer in the project
remove_deleted_apps();

//Array of GROUPS ================
$arr_grp = array();
sc_select(rs, “SELECT group_id FROM sec_groups”);
while(!$rs->EOF)
{
$arr_grp[] = $rs->fields[0];
$rs->MoveNext();
}
$rs->Close();

//Array of SEC_APPS Table ini files ===============
sc_select(rs, “SELECT app_name FROM sec_apps”);

$arr_apps_db = array();
while(!$rs->EOF)
{
$arr_apps_db[] = $rs->fields[0] . ‘_ini.txt’;
$rs->MoveNext();
}
$rs->Close();

//Array of INI files in the friendly_url directory
$arr_friendly = array_diff(scandir($this->Ini->path_aplicacao . “…/_lib/friendly_url/”), array(’.’,’…’));

foreach($arr_friendly as $k => $vc_ininame)
{
//Get appname and dirname from friendly array
$app = substr($vc_ininame, 0, -8);
$friendly_name = file_get_contents($this->Ini->path_aplicacao . “…/_lib/friendly_url/”. $app . ‘_ini.txt’);
$proj_name = ’ ’ ;
$app_type = ’ ’ ;

//omit mobile apps
if(substr($app, -4) == '_mob' && file_exists($this->Ini->path_aplicacao . "../_lib/friendly_url/". substr($app, 0, -4) . "_ini.txt"))
{
	unset($arr_friendly[$k]);
	continue;
}

//Scan the master directory
$path_parts = pathinfo($this->Ini->path_aplicacao);
$dir    = $path_parts['dirname'];
$master_directory = array_diff(scandir($dir), array('..', '.', '_lib'));

//Difference between the master directory and sec_apps
$arr_apps = array_diff($master_directory, $arr_apps_db);

//This gives me what I want
foreach($arr_apps as $k => $app_name)
{

//Get apptype from ini file in master directory
$file_ini = $this->Ini->path_aplicacao. "../".$app_name . "/". $vc_ininame;
if(is_file($file_ini))
	{
	$lines = file($file_ini);
	if(isset($lines[4]))
				$app_type = trim($lines[4]);
	if(isset($lines[1]))
		$proj_name = trim($lines[1]) ;
	
$sql = "SELECT count(*) FROM sec_apps WHERE app_name = '". $app_name ."' ";
sc_lookup(rs, $sql);
if({rs[0][0]} == 0)
{
	$sql = "INSERT INTO sec_apps(app_name, app_type) VALUES ('". $app_name ."', '".$app_type."')";
	sc_exec_sql( $sql );
	foreach($arr_grp as $grp)
	{
		$sql = "INSERT INTO sec_groups_apps(app_name, group_id) VALUES ('". $app_name ."', '". $grp ."')";
		sc_exec_sql( $sql );
	}
} 
	} 
} //end 2nd foreach loop

} //end first foreach loop

This is how I fixed it

Problem #1 - It does not populate the app_type field in sec_apps; causing the inability to assign permissions to update, delete, insert in sec_groups_apps. (It gets the app_type from the 4th line in the ini file that is found in the application directory, btw - not the 4th character).

This is what I did to fix it:

    $vc_dir = ($this->Ini->path_aplicacao) ; <-- Added this line (the path was including the name of the current application (sec_sync_apps); I am truncating this in $file_ini to remove that 
$_app_type = '' ; <-- Added this line because after I added $vc_dir variable I was getting an offset error
/*$file_ini = $this->Ini->path_aplicacao. "../". trim($friendly_name) . "/".$app ."_ini.txt";*/ <-- removed this line
$file_ini = substr($vc_dir, 0, -14) . "/". trim($friendly_name) . "/".$app ."_ini.txt"; <-- Added this line; note that I am trimming $friendly_name because it had an embedded space in it

(Still not perfect but better than it was!)

Hello,

This problem is already registered for our development team. As soon as I have some feedback, I will contact you.

Thanks John

It is still bug till now. But you can directly update the tables with the permission you want.

www.LiviApps.com (Scriptcase International)
www.OwenSolution.com (Scriptcase Indonesia)