• CRM PrincipalObjectAccess(POA)


    PrincipalObjectAccess (POA) table is an important table which holds all grants share on CRM objects. This is just for understanding purpose.

    SELECT TOP 100
     [PrincipalObjectAccessId]
     ,[PrincipalId]
     ,[PrincipalTypeCode]
     ,[ObjectId]
     ,[ObjectTypeCode]
     ,[AccessRightsMask]
     ,[InheritedAccessRightsMask]
    FROM
     [PrincipalObjectAccess] WITH (NOLOCK)

    PrincipalObjectAccessId – The GUID of share record.
    PrincipalId – The GUID of the User or Team receiving the Share.
    PrincipalTypeCode – indicates whether it’s a User or Team. -- 8 user 9 team
    ObjectId – The GUID of the specific object being shared.
    ObjectTypeCode – The object type of the record being shared.
    AccessRightsMask – This field stores the rights granted directly via the ‘Sharing’ dialog.
    InheritedAccessRightsMask – The rights applied by the system through cascading or reassignment processes are stored in this field.

    check microsoft query to control this table data..

    InheritedAccessRightsMask – The rights applied by the system through cascading or reassignment processes are stored in this field.

    1 User

    2 Business Unit

    4 Parent: Child

    8 Organization


    Decoding the RightsMask Fields (AccessRightsMask and InheritedAccessRightsMask)

    0               No permission
    1                  Read
    2                  Write
    4                  Append
    16                AppendTo
    32                Create
    65536           Delete
    262144          Share
    524288          Assign
    134217728    Undocumented

    for example 
    852023 (1+2+4+16+32+65536+262144+524288) - ALL documneted permissions

    Whenever a record is shared against a User or a Team, CRM will be tracking those entries in PincipalObjectAccess table and same will be queried using FilteredView.

    FilteredAccount View part of code

    or

    [Account].[AccountId] in
    (
    select  POA.ObjectId from PrincipalObjectAccess POA
    join SystemUserPrincipals sup (NOLOCK) on POA.PrincipalId = sup.PrincipalId
    where sup.SystemUserId = u.SystemUserId and
    POA.ObjectTypeCode = 1 and
    ((POA.AccessRightsMask | POA.InheritedAccessRightsMask) & 1)=1
    )
    
    ---Get the total number of shared records
    SELECT COUNT(0) FROM PrincipalObjectAccess
    
    --Get the total number of shared records grouped by Entity
    SELECT  EV.NAME AS [ENTITY NAME],COUNT(POA.OBJECTTYPECODE) AS [RECORDS COUNT]
    FROM PRINCIPALOBJECTACCESS POA
    INNER JOIN ENTITYLOGICALVIEW EV ON EV.OBJECTTYPECODE = POA.OBJECTTYPECODE
    GROUP BY EV.NAME
    ORDER BY 2 DESC
    
    --Get the total number of shared records grouped by User
    SELECT  SU.FULLNAME AS [USER NAME],COUNT(POA.OBJECTTYPECODE) AS [RECORDS COUNT]
    FROM PRINCIPALOBJECTACCESS POA
    INNER JOIN SYSTEMUSER SU ON POA.PRINCIPALID= SU.SYSTEMUSERID
    GROUP BY SU.FULLNAME
    ORDER BY 2 DESC
    
    --Get the total number of shared records grouped by Entity and User
    SELECT  SU.FULLNAME AS [USER NAME],EV.NAME AS [ENTITY NAME],COUNT(POA.OBJECTTYPECODE) AS [RECORDS COUNT]
    FROM PRINCIPALOBJECTACCESS POA
    INNER JOIN SYSTEMUSER SU ON POA.PRINCIPALID= SU.SYSTEMUSERID
    INNER JOIN ENTITYLOGICALVIEW EV ON EV.OBJECTTYPECODE = POA.OBJECTTYPECODE
    GROUP BY SU.FULLNAME,EV.NAME
    ORDER BY 1
    
    SELECT DISTINCT name, objecttypecode
    FROM [CRMORGDB_MSCRM].[MetadataSchema].[Entity]
    ORDER BY name ASC 
    
     
    
    
    select distinct
           case
               when POA.[PrincipalTypeCode] = 8 then
                   'User'
               when POA.[PrincipalTypeCode] = 9
                    and TEAM.[TeamType] = 0 then
                   'Owner Team'
               when POA.[PrincipalTypeCode] = 9
                    and TEAM.[TeamType] = 1 then
                   'Access Team'
               else
                   'Other'
           end                                       as 'PrincipalType'
         , coalesce(USERID.[FirstName], TEAM.[Name]) as PrincipalName
         , POA.[ObjectTypeCode]
         , ENTITY.[OriginalLocalizedName]
         , POA.[ObjectId]
         , POA.[AccessRightsMask]
         , POA.[InheritedAccessRightsMask]
         , POA.[ChangedOn]
         , POA.[PrincipalTypeCode]
         , POA.[PrincipalId]
    from KYGF_MSCRM.[dbo].[PrincipalObjectAccess]            as POA
        left outer join KYGF_MSCRM.[dbo].[SystemUserBase]    as USERID
            on POA.[PrincipalId] = USERID.[SystemUserId]
        left outer join KYGF_MSCRM.[dbo].[TeamBase]          as TEAM
            on POA.[PrincipalId] = TEAM.[TeamId]
        left outer join KYGF_MSCRM.[MetadataSchema].[Entity] as ENTITY
            on POA.[ObjectTypeCode] = ENTITY.[ObjectTypeCode]
    where POA.[PrincipalTypeCode] in ( 8, 9 )
          and POA.[ObjectTypeCode] = 2
          and POA.ObjectId = 'C84FBA58-8CCB-DF11-9176-02BF0AC9DF07';
  • 相关阅读:
    美国航天局的十大编码戒律(转)
    大型数据库应用解决方案总结
    IOCP模型
    SSH 连接慢的解决方案详解
    指针(详解)【转】
    有关推挽输出、开漏输出、复用开漏输出、复用推挽输出以及上拉输入、下拉输入、浮空输入、模拟输入区别【转】
    USB入门开发的八个问题&USB枚举『转』
    浅谈 STM32 硬件I2C的使用 (中断方式 无DMA 无最高优先级)(转)
    KEIL Code RO-data RW-data ZI-data 【转】
    262K Color
  • 原文地址:https://www.cnblogs.com/BinBinGo/p/5820127.html
Copyright © 2020-2023  润新知