UFN_CONSTITUENT_GETRECORDSINSELECTION_FORBUSINESSPROCESS
Filters constituent records in a selection based on site and record access security.
Return
Return Type |
---|
table |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@CURRENTAPPUSERID | uniqueidentifier | IN | |
@IDSETREGISTERID | uniqueidentifier | IN | |
@BUSINESSPROCESSCATALOGID | uniqueidentifier | IN | |
@BYPASSSECURITY | bit | IN | |
@BYPASSSITESECURITY | bit | IN |
Definition
Copy
CREATE function dbo.UFN_CONSTITUENT_GETRECORDSINSELECTION_FORBUSINESSPROCESS
(
@CURRENTAPPUSERID uniqueidentifier,
@IDSETREGISTERID uniqueidentifier,
@BUSINESSPROCESSCATALOGID uniqueidentifier,
@BYPASSSECURITY bit,
@BYPASSSITESECURITY bit
)
returns @IDSETRECORDS table (ID uniqueidentifier)
as
begin
declare @IDSETRECORDTYPEID uniqueidentifier
select @IDSETRECORDTYPEID = RECORDTYPEID from dbo.IDSETREGISTER where ID = @IDSETREGISTERID
if @IDSETRECORDTYPEID is null or @IDSETRECORDTYPEID = dbo.UFN_RECORDTYPE_GETIDBYNAME('CONSTITUENT') -- Check the record type of the selection first
begin
if @BYPASSSECURITY = 0 or @BYPASSSITESECURITY = 0
begin
if @IDSETREGISTERID is not null
begin
insert into @IDSETRECORDS(ID)
select
SELECTEDCONSTITUENTS.ID
from
dbo.UFN_IDSETREADER_GETRESULTS_GUID(@IDSETREGISTERID) SELECTEDCONSTITUENTS
left join dbo.UFN_SECURITY_APPUSER_GRANTED_CONSTITIDS_FORBUSINESSPROCESS(@CURRENTAPPUSERID, @BUSINESSPROCESSCATALOGID) as CONSTIT_RACS on SELECTEDCONSTITUENTS.ID = CONSTIT_RACS.ID
where
(@BYPASSSECURITY = 1 or CONSTIT_RACS.ID is not null)
and
(
@BYPASSSITESECURITY = 1 or
exists
(
select 1
from dbo.CONSTITUENT --JamesWill WI170986 2011-08-15 Make sure to check if null site is allowed for constituents with no entries in CONSTITUENTSITE
left join dbo.CONSTITUENTSITE on CONSTITUENTSITE.CONSTITUENTID = CONSTITUENT.ID
where CONSTITUENT.ID = SELECTEDCONSTITUENTS.ID
and dbo.UFN_SECURITY_APPUSER_GRANTED_BUSINESSPROCESS_FORSITE(@CURRENTAPPUSERID, @BUSINESSPROCESSCATALOGID, CONSTITUENTSITE.SITEID) = 1
)
);
end
else
begin
insert into @IDSETRECORDS(ID)
select
SELECTEDCONSTITUENTS.ID
from
dbo.CONSTITUENT SELECTEDCONSTITUENTS
left join dbo.UFN_SECURITY_APPUSER_GRANTED_CONSTITIDS_FORBUSINESSPROCESS(@CURRENTAPPUSERID, @BUSINESSPROCESSCATALOGID) as CONSTIT_RACS on SELECTEDCONSTITUENTS.ID = CONSTIT_RACS.ID
where
(@BYPASSSECURITY = 1 or CONSTIT_RACS.ID is not null)
and
(
@BYPASSSITESECURITY = 1 or
exists
(
select 1
from dbo.CONSTITUENT --JamesWill WI170986 2011-08-15 Make sure to check if null site is allowed for constituents with no entries in CONSTITUENTSITE
left join dbo.CONSTITUENTSITE on CONSTITUENTSITE.CONSTITUENTID = CONSTITUENT.ID
where CONSTITUENT.ID = SELECTEDCONSTITUENTS.ID
and dbo.UFN_SECURITY_APPUSER_GRANTED_BUSINESSPROCESS_FORSITE(@CURRENTAPPUSERID, @BUSINESSPROCESSCATALOGID, CONSTITUENTSITE.SITEID) = 1
)
);
end
end
else
begin
if @IDSETREGISTERID is not null
begin
insert into @IDSETRECORDS(ID)
select
ID
from
dbo.UFN_IDSETREADER_GETRESULTS_GUID(@IDSETREGISTERID);
end
else
begin
insert into @IDSETRECORDS(ID)
select
ID
from
dbo.CONSTITUENT;
end
end
--AdamBu - Bug 40526 - If the selection used is static, make sure none of the records it contains have been deleted.
if exists(
select 1
from dbo.IDSETREGISTER
where ID = @IDSETREGISTERID and STATIC = 1
)
begin
delete @IDSETRECORDS
where ID not in(
select ID from CONSTITUENT
)
end
end
return
end