UFN_SECURITY_APPUSER_GRANTED_BATCHTEMPLATEONLY

Returns true if user has been granted and not denied the batch template for a system role. This does not check the batch type

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@APPUSERID uniqueidentifier IN
@BATCHTEMPLATEID uniqueidentifier IN

Definition

Copy


create function dbo.UFN_SECURITY_APPUSER_GRANTED_BATCHTEMPLATEONLY
(@APPUSERID uniqueidentifier,@BATCHTEMPLATEID uniqueidentifier)
returns bit
as
/*
Returns true if user has been granted and not denied the batch type for a System Role.
*/
begin
    --If at least one grant and no deny then return true

    --otherwise, false

    declare @grant bit;
    set @grant=0;

    select @grant = ISSYSADMIN from dbo.APPUSER where ID = @APPUSERID;

    if @grant = 0 
        begin
            --order by GRANTORDENY, deny will be first.

             select   
                top 1 @grant=SECURITYVIEW.GRANTORDENY  
             from   
                dbo.V_SECURITY_SYSTEMROLEASSIGNMENT_USER_BATCHTEMPLATE SECURITYVIEW  
                with (NOEXPAND, INDEX(IX_V_SECURITY_SYSTEMROLEASSIGNMENT_USER_BATCHTEMPLATE_BATCHTEMPLATEID_APPUSERID_GRANTORDENY))  
             where   
                SECURITYVIEW.APPUSERID = @APPUSERID  
             and   
                SECURITYVIEW.BATCHTEMPLATEID=@BATCHTEMPLATEID      
             and   
                ((SECURITYVIEW.SITEID is null) or (dbo.UFN_SITEALLOWEDFORUSER(@APPUSERID,SECURITYVIEW.SITEID) = 1))  
             order by   
                SECURITYVIEW.GRANTORDENY ASC;  
        end

    return @grant;                
end