UFN_SECURITY_GETGRANTEDSMARTQUERIESFORUSER

Return

Return Type
table

Parameters

Parameter Parameter Type Mode Description
@APPUSERID uniqueidentifier IN

Definition

Copy


CREATE function dbo.UFN_SECURITY_GETGRANTEDSMARTQUERIESFORUSER(@APPUSERID uniqueidentifier)
returns table
as
--If the appuser is a sysadmin this function should not be used, just select ID from SMARTQUERYCATALOG 

return
(
    with assignedperms as 
    (
        select 
            [SRP].SMARTQUERYCATALOGID as FEATUREID,
            [SRP].GRANTORDENY
        from dbo.V_SECURITY_SYSTEMROLEASSIGNMENT_USER_SMARTQUERY as [SRP]
        where SRP.APPUSERID=@APPUSERID
    )
    select distinct FEATUREID as SMARTQUERYCATALOGID from assignedperms
    where GRANTORDENY=1
    and FEATUREID not in 
        --explicitly denied smart queries in system roles

        (
            select FEATUREID from assignedperms where (GRANTORDENY=0)
        )
)