UFN_ORGANIZATIONHIERARCHY_GETPARENTWITHSECURITY
Returns the first parent record that the user has rights to.
Return
Return Type |
---|
uniqueidentifier |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@POSITIONID | uniqueidentifier | IN | |
@CURRENTAPPUSERID | uniqueidentifier | IN |
Definition
Copy
create function dbo.UFN_ORGANIZATIONHIERARCHY_GETPARENTWITHSECURITY
(
@POSITIONID uniqueidentifier,
@CURRENTAPPUSERID uniqueidentifier
)
returns uniqueidentifier
as
begin
declare @RETVAL uniqueidentifier;
declare @HASRIGHTS bit;
declare @ITERATION integer;
set @ITERATION = 1;
set @RETVAL = @POSITIONID;
--Using while loop instead of recursion
--protect against runaway process
while @ITERATION < 100
begin
select @RETVAL = PARENT.ID,
@HASRIGHTS = dbo.UFN_SITEALLOWEDFORUSER(@CURRENTAPPUSERID, PARENT.SITEID)
from dbo.ORGANIZATIONHIERARCHY
inner join dbo.ORGANIZATIONPOSITION PARENT
on ORGANIZATIONHIERARCHY.PARENTID = PARENT.ID
where ORGANIZATIONHIERARCHY.ID = @RETVAL
--If we the use has rights to the parent of there is no parent
if @HASRIGHTS = 1 or @RETVAL is null
return @RETVAL;
set @ITERATION = @ITERATION + 1
end
return null;
end