In this example you will see how to delete the current role definition of the group in SharePoint using the REST. Develop the project using the following method in the NAPA Tool.

On your Developer Site, open the "Napa" Office 365 Development Tools and then choose Add New Project.

Prerequisites

The following is the important procedure to be done before creating the app. Specify the permissions that your app needs as in the following. Choose the Properties button at the bottom of the page.

The code example in this article sets the custom permissions on a list and then changes a group's permissions to it. The example uses the REST interface to:
Source Code
  1. 'use strict';
  2. // Change placeholder values before you run this code.
  3. var listTitle = 'List 1';
  4. var groupName = 'Group A';
  5. var targetRoleDefinitionName = 'Contribute';
  6. var appweburl;
  7. var hostweburl;
  8. var executor;
  9. var groupId;
  10. var targetRoleDefinitionId;
  11. $(document).ready( function() {
  12. //Get the URI decoded URLs.
  13. hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
  14. appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
  15. // Load the cross-domain library file and continue to the custom code.
  16. var scriptbase = hostweburl + "/_layouts/15/";
  17. $.getScript(scriptbase + "SP.RequestExecutor.js", getTargetGroupId);
  18. });
  19. // Get the ID of the target group.
  20. function getTargetGroupId() {
  21. executor = new SP.RequestExecutor(appweburl);
  22. var endpointUri = appweburl + "/_api/SP.AppContextSite(@target)/web/sitegroups/getbyname('";
  23. endpointUri += groupName + "')/id" + "?@target='" + hostweburl + "'";
  24. executor.executeAsync({
  25. url: endpointUri,
  26. method: 'GET',
  27. headers: { 'accept':'application/json;odata=verbose' },
  28. success: function(responseData) {
  29. var jsonObject = JSON.parse(responseData.body);
  30. groupId = jsonObject.d.Id;
  31. getTargetRoleDefinitionId();
  32. },
  33. error: errorHandler
  34. });
  35. }
  36. // Get the ID of the role definition that defines the permissions
  37. // you want to assign to the group.
  38. function getTargetRoleDefinitionId() {
  39. var endpointUri = appweburl + "/_api/SP.AppContextSite(@target)/web/roledefinitions/getbyname('";
  40. endpointUri += targetRoleDefinitionName + "')/id" + "?@target='" + hostweburl + "'";
  41. executor.executeAsync({
  42. url: endpointUri,
  43. method: 'GET',
  44. headers: { 'accept':'application/json;odata=verbose' },
  45. success: function(responseData) {
  46. var jsonObject = JSON.parse(responseData.body)
  47. targetRoleDefinitionId = jsonObject.d.Id;
  48. breakRoleInheritanceOfList();
  49. },
  50. error: errorHandler
  51. });
  52. }
  53. // Break role inheritance on the list.
  54. function breakRoleInheritanceOfList() {
  55. var endpointUri = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('";
  56. endpointUri += listTitle + "')/breakroleinheritance(true)?@target='" + hostweburl + "'";
  57. executor.executeAsync({
  58. url: endpointUri,
  59. method: 'POST',
  60. headers: { 'X-RequestDigest':$('#__REQUESTDIGEST').val() },
  61. success: deleteCurrentRoleForGroup,
  62. error: errorHandler
  63. });
  64. }
  65. // Remove the current role assignment for the group on the list.
  66. function deleteCurrentRoleForGroup() {
  67. var endpointUri = appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('";
  68. endpointUri += listTitle + "')/roleassignments/getbyprincipalid('" + groupId + "')?@target='" + hostweburl + "'";
  69. executor.executeAsync({
  70. url: endpointUri,
  71. method: 'POST',
  72. headers: {
  73. 'X-RequestDigest':$('#__REQUESTDIGEST').val(),
  74. 'X-HTTP-Method':'DELETE'
  75. },
  76. success: successHandler,
  77. error: errorHandler
  78. });
  79. }
  80. // Get parameters from the query string.
  81. // For production purposes you may want to use a library to handle the query string.
  82. function getQueryStringParameter(paramToRetrieve) {
  83. var params = document.URL.split("?")[1].split("&");
  84. for (var i = 0; i < params.length; i = i + 1) {
  85. var singleParam = params[i].split("=");
  86. if (singleParam[0] == paramToRetrieve) return singleParam[1];
  87. }
  88. }
  89. function successHandler() {
  90. alert('Request succeeded.');
  91. }
  92. function errorHandler(xhr, ajaxOptions, thrownError) {
  93. alert('Request failed: ' + xhr.status + '\n' + thrownError + '\n' + xhr.responseText);
  94. }
Publish

Publish the app and click the Trust it Button.

Output

Request succeeded.