I need to assign permissions to a particular list item using client object model in JavaScript.Say for 5th item by id I want to assign contribute permission to a particular group.
I have previously done this using c# object model like below. I have below c# code which can break role inheritance then assign permission.
private static void RemoveAllPermissions(SPListItem CurrentlistItem)
{
CurrentlistItem.BreakRoleInheritance(true);
SPRoleAssignmentCollection SPRoleAssColn = CurrentlistItem.RoleAssignments;
for (int i = SPRoleAssColn.Count - 1; i >=0 ; i--)
{
SPRoleAssColn.Remove(i);
}
Console.WriteLine("All Permissions Removed");
}
Then for granting permission
private static void GrantPermission(SPListItem CurrentListItem, SPWeb oSPWeb, SPRoleType SPRoleType, SPPrincipal SPPrincipal)
{
SPRoleDefinition oSPRoleDefinition = oSPWeb.RoleDefinitions.GetByType(SPRoleType);
SPRoleAssignment oSPRoleAssignment = new SPRoleAssignment(SPPrincipal);
oSPRoleAssignment.RoleDefinitionBindings.Add(oSPRoleDefinition);
CurrentListItem.RoleAssignments.Add(oSPRoleAssignment);
CurrentListItem.Update();
}
My question is how can this achieved by using JSOM or rest ?(any one is fine).I am using SP 2013.Any help is appreciated.