====== pears.NetHasPermission ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
COMMENT TO PRESERVE FORMAT ON PROCEDURE "pears"."NetHasPermission" IS
{create FUNCTION pears."NetHasPermission"( in pWebUserID char(20), in pPersonID char(20), in pCompanyID char(20) )
RETURNS INTEGER
// IQXWeb
BEGIN
DECLARE "rv" INTEGER;
declare userclass char(20);
declare divid char(20);
set rv=0;
select iqxnetuserclassid into userclass from iqxnetuser where iqxnetuserid=pwebuserid;
if userclass='CANDIDATE' then
set rv=(select first 1 from iqxnetuserlink where personid=ppersonid and iqxnetuserid=pwebuserid)
else if userclass='CLIENT' then
set rv=(select first 1 from employment as e key join iqxnetuserlink as x where e.companyid=pcompanyid and x.iqxnetuserid=pwebuserid)
else if userclass='AGENCY' then
set rv=(select first 1 from pay_employee as pe key join company key join employment key join iqxnetuserlink as x where pe.personid=ppersonid and x.iqxnetuserid=pwebuserid)
else if userclass='OWNER' then
set divid=isnull((select first divisionid from person where personid=pPersonID order by 1),(select first divisionid from company where companyid=pCompanyID order by 1),'');
if divid in (select DivisionID from DashboardStaffDivisions()) then
set rv=1
end if;
end if
end if
end if
end if;
RETURN isnull(rv,0)
END
/* DOC
2016-08-30 PC doc and test
2018-10-22 MHS improved OWNER logic to properly respect staff division rights
inputs:
pWebUserID
pPersonID
pCompanyID
outputs:
(integer) - 0 or 1
tests:
test all null
test invalid pWebUserID
test valid pWebUserID as person and invalid pPersonID
test valid pWebUserID as person and valid pPersonID
test valid pWebUserID as client and pPersonID and valid pCompanyID
test valid pWebUserID as agency and pPersonID and valid pCompanyID
test valid pWebUserID as owner and pPersonID and valid pCompanyID
*/
/* TEST
call NetTestSetup('','NetHasPermission');
update company set divisionid='test' where companyid='test';
update person set divisionid='TEST' where personid='test';
update staff set divisionid='TEST' where staffid='TEST';
insert into pay_employee (personid, secondaryagencyid) on existing update values ('test','test');
select NetHasPermission(null,null,null);
expect 0;
select NetHasPermission('test.candidate','T9',null);
expect 0;
select NetHasPermission('test.candidate','Test',null);
expect 1;
select NetHasPermission('TEST.client','test','test');
expect 1;
select NetHasPermission('TEST.agency','test','test');
expect 1;
select NetHasPermission('TEST.owner','test','test');
expect 1;
*/
}