UFN_SITESFORUSER

Returns a list of Sites that the user could interact with based on role assignments.

Return

Return Type
table

Parameters

Parameter Parameter Type Mode Description
@CURRENTAPPUSERID uniqueidentifier IN

Definition

Copy


CREATE function dbo.UFN_SITESFORUSER 
(
  @CURRENTAPPUSERID uniqueidentifier
)
returns @T table (SITEID uniqueidentifier primary key)
as
begin
  /*Return all sites if the application user is a system administrator or is assigned to a role with access to all sites*/
  if (select [ISSYSADMIN] from dbo.[APPUSER] where [ID] = @CURRENTAPPUSERID) = 1 or exists(SELECT SYSTEMROLEAPPUSER.ID from dbo.SYSTEMROLEAPPUSER where SYSTEMROLEAPPUSER.APPUSERID = @CURRENTAPPUSERID and SYSTEMROLEAPPUSER.SECURITYMODECODE = 0) begin
    insert into @T(SITEID) 
      select SITE.ID
      from dbo.SITE;

    return;
  end

  insert into @T(SITEID)
    select distinct 
      SITEID 
    from dbo.SITEPERMISSION 
    where SITEPERMISSION.APPUSERID = @CURRENTAPPUSERID;

  return;
end