Use the profile instead of the login name in the view

This commit is contained in:
Dany De Bontridder 2015-09-04 13:25:00 +02:00
parent 28c5158bed
commit 08e9239052
3 changed files with 88 additions and 6 deletions

View file

@ -843,9 +843,9 @@ function show_module($selected)
me_code,me_menu,me_url,me_javascript,p_order,me_type,me_description
from v_all_menu
where
user_name=$1
p_id=$1
and p_type_display='M'
order by p_order", array($g_user->login));
order by p_order", array($g_user->get_profile()));
if ($selected != -1)
{
@ -853,7 +853,7 @@ function show_module($selected)
. ' pm_id = $1 ', array($selected));
require_once NOALYSS_INCLUDE.'/template/module.php';
$file = $cn->get_array("select me_file,me_parameter,me_javascript,me_type,me_description from v_all_menu
where pm_id=$1 and user_name=$2", array($selected,$g_user->login));
where pm_id=$1 and p_id=$2", array($selected,$g_user->get_profile()));
if ( count($file ) == 0 )
{
echo '</div>';

View file

@ -545,12 +545,13 @@ class User
/**
* Check if an user can access a module, return 1 if yes, otherwise 0
* record in audit log
* This function works only if user is connected to a Folder
* @param string $p_module menu_ref.me_code
*/
function check_module($p_module)
{
$acc = $this->db->get_value("select count(*) from v_all_menu where user_name = $1
and me_code=$2", array($this->login, $p_module));
$acc = $this->db->get_value("select count(*) from v_all_menu where p_id = $1
and me_code=$2", array($this->get_profile(), $p_module));
if ($acc == 0)
{
$this->audit("FAIL", $p_module);

View file

@ -182,4 +182,85 @@ language plpgsql;
select insert_menu();
drop function insert_menu();
drop function insert_menu();
CREATE OR REPLACE VIEW v_all_menu AS
SELECT pm.me_code,
pm.pm_id,
pm.me_code_dep,
pm.p_order,
pm.p_type_display,
p.p_name,
p.p_desc,
mr.me_menu,
mr.me_file,
mr.me_url,
mr.me_parameter,
mr.me_javascript,
mr.me_type,
pm.p_id,
mr.me_description
FROM profile_menu pm
JOIN profile p ON p.p_id = pm.p_id
JOIN menu_ref mr USING (me_code)
ORDER BY pm.p_order;
DROP FUNCTION comptaproc.get_profile_menu(text);
CREATE OR REPLACE FUNCTION comptaproc.get_profile_menu(p_profile integer)
RETURNS SETOF menu_tree AS
$BODY$
declare
a menu_tree;
e menu_tree;
begin
for a in select me_code,me_description from v_all_menu where p_id=p_profile
and me_code_dep is null and me_type <> 'PR' and me_type <>'SP'
loop
return next a;
for e in select * from get_menu_tree(a.code,p_profile)
loop
return next e;
end loop;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql ;
DROP FUNCTION comptaproc.get_menu_tree(text, text);
CREATE OR REPLACE FUNCTION comptaproc.get_menu_tree(p_code text, p_profile integer)
RETURNS SETOF menu_tree AS
$BODY$
declare
i menu_tree;
e menu_tree;
a text;
x v_all_menu%ROWTYPE;
begin
for x in select * from v_all_menu where me_code_dep=p_code::text and p_id=p_profile
loop
if x.me_code_dep is not null then
i.code := x.me_code_dep||'/'||x.me_code;
else
i.code := x.me_code;
end if;
i.description := x.me_description;
return next i;
for e in select * from get_menu_tree(x.me_code,p_profile)
loop
e.code:=x.me_code_dep||'/'||e.code;
return next e;
end loop;
end loop;
return;
end;
$BODY$
LANGUAGE plpgsql;