{"id":155,"date":"2010-07-30T10:21:50","date_gmt":"2010-07-30T09:21:50","guid":{"rendered":"http:\/\/www.italkcode.net\/?p=100"},"modified":"2010-07-30T10:21:50","modified_gmt":"2010-07-30T09:21:50","slug":"revoke-permissions-from-roledefinition","status":"publish","type":"post","link":"https:\/\/commonware.nl\/?p=155","title":{"rendered":"Revoke Permissions from RoleDefinition"},"content":{"rendered":"<p>I had to revoke some of the permissions of a role definition but there&#8217;s no out of the box functionality to do so. After some searching on the web I couldn&#8217;t find any suitable methods either.<br \/>\nSo I decided to create on myself and thought creating an extension method would be the best option.<\/p>\n<pre lang=\"csharp\">\n\/\/\/ <summary>\n\/\/\/ Revokes the given permission from the BasePermission set.\n\/\/\/ <\/summary>\n\/\/\/ <param name=\"roleDefinition\">The role definition.<\/param>\n\/\/\/ <param name=\"revokePermission\">The permission you want tor revoke.<\/param>\npublic static void RevokePermission(this SPRoleDefinition roleDefinition, SPBasePermissions revokePermission)\n{\n\t\/\/ Remove space, because BasePermissions contains spaces between entries\n\tstring originalPermissionsString = roleDefinition.BasePermissions.ToString().Replace(\" \", \"\");\n\n\t\/\/ Split orignal permission entries\n\tstring[] originalPermissions = originalPermissionsString.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);\n\troleDefinition.BasePermissions = new SPBasePermissions();\n\n\tforeach (string originalPermission in originalPermissions)\n\t{\n\t\tif (originalPermission == revokePermission.ToString())\n\t\t\tcontinue;\n\n\t\tSPBasePermissions newPermission = (SPBasePermissions)Enum.Parse(typeof(SPBasePermissions), originalPermission);\n\n\t\troleDefinition.BasePermissions = roleDefinition.BasePermissions | newPermission;\n\t}\n}<\/pre>\n<p>After implementing this extension into your project\/solution\/class you can now revoke permissions from your permission set like this.<\/p>\n<pre lang=\"csharp\">\nSPRoleDefinition roleDefinition = web.RoleDefinitions[\"YourRoleDef\"];\nroleDefinition.RevokePermission(SPBasePermissions.BrowseUserInfo);\nroleDefinition.Update();\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I had to revoke some of the permissions of a role definition but there&#8217;s no out of the box functionality to do so. After some searching on the web I couldn&#8217;t find any suitable methods either. So I decided to create on myself and thought creating an extension method would be the best option. \/\/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[8,20],"tags":[7,19,14],"class_list":["post-155","post","type-post","status-publish","format-standard","hentry","category-development","category-sharepoint","tag-development","tag-extension-method","tag-sharepoint"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/posts\/155"}],"collection":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=155"}],"version-history":[{"count":0,"href":"https:\/\/commonware.nl\/index.php?rest_route=\/wp\/v2\/posts\/155\/revisions"}],"wp:attachment":[{"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/commonware.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}