UFN_APPUSER_DEFAULTSITEFORUSER

Returns the user's default site if the user is in a system role that allows access to it, otherwise null. Used for defaulting in site.

Return

Return Type
uniqueidentifier

Parameters

Parameter Parameter Type Mode Description
@APPUSERID uniqueidentifier IN

Definition

Copy


            CREATE function dbo.UFN_APPUSER_DEFAULTSITEFORUSER
            (
                @APPUSERID uniqueidentifier
            )
            returns uniqueidentifier
            as begin
                declare @SITEID uniqueidentifier = null;

                declare @HASRIGHTS bit = 0;

                select @HASRIGHTS = dbo.UFN_APPUSER_ISSYSADMIN(@APPUSERID)

                if @HASRIGHTS = 0
                    if exists(select SYSTEMROLEAPPUSER.ID from dbo.SYSTEMROLEAPPUSER where SYSTEMROLEAPPUSER.APPUSERID = @APPUSERID and SYSTEMROLEAPPUSER.SECURITYMODECODE = 0)
                        set @HASRIGHTS = 1

                if @HASRIGHTS = 1
                    select @SITEID = SITEID from dbo.APPUSER where APPUSER.ID = @APPUSERID
                else
                    select 
                        @SITEID = SITEID 
                    from 
                        dbo.APPUSER
                    where 
                        SITEID in
                            (
                                select 
                                    SITEID 
                                from 
                                    dbo.SITEPERMISSION
                                where
                                    SITEPERMISSION.APPUSERID = APPUSER.ID
                            )
                        and APPUSER.ID = @APPUSERID;

                return @SITEID;
            end