I recently blogged about how to security trim contents of a page using the Security Trim Control, it works great for content on the page but what about contents within a web part I was asked, for example that of a DataView web part. Well that’s easy too, all you need is a little less known built in XSLT function called ddwrt:IfHasRights(<Permission Mask>)) and some Conditional Formatting logic.

  1. Simply select the text or mark-up inside the data view web part and then
  2. Click on Conditional Formatting option in the Task Panes menu
  3. In the Condition Criteria dialog box select Advanced and in the Advanced Condition dialog box change Select a function category to All
  4. Find and insert the IfHasRights() function by double clicking on the Select a function list
  5. Use a single Permission Mask for example 4 IfHasRights(4) to only make the mark-up or text visible when the user has edit rights on the page\item

Following is a list of Permission Masks for the build in permissions

  • ViewListItems – 1
  • AddListItems – 2
  • EditListItems – 4
  • DeleteListItems – 8
  • ApproveItems – 16
  • OpenItems – 32
  • ViewVersions – 64
  • DeleteVersions – 128
  • CancelCheckout – 256
  • PersonalViews – 512
  • ManageLists – 2048
  • ViewFormPages – 4096
  • Open – 65536
  • ViewPages – 131072
  • AddAndCustomizePages – 262144
  • ApplyThemeAndBorder – 524288
  • ApplyStyleSheets – 1048576
  • ViewUsageData – 2097152
  • CreateSSCSite – 4194314
  • ManageSubwebs – 8388608
  • CreateGroups – 16777216
  • ManagePermissions – 33554432
  • BrowseDirectories – 67108864
  • BrowseUserInfo – 134217728
  • AddDelPrivateWebParts – 268435456
  • UpdatePersonalWebParts – 536870912
  • ManageWeb – 1073741824
  • UseRemoteAPIs – 137438953472
  • ManageAlerts – 274877906944
  • CreateAlerts – 549755813888
  • EditMyUserInfo – 1099511627776
  • EnumeratePermissions – 4611686018427387904
  • FullMask – 9223372036854775807
Advertisements