{"id":1773,"date":"2017-04-06T14:41:34","date_gmt":"2017-04-06T12:41:34","guid":{"rendered":"https:\/\/blog.kodono.info\/wordpress\/?p=1773"},"modified":"2017-05-02T18:48:15","modified_gmt":"2017-05-02T16:48:15","slug":"check-permissions-in-sharepoint-based-on-a-permmask","status":"publish","type":"post","link":"https:\/\/blog.kodono.info\/wordpress\/2017\/04\/06\/check-permissions-in-sharepoint-based-on-a-permmask\/","title":{"rendered":"Check permissions in Sharepoint based on a PermMask"},"content":{"rendered":"<p>In some cases you could get this kind of hexadecimal numbers from Sharepoint for the PermMask: <code>0xb008431061<\/code>, or <code>0x1b03c4313ff<\/code>, and so on.<\/p>\n<p>To verify the PermMask against the different level of permissions you can proceed with the below method (using functions from <code>core.js<\/code>):<\/p>\n<pre class=\"brush:javascript\">\r\nvar permMask = '0x1b03c4313ff';\r\nvar permissions = new SP.BasePermissions();\r\npermissions.initPropertiesFromJson({High:GetPermMaskH(permMask), Low:GetPermMaskL(permMask)});\r\n\/\/ we can now check permissions using SP.BasePermissions.has()\r\n\/\/ and we can compare with SP.PermissionKind \u2014 see https:\/\/msdn.microsoft.com\/en-us\/library\/office\/ee556747(v=office.14).aspx\r\nvar canEdit = permissions.has(SP.PermissionKind.editListItems);\r\n<\/pre>\n<p>On Sharepoint 2010 <code>GetPermMaskH<\/code> and <code>GetPermMaskL<\/code> are not defined, so here is their code:<\/p>\n<pre class=\"brush:javascript\">\r\nfunction GetPermMaskH(b) {\r\n    var a = b.length;\r\n    return a &lt;= 10 ? 0 : parseInt(b.substring(2, a - 8), 16)\r\n}\r\n\r\nfunction GetPermMaskL(b) {\r\n    var a = b.length;\r\n    return a &lt;= 10 ? parseInt(b) : parseInt(b.substring(a - 8, a), 16)\r\n}\r\n<\/pre>\n<p>It took me many hours to find how to proceed, so I hope it will help some others.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In some cases you could get this kind of hexadecimal numbers from Sharepoint for the PermMask: 0xb008431061, or 0x1b03c4313ff, and so on. To verify the PermMask against the different level of permissions you can proceed with the below method (using functions from core.js): var permMask = &#8216;0x1b03c4313ff&#8217;; var permissions = new SP.BasePermissions(); permissions.initPropertiesFromJson({High:GetPermMaskH(permMask), Low:GetPermMaskL(permMask)}); \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","hide_page_title":"","footnotes":""},"categories":[170,13,33],"tags":[24,152,158,117],"class_list":["post-1773","post","type-post","status-publish","format-standard","hentry","category-english","category-niveau-intermediaire","category-programmation","tag-javascript","tag-niveau-intermediaire","tag-programmation","tag-sharepoint"],"_links":{"self":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1773"}],"version-history":[{"count":3,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1773\/revisions"}],"predecessor-version":[{"id":1783,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/posts\/1773\/revisions\/1783"}],"wp:attachment":[{"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kodono.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}