UFN_EXPORTDEFINITION_USERHASRIGHTSTOQUERYVIEWS

Returns true if user has rights to all of the query views used in the export definition.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@APPUSERID uniqueidentifier IN
@EXPORTDEFINITIONXML xml IN

Definition

Copy


CREATE function dbo.UFN_EXPORTDEFINITION_USERHASRIGHTSTOQUERYVIEWS(@APPUSERID uniqueidentifier, @EXPORTDEFINITIONXML xml)
        returns bit
        as
        begin

            declare @RETURNVALUE bit;
      declare @ISSYSADMIN bit;
            declare @HASQUERYVIEWSYSTEMPRIVILEGE bit = 0;

            select @ISSYSADMIN = ISSYSADMIN from dbo.APPUSER where ID = @APPUSERID;
            if @ISSYSADMIN = 0
                --This system privilege allows users access to all Query Views

                select @HASQUERYVIEWSYSTEMPRIVILEGE = dbo.UFN_SECURITY_APPUSER_GRANTED_SYSTEMPRIVILEGE_IN_SYSTEMROLE(@APPUSERID, '5f9bbcaf-9c67-4539-9880-ae4f709a9c1f')

            if (@ISSYSADMIN = 0 and @HASQUERYVIEWSYSTEMPRIVILEGE = 0)
            begin
                declare @OKVIEWS table (OBJECTNAME nvarchar(128));

                with xmlnamespaces ('bb_appfx_queryview' as tns, 'bb_appfx_commontypes' as common)
                insert into @OKVIEWS (OBJECTNAME)
                select QUERYVIEWCATALOG.OBJECTNAME from dbo.QUERYVIEWCATALOG
                where exists (
                    select [OKVIEWS].QUERYVIEWCATALOGID 
                    from dbo.UFN_SECURITY_GETGRANTEDQUERYVIEWSFORUSER(@APPUSERID) as [OKVIEWS] where [OKVIEWS].QUERYVIEWCATALOGID = QUERYVIEWCATALOG.ID)
                    or (coalesce(QUERYVIEWCATALOG.QUERYVIEWSPEC.value('(tns:QueryViewSpec/@SecurityUIDisplayFeature)[1]', 'bit'), 1) = 0 and
                            coalesce(QUERYVIEWCATALOG.QUERYVIEWSPEC.value('(tns:QueryViewSpec/@UseForExportDefinitionsOnly)[1]', 'bit'), 0) = 1);

                if exists (
                    select [QUERYVIEWSINUSE].OBJECTNAME 
                    from dbo.EXPORTDEFINITION
                    outer apply dbo.UFN_EXPORTDEFINITION_QUERYVIEWSINUSE(@EXPORTDEFINITIONXML) as [QUERYVIEWSINUSE]
                    where not exists (
                        select [OKVIEWS].OBJECTNAME 
                        from @OKVIEWS as [OKVIEWS] where [OKVIEWS].OBJECTNAME = [QUERYVIEWSINUSE].OBJECTNAME))
                begin
                    set @RETURNVALUE = 0;
                end
                else
                begin
                    set @RETURNVALUE = 1;
                end;
            end
            else
            begin
                set @RETURNVALUE = 1;
            end;

            return @RETURNVALUE;

        end;